Skip to content

Commit

Permalink
Fixed yield tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pyromaniac committed Feb 12, 2011
1 parent 6a402f2 commit f70db38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -50,7 +50,15 @@ In puffer pages you can use puffer pages layouts or applcation layouts.
For puffer pages layouts page parts placeholder is liquid tag yield.
<pre>{% yield [page_part_name] %}</pre>

If no page_part_name specified, puffer layout will use page part with default name (`body`). You can change defaul page part name in puffer pages setup initializer.
If no page_part_name specified, puffer layout will use page part with default name ('body'). You can change defaul page part name in puffer pages setup initializer.

Ex.
<pre>
{% yield %} # renders body
{% yield 'sidebar' %} # renders sidebar
{% assign sb = 'sidebar' %}
{% yield sb %} # renders sidebar too
</pre>

### Application layouts.
For application layout page part body will be inserted instead of SUDDENLY! <%= yield %>
Expand Down
2 changes: 1 addition & 1 deletion app/models/page.rb
Expand Up @@ -99,7 +99,7 @@ def inherited_page_parts
end

def part name
inherited_page_parts.detect {|part| part.name = name}
inherited_page_parts.detect {|part| part.name == name}
end

def is_layout?
Expand Down
6 changes: 3 additions & 3 deletions lib/puffer_pages/liquid/tags/yield.rb
Expand Up @@ -3,20 +3,20 @@ module Liquid
module Tags

class Yield < ::Liquid::Tag
Syntax = /(\w+)/
Syntax = /(#{::Liquid::QuotedFragment}+)/

def initialize(tag_name, markup, tokens)
if markup =~ Syntax
@name = $1
else
@name = PufferPages.primary_page_part_name
@name = "'#{PufferPages.primary_page_part_name}'"
end

super
end

def render(context)
swallow_nil{context.registers[:page].part(@name).render(context)}
context.registers[:page].part(context[@name]).render(context)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/page_spec.rb
Expand Up @@ -122,9 +122,9 @@
end

it 'should render layout' do
@layout = Fabricate :layout, :name => 'foo_layout', :body => "{% yield %} {% yield sidebar %}"
@layout = Fabricate :layout, :name => 'foo_layout', :body => "|{% yield %}|{% yield 'sidebar' %}|{% assign sb = 'sidebar' %}|{% yield sb %}|"
result = @root.render 'self' => PufferPages::Liquid::PageDrop.new(@root)
result.should == "#{@root.title} #{@root.name}"
result.should == "|#{@root.title}|#{@root.name}||#{@root.name}|"
end

end
Expand Down
9 changes: 9 additions & 0 deletions spec/models/tags_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'Tags' do

#describe 'yield' do

#end

end

0 comments on commit f70db38

Please sign in to comment.