Skip to content

Commit

Permalink
better rendering in content using liquid_context.stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed May 12, 2014
1 parent aac9dec commit 2d774db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/models/smithy/page_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def content_block_attributes=(attributes)
end
end

def render(liquid_registers)
content_block_template.liquid_template.render(::Liquid::Context.new({}, self.to_liquid, liquid_registers, !Rails.env.production?))
def render(liquid_context)
liquid_context.stack do
# push the default assigns into a smithy namespace. They'll still be in the
# scopes as the original values as well, but this ensures they don't get clobbered
liquid_context.merge('smithy' => liquid_context.scopes.last)
liquid_context.merge(self.to_liquid)
content_block_template.liquid_template.render(liquid_context)
end
end

def to_liquid
Expand Down
3 changes: 2 additions & 1 deletion spec/models/smithy/page_content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
it { should belong_to(:content_block_template) }

describe "#render" do
let(:liquid_context) { ::Liquid::Context.new }
let(:content_block_template) { build(:content_block_template, :content => '{{ content }}' ) }
let(:content) { build(:content, :content => "This is the content") }
subject { build(:page_content, :content_block => content, :content_block_template => content_block_template).render }
subject { build(:page_content, :content_block => content, :content_block_template => content_block_template).render(liquid_context) }
it { should_not be_nil }
it { should == "This is the content"}
end
Expand Down

0 comments on commit 2d774db

Please sign in to comment.