2010-08-24 22:59:22 +00:00
|
|
|
module Locomotive
|
|
|
|
module Liquid
|
|
|
|
module Tags
|
|
|
|
class InheritedBlock < ::Liquid::InheritedBlock
|
|
|
|
|
2010-08-27 15:40:03 +00:00
|
|
|
def initialize(tag_name, markup, tokens, context)
|
|
|
|
if markup =~ Syntax
|
|
|
|
@name = $1
|
|
|
|
else
|
2010-08-28 00:00:05 +00:00
|
|
|
raise ::Liquid::SyntaxError.new("Error in tag 'block' - Valid syntax: block [name]")
|
2010-08-27 15:40:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context[:current_block] = self # for now, no need to push it in a stack
|
|
|
|
|
2010-08-28 00:00:05 +00:00
|
|
|
# puts "** InheritedBlock[begin] #{context.object_id} / #{@name} / #{context[:page].try(:fullpath)}"
|
2010-08-27 15:40:03 +00:00
|
|
|
|
|
|
|
super if tokens
|
|
|
|
end
|
|
|
|
|
2010-08-24 22:59:22 +00:00
|
|
|
def end_tag
|
2010-08-28 00:00:05 +00:00
|
|
|
# puts "** InheritedBlock[end_tag] before super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}"
|
2010-08-24 22:59:22 +00:00
|
|
|
|
2010-08-27 15:40:03 +00:00
|
|
|
self.register_current_block
|
|
|
|
|
|
|
|
if !self.contains_super?(@nodelist) # then disable all editable_elements coming from the parent block too and not used
|
2010-08-28 00:00:05 +00:00
|
|
|
# puts "** InheritedBlock[end_tag] disabling_parent_editable_elements... #{@context.object_id}"
|
2010-08-27 15:40:03 +00:00
|
|
|
@context[:page].disable_parent_editable_elements(@name)
|
2010-08-24 22:59:22 +00:00
|
|
|
end
|
2010-08-27 15:40:03 +00:00
|
|
|
|
2010-08-28 00:00:05 +00:00
|
|
|
# puts "** InheritedBlock[end_tag] after super #{@name} / #{@context.object_id}/ #{@context[:page].fullpath}"
|
2010-08-24 22:59:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2010-08-28 00:00:05 +00:00
|
|
|
# def register_current_block
|
|
|
|
# @context[:blocks] ||= {}
|
|
|
|
#
|
|
|
|
# block = @context[:blocks][@name]
|
|
|
|
#
|
|
|
|
# if block
|
|
|
|
# # needed for the block.super statement
|
|
|
|
# # puts "[BLOCK #{@name}|end_tag] nodelist #{@nodelist.inspect}"
|
|
|
|
# block.add_parent(@nodelist)
|
|
|
|
#
|
|
|
|
# @parent = block.parent
|
|
|
|
# @nodelist = block.nodelist
|
|
|
|
#
|
|
|
|
# # puts "[BLOCK #{@name}|end_tag] direct parent #{block.parent.inspect}"
|
|
|
|
# else
|
|
|
|
# # register it
|
|
|
|
# # puts "[BLOCK #{@name}|end_tag] register it"
|
|
|
|
# @context[:blocks][@name] = self
|
|
|
|
# end
|
|
|
|
# end
|
2010-08-27 15:40:03 +00:00
|
|
|
|
2010-08-24 22:59:22 +00:00
|
|
|
def contains_super?(nodelist)
|
|
|
|
nodelist.any? do |node|
|
|
|
|
if node.is_a?(String) && node =~ /\{\{\s*block.super\s*\}\}/
|
|
|
|
true
|
|
|
|
elsif node.respond_to?(:nodelist) && !node.is_a?(Locomotive::Liquid::Tags::InheritedBlock)
|
|
|
|
contains_super?(node.nodelist)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
::Liquid::Template.register_tag('block', InheritedBlock)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|