diff --git a/Rakefile b/Rakefile index 1642a5f..98c543e 100644 --- a/Rakefile +++ b/Rakefile @@ -2,13 +2,14 @@ require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' +require 'rake/testtask' require 'fileutils' include FileUtils NAME = "camping" REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil VERS = ENV['VERSION'] || ("1.5" + (REV ? ".#{REV}" : "")) -CLEAN.include ['**/.*.sw?', '*.gem', '.config'] +CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log'] RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation", "--opname", "index.html", "--line-numbers", @@ -87,3 +88,9 @@ end task :uninstall => [:clean] do sh %{sudo gem uninstall #{NAME}} end + +Rake::TestTask.new(:test) do |t| + t.test_files = FileList['test/test_*.rb'] +# t.warning = true +# t.verbose = true +end diff --git a/lib/camping-unabridged.rb b/lib/camping-unabridged.rb index c18c371..ce645f6 100644 --- a/lib/camping-unabridged.rb +++ b/lib/camping-unabridged.rb @@ -337,7 +337,7 @@ def method_missing(*a,&b) a.shift if a[0]==:render m=Mab.new({},self) s=m.capture{send(*a,&b)} - s=m.layout{s} if /^_/!~a[0].to_s and m.respond_to?:layout + s=m.capture{send(:layout){s}} if /^_/!~a[0].to_s and m.respond_to?:layout s end diff --git a/lib/camping.rb b/lib/camping.rb index 4ca4347..6a689b8 100644 --- a/lib/camping.rb +++ b/lib/camping.rb @@ -7,9 +7,10 @@ module Camping;Apps=[];C=self;S=IO.read(__FILE__).sub(/S=I.+$/,'') p[/^\//]?@root+p : p end;def errors_for o;ul.errors{o.errors.each_full{|x|li x} }if o.errors.any?end end;module Base;include Helpers;attr_accessor:input, :cookies,:env,:headers,:body,:status,:root;def method_missing*a,&b -a.shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)};s=m.layout{s}if -/^_/!~a[0].to_s and m.respond_to?:layout;s end;def r s,b,h={};@status=s;@headers. -merge!h;@body=b end;def redirect*a;r 302,'','Location'=>URL(*a)end;Z="\r\n" +a.shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)} +s=m.capture{send(:layout){s}} if /^_/!~a[0].to_s and m.respond_to?:layout +s end;def r s,b,h={};@status=s;@headers.merge!h;@body=b end +def redirect*a;r 302,'','Location'=>URL(*a)end;Z="\r\n" def initialize r,e,m;e=H[e.to_hash];@status,@method,@env,@headers,@root=200,m. downcase,e,{'Content-Type'=>"text/html"},e.SCRIPT_NAME.sub(/\/$/,'') @k=C.kp e.HTTP_COOKIE;q=C.qsp e.QUERY_STRING;@in=r diff --git a/test/test_xhtml_trans.rb b/test/test_xhtml_trans.rb new file mode 100644 index 0000000..ce036ef --- /dev/null +++ b/test/test_xhtml_trans.rb @@ -0,0 +1,55 @@ +require 'mosquito' + +Camping.goes :XhtmlTrans + +module XhtmlTrans + module Controllers + class WithLayout < R '/with_layout' + def get + render :with_layout + end + end + + class WithoutLayout < R '/without_layout' + def get + render :_without_layout + end + end + end + + module Views + def layout + xhtml_transitional do + head do title "title" end + body do capture { yield } end + end + end + + def with_layout + h1 "With layout" + end + + def _without_layout + xhtml_transitional do + head do title "title" end + body do h1 "Without layout" end + end + end + end +end + +class XhtmlTransTest < Camping::FunctionalTest + def test_with_layout + get '/with_layout' + + assert(@response.body =~ /DOCTYPE/, "No doctype defined") + end + + def test_without_layout + get '/without_layout' + + assert(@response.body =~ /DOCTYPE/, "No doctype defined") + end + +end +