Sha256: 1771b85b72b09648a7a591e3dcb9b0d76f93b5bc187315edae41cf53ad624401

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Tags

        class Snippet < ::Liquid::Include

          attr_reader :name

          def initialize(tag_name, markup, options)
            super

            # we use a convention to differentiate sections from snippets
            @name               = evaluate_snippet_name
            @template_name_expr = "snippets--#{@name}"
          end

          def parse(tokens)
            ActiveSupport::Notifications.instrument('steam.parse.include', page: parse_context[:page], name: name)

            # look for editable elements (only used by the Engine)
            # In the next version of Locomotive (v5), we won't support the editable elements
            if parse_context[:snippet_finder] && snippet = parse_context[:snippet_finder].find(name)
              parse_context[:parser]._parse(snippet, parse_context.merge(snippet: name))
            end
          end

          def render(context)
            # parse_context (previously @options) doesn't include the page key if cache is on
            parse_context[:page] = context.registers[:page]
            super
          end

          private

          def evaluate_snippet_name
            (!template_name_expr.is_a?(String) && template_name_expr.send(:state).first) ||
            template_name_expr
          end

        end

        ::Liquid::Template.register_tag('include'.freeze, Snippet)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0 lib/locomotive/steam/liquid/tags/snippet.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/liquid/tags/snippet.rb