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-22 23:48:11 +00:00
|
|
|
attr_accessor :page_id
|
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
def parse_parent_template(context)
|
2010-08-21 23:56:44 +00:00
|
|
|
page = nil
|
|
|
|
|
|
|
|
if @template_name == 'parent'
|
2010-08-22 23:48:11 +00:00
|
|
|
if context[:cached_parent]
|
|
|
|
page = context[:cached_parent]
|
|
|
|
context[:cached_parent] = nil
|
|
|
|
else
|
|
|
|
page = context[:page].parent
|
|
|
|
end
|
2010-08-21 23:56:44 +00:00
|
|
|
else
|
2010-08-22 23:48:11 +00:00
|
|
|
path = @template_name.gsub("'", '')
|
|
|
|
page = context[:cached_pages].try(:[], path) || context[:site].pages.where(:fullpath => path).first
|
2010-08-21 23:56:44 +00:00
|
|
|
end
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if page.nil?
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-22 23:48:11 +00:00
|
|
|
@page_id = page.id
|
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
template = page.template
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
# merge blocks ?
|
|
|
|
blocks = find_blocks(template.root.nodelist)
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
blocks.each_value do |block|
|
|
|
|
block.send(:instance_variable_set, :"@context", context)
|
|
|
|
block.end_tag
|
2010-08-08 11:30:27 +00:00
|
|
|
end
|
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
template
|
2010-08-08 11:30:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
::Liquid::Template.register_tag('extends', Extends)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|