diff --git a/lib/locomotive/liquid/tags/editable/ouput.rb b/lib/locomotive/liquid/tags/editable/ouput.rb new file mode 100644 index 00000000..1964f92a --- /dev/null +++ b/lib/locomotive/liquid/tags/editable/ouput.rb @@ -0,0 +1,49 @@ +module Locomotive + module Liquid + module Tags + module Editable + class Content < ::Liquid::Tag + + Syntax = /(#{::Liquid::Expression}+)?/ + + def initialize(tag_name, markup, tokens, context) + if markup =~ Syntax + @slug = $1 + @options = { :inherit => false } + markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') } + else + raise ::Liquid::SyntaxError.new("Syntax Error in 'content' - Valid syntax: slug") + end + + super + end + + def render(context) + page = context.registers[:page] + element = find_element(page) + + if element.nil? && @options[:inherit] != false + while page.parent.present? && element.nil? + page = page.parent + element = find_element(page) + end + end + + if element.present? + return element.content + else + raise ::Liquid::SyntaxError.new("Error in 'content' - Can't find editable element called `#{@slug}`") + end + end + + def find_element(page) + page.editable_elements.where(:slug => @slug).first + end + + end + + ::Liquid::Template.register_tag('content', Content) + end + end + end +end \ No newline at end of file