Sha256: 113932950239192070c6e20df08e2c8acbf28f723053a52b14a0bedb156728f1

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 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, options)
              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(options[:locale].t("errors.syntax.#{tag_name}"), options[:line])
              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

15 entries across 15 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.5.8 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.7 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.6 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.5 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.4 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.3 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.2 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.1 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.0 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.5.0.rc1 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.4.0 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.3.3 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.3.2 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.3.1 lib/locomotive/wagon/liquid/tags/editable/base.rb
locomotivecms_wagon-1.3.0 lib/locomotive/wagon/liquid/tags/editable/base.rb