Sha256: 0f9de8124032c984a4595edf29637e290dc5a543a9ad390ffeb2694036025cc6

Contents?: true

Size: 673 Bytes

Versions: 10

Compression:

Stored size: 673 Bytes

Contents

module Liquid
  class Tokenizer
    attr_reader :line_number

    def initialize(source, line_numbers = false)
      @source = source
      @line_number = line_numbers ? 1 : nil
      @tokens = tokenize
    end

    def shift
      token = @tokens.shift
      @line_number += token.count("\n") if @line_number && token
      token
    end

    private

    def tokenize
      @source = @source.source if @source.respond_to?(:source)
      return [] if @source.to_s.empty?

      tokens = @source.split(TemplateParser)

      # removes the rogue empty element at the beginning of the array
      tokens.shift if tokens[0] && tokens[0].empty?

      tokens
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
liquid-4.0.4 lib/liquid/tokenizer.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/tokenizer.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/tokenizer.rb
liquid-4.0.3 lib/liquid/tokenizer.rb
liquid-4.0.2 lib/liquid/tokenizer.rb
liquid-4-0-2-4.0.2 lib/liquid/tokenizer.rb
liquid-4.0.1 lib/liquid/tokenizer.rb
liquid-4.0.0 lib/liquid/tokenizer.rb
liquid-4.0.0.rc3 lib/liquid/tokenizer.rb
liquid-4.0.0.rc2 lib/liquid/tokenizer.rb