diff --git a/lib/toto.rb b/lib/toto.rb index 3740fc2..0766de9 100644 --- a/lib/toto.rb +++ b/lib/toto.rb @@ -97,7 +97,8 @@ def / self[:root] end - def go route, type = :html, env + def go route, type, env + type ||= :html route << self./ if route.empty? type, path = type =~ /html|xml|json/ ? type.to_sym : :html, route.join('/') context = lambda do |data, page| @@ -165,8 +166,12 @@ def title end def render page, type - content = to_html page, @config - type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page) + if type == :html + content = to_html page, @config + to_html(:layout, @config, &Proc.new { content }) + else + send(:"to_#{type}", page) + end end def to_xml page @@ -335,7 +340,7 @@ def call env path, mime = @request.path_info.split('.') route = (path || '/').split('/').reject {|i| i.empty? } - response = @site.go(route, *(mime ? mime : []), env) + response = @site.go(route, mime ? mime : [], env) @response.body = [response[:body]] @response['Content-Length'] = response[:body].length.to_s unless response[:body].empty? diff --git a/test/templates/custom.builder b/test/templates/custom.builder new file mode 100644 index 0000000..e9cab34 --- /dev/null +++ b/test/templates/custom.builder @@ -0,0 +1,10 @@ +xml.instruct! +xml.custom do + xml.title @config[:title] + xml.id @config[:url] + + xml.child do + xml.name "Testing Baby" + end +end + diff --git a/test/toto_test.rb b/test/toto_test.rb index 8b1ed62..7b1bb73 100644 --- a/test/toto_test.rb +++ b/test/toto_test.rb @@ -102,6 +102,13 @@ asserts("summary shouldn't be empty") { topic.body }.includes_html("summary" => /.{10,}/) end + context "GET /custom.xml (custom XML)" do + setup { @toto.get('/custom.xml') } + asserts("content type is set properly") { topic.content_type }.equals "application/xml" + asserts("body should be valid xml") { topic.body }.includes_html("custom > child" => /.+/) + asserts("summary shouldn't be empty") { topic.body }.includes_html("name" => /.{10,}/) + end + context "GET to a repo name" do setup do class Toto::Repo