Sha256: 11da6bff8f39623c0aff295210246ee9bb2c0ce8879ed20ea490de2f8d1e59e9

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'liquid/tag/disabler'
require 'liquid/tag/disableable'

module Liquid
  class Tag
    attr_reader :nodelist, :tag_name, :line_number, :parse_context
    alias_method :options, :parse_context
    include ParserSwitching

    class << self
      def parse(tag_name, markup, tokenizer, parse_context)
        tag = new(tag_name, markup, parse_context)
        tag.parse(tokenizer)
        tag
      end

      def disable_tags(*tag_names)
        tag_names += disabled_tags
        define_singleton_method(:disabled_tags) { tag_names }
        prepend(Disabler)
      end

      private :new

      protected

      def disabled_tags
        []
      end
    end

    def initialize(tag_name, markup, parse_context)
      @tag_name      = tag_name
      @markup        = markup
      @parse_context = parse_context
      @line_number   = parse_context.line_number
    end

    def parse(_tokens)
    end

    def raw
      "#{@tag_name} #{@markup}"
    end

    def name
      self.class.name.downcase
    end

    def render(_context)
      ''
    end

    # For backwards compatibility with custom tags. In a future release, the semantics
    # of the `render_to_output_buffer` method will become the default and the `render`
    # method will be removed.
    def render_to_output_buffer(context, output)
      render_result = render(context)
      output << render_result if render_result
      output
    end

    def blank?
      false
    end

    private

    def parse_expression(markup)
      parse_context.parse_expression(markup)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
liquid-5.7.0 lib/liquid/tag.rb
liquid-5.6.4 lib/liquid/tag.rb
liquid-5.6.3 lib/liquid/tag.rb
liquid-5.6.2 lib/liquid/tag.rb
liquid-5.6.1 lib/liquid/tag.rb
liquid-5.6.0 lib/liquid/tag.rb
liquid-5.6.0.rc3 lib/liquid/tag.rb
liquid-5.6.0.rc2 lib/liquid/tag.rb
liquid-5.6.0.rc1 lib/liquid/tag.rb