Class: Liquid::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/tokenizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) ⇒ Tokenizer

Returns a new instance of Tokenizer.



7
8
9
10
11
12
# File 'lib/liquid/tokenizer.rb', line 7

def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
  @source         = source.to_s.to_str
  @line_number    = line_number || (line_numbers ? 1 : nil)
  @for_liquid_tag = for_liquid_tag
  @tokens         = tokenize
end

Instance Attribute Details

#for_liquid_tagObject (readonly)

Returns the value of attribute for_liquid_tag.



5
6
7
# File 'lib/liquid/tokenizer.rb', line 5

def for_liquid_tag
  @for_liquid_tag
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



5
6
7
# File 'lib/liquid/tokenizer.rb', line 5

def line_number
  @line_number
end

Instance Method Details

#shiftObject



14
15
16
17
18
19
20
21
22
# File 'lib/liquid/tokenizer.rb', line 14

def shift
  (token = @tokens.shift) || return

  if @line_number
    @line_number += @for_liquid_tag ? 1 : token.count("\n")
  end

  token
end