Sha256: 4c33d1a753658914847481b3b16601757dc609e1d543f10e4e71a38fe14da0f3

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

module Locomotive
  module Wagon
    module Liquid
      module Tags
        module Editable
          class Base < ::Liquid::Block

            Syntax = /(#{::Liquid::QuotedFragment})(\s*,\s*#{::Liquid::Expression}+)?/

            def initialize(tag_name, markup, tokens, context)
              if markup =~ Syntax
                @slug = $1.gsub(/[\"\']/, '')
                @options = {}
                markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/^'/, '').gsub(/'$/, '') }
              else
                raise ::Liquid::SyntaxError.new("Syntax Error in 'editable_xxx' - Valid syntax: editable_xxx <slug>(, <options>)")
              end

              super
            end

            def render(context)
              current_page = context.registers[:page]

              element = current_page.find_editable_element(self.current_block_name(context), @slug)

              if element.present?
                render_element(context, element)
              else
                super
              end
            end

            protected

            def render_element(context, element)
              element.content
            end

            def current_block_name(context)
              context['block'].try(:name)
            end

          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/liquid/tags/editable/base.rb