Class: Liquid::ParseContext

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = Const::EMPTY_HASH) ⇒ ParseContext

Returns a new instance of ParseContext.



8
9
10
11
12
13
14
15
16
17
# File 'lib/liquid/parse_context.rb', line 8

def initialize(options = Const::EMPTY_HASH)
  @environment = options.fetch(:environment, Environment.default)
  @template_options = options ? options.dup : {}

  @locale   = @template_options[:locale] ||= I18n.new
  @warnings = []

  self.depth   = 0
  self.partial = false
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



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

def depth
  @depth
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/liquid/parse_context.rb', line 6

def environment
  @environment
end

#error_modeObject (readonly)

Returns the value of attribute error_mode.



6
7
8
# File 'lib/liquid/parse_context.rb', line 6

def error_mode
  @error_mode
end

#line_numberObject

Returns the value of attribute line_number.



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

def line_number
  @line_number
end

#localeObject

Returns the value of attribute locale.



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

def locale
  @locale
end

#partialObject

Returns the value of attribute partial.



6
7
8
# File 'lib/liquid/parse_context.rb', line 6

def partial
  @partial
end

#trim_whitespaceObject

Returns the value of attribute trim_whitespace.



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

def trim_whitespace
  @trim_whitespace
end

#warningsObject (readonly)

Returns the value of attribute warnings.



6
7
8
# File 'lib/liquid/parse_context.rb', line 6

def warnings
  @warnings
end

Instance Method Details

#[](option_key) ⇒ Object



19
20
21
# File 'lib/liquid/parse_context.rb', line 19

def [](option_key)
  @options[option_key]
end

#new_block_bodyObject



23
24
25
# File 'lib/liquid/parse_context.rb', line 23

def new_block_body
  Liquid::BlockBody.new
end

#new_tokenizer(markup, start_line_number: nil, for_liquid_tag: false) ⇒ Object



27
28
29
# File 'lib/liquid/parse_context.rb', line 27

def new_tokenizer(markup, start_line_number: nil, for_liquid_tag: false)
  Tokenizer.new(markup, line_number: start_line_number, for_liquid_tag: for_liquid_tag)
end

#parse_expression(markup) ⇒ Object



31
32
33
# File 'lib/liquid/parse_context.rb', line 31

def parse_expression(markup)
  Expression.parse(markup)
end

#partial_optionsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/liquid/parse_context.rb', line 42

def partial_options
  @partial_options ||= begin
    dont_pass = @template_options[:include_options_blacklist]
    if dont_pass == true
      { locale: locale }
    elsif dont_pass.is_a?(Array)
      @template_options.reject { |k, _v| dont_pass.include?(k) }
    else
      @template_options
    end
  end
end