2010-08-08 11:30:27 +00:00
|
|
|
module Locomotive
|
|
|
|
module Liquid
|
|
|
|
module Tags
|
2010-08-20 00:31:01 +00:00
|
|
|
class Extends < ::Liquid::Extends
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-30 23:56:54 +00:00
|
|
|
def prepare_parsing
|
2010-08-24 22:59:22 +00:00
|
|
|
super
|
2010-08-26 11:06:44 +00:00
|
|
|
|
2010-08-30 23:56:54 +00:00
|
|
|
parent_page = @context[:parent_page]
|
|
|
|
|
2010-08-31 21:53:30 +00:00
|
|
|
@context[:page].merge_editable_elements_from_page(parent_page)
|
|
|
|
|
2010-08-30 23:56:54 +00:00
|
|
|
@context[:snippets] = parent_page.snippet_dependencies
|
|
|
|
@context[:templates] = ([*parent_page.template_dependencies] + [parent_page.id]).compact
|
2010-08-24 22:59:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_parent_template
|
|
|
|
if @template_name == 'parent'
|
|
|
|
if @context[:cached_parent]
|
2011-01-07 23:10:44 +00:00
|
|
|
@context[:parent_page] = @context[:cached_parent] #.clone # parent must not be modified
|
|
|
|
|
|
|
|
@context[:cached_parent].instance_variable_set(:@template, nil) # force to reload the template
|
2010-08-24 22:59:22 +00:00
|
|
|
@context[:cached_parent] = nil
|
|
|
|
else
|
|
|
|
@context[:parent_page] = @context[:page].parent
|
|
|
|
end
|
|
|
|
else
|
2010-08-26 11:06:44 +00:00
|
|
|
@context[:parent_page] = @context[:cached_pages].try(:[], @template_name) ||
|
|
|
|
@context[:site].pages.where(:fullpath => @template_name).first
|
2010-08-24 22:59:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil?
|
|
|
|
|
2011-01-07 23:10:44 +00:00
|
|
|
# be sure to work with a copy of the parent template otherwise there will be conflicts
|
|
|
|
parent_template = @context[:parent_page].template.clone
|
|
|
|
|
|
|
|
@context[:parent_page].instance_variable_set(:@template, parent_template)
|
|
|
|
|
|
|
|
parent_template
|
2010-08-24 22:59:22 +00:00
|
|
|
end
|
|
|
|
|
2010-08-08 11:30:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
::Liquid::Template.register_tag('extends', Extends)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|