From d2a5ba569a1f81be4fc07d1b806676cdaa2881c8 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Mon, 16 Apr 2012 13:20:28 +0800 Subject: [PATCH] Adding support for partials. --- lib/toto.rb | 6 +++++- test/templates/composite.rhtml | 2 ++ test/templates/sidebar.rhtml | 1 + test/toto_test.rb | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/templates/composite.rhtml create mode 100644 test/templates/sidebar.rhtml diff --git a/lib/toto.rb b/lib/toto.rb index 6d98c2b..6b5cc71 100644 --- a/lib/toto.rb +++ b/lib/toto.rb @@ -165,10 +165,14 @@ def title end def render page, type - content = to_html page, @config + content = to_partial page type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page) end + def to_partial page + to_html page, @config + end + def to_xml page xml = Builder::XmlMarkup.new(:indent => 2) instance_eval File.read("#{Paths[:templates]}/#{page}.builder") diff --git a/test/templates/composite.rhtml b/test/templates/composite.rhtml new file mode 100644 index 0000000..6a9d891 --- /dev/null +++ b/test/templates/composite.rhtml @@ -0,0 +1,2 @@ +

Composite Page

+<%= render 'sidebar', :partial %> diff --git a/test/templates/sidebar.rhtml b/test/templates/sidebar.rhtml new file mode 100644 index 0000000..74660ff --- /dev/null +++ b/test/templates/sidebar.rhtml @@ -0,0 +1 @@ + diff --git a/test/toto_test.rb b/test/toto_test.rb index aa090b6..e919511 100644 --- a/test/toto_test.rb +++ b/test/toto_test.rb @@ -280,6 +280,12 @@ def readme() "#{self[:name]}'s README" end context "extensions to the core Ruby library" do should("respond to iso8601") { Date.today }.respond_to?(:iso8601) end + + context "rendering a partial" do + setup { @toto.get('/composite') } + should("include a sidebar") { topic.body }.includes_elements("#sidebar", 1) + end + end