Sha256: da495b30f2fceb1517125c2640c8f9865bb26e26a27e00ec0fc85b6a9df4dbc1

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Tags
        module Concerns

          # Many of Liquid tags have attributes (like options)
          # This module makes sure we use the same reliable way to
          # extract and evaluate them.

          module Attributes

            attr_reader :attributes, :raw_attributes

            private

            def parse_attributes(markup, default = {})
              @attributes     = default || {}
              @raw_attributes = @attributes.dup

              return if markup.blank?

              markup.scan(tag_attributes_regexp) do |key, value|
                _key = key.to_sym

                @attributes[_key]     = block_given? ? yield(value) : ::Liquid::Expression.parse(value)
                @raw_attributes[_key] = @attributes[_key]
              end
            end

            def evaluate_attributes(context, lax: false)
              @attributes = @raw_attributes.transform_values do |value|
                _value = context.evaluate(value)
                lax && _value.nil? ? value&.name : _value
              end
            end

            def tag_attributes_regexp
              ::Liquid::TagAttributes
            end

          end

        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/liquid/tags/concerns/attributes.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/liquid/tags/concerns/attributes.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/liquid/tags/concerns/attributes.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/liquid/tags/concerns/attributes.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/liquid/tags/concerns/attributes.rb