Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for partials #121

Open
wants to merge 1 commit into from

1 participant

@adscott

This change should allow partials to be rendered using syntax like:

<%= render 'sidebar', :partial %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 16, 2012
  1. @adscott

    Adding support for partials.

    adscott authored
This page is out of date. Refresh to see the latest.
View
6 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")
View
2  test/templates/composite.rhtml
@@ -0,0 +1,2 @@
+<h1>Composite Page</h1>
+<%= render 'sidebar', :partial %>
View
1  test/templates/sidebar.rhtml
@@ -0,0 +1 @@
+<div id="sidebar">Sidebar</div>
View
6 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
Something went wrong with that request. Please try again.