Skip to content

Commit

Permalink
Pass the liquid_registers around better so the controller, etc is ava…
Browse files Browse the repository at this point in the history
…ilable at the content level
  • Loading branch information
Tim Glen committed May 9, 2014
1 parent 58f5890 commit 4ddea4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/models/smithy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Page < ActiveRecord::Base
scope :published, -> { where('published_at <= ?', Time.now) }

attr_accessor :publish
attr_accessor :liquid_registers

def container?(container_name)
containers.where(:name => container_name).count > 0
Expand All @@ -44,10 +45,15 @@ def published?
self.published_at?
end

def render(liquid_context)
@liquid_registers = liquid_context.registers
self.template.liquid_template.render(liquid_context)
end

def render_container(container_name)
return '' unless container?(container_name)
Rails.cache.fetch(self.container_cache_key(container_name)) do
self.contents_for_container_name(container_name).map(&:render).join("\n\n")
self.contents_for_container_name(container_name).map{|c| c.render(liquid_registers) }.join("\n\n")
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/smithy/page_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def content_block_attributes=(attributes)
end
end

def render
content_block_template.liquid_template.render(self.to_liquid)
def render(liquid_registers)
content_block_template.liquid_template.render(::Liquid::Context.new({}, self.to_liquid, liquid_registers, !Rails.env.production?))
end

def to_liquid
Expand Down

0 comments on commit 4ddea4e

Please sign in to comment.