Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 57 #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
10 changes: 10 additions & 0 deletions test/templates/custom.builder
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions test/toto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down