Class: Liquid::ParseContext
- Inherits:
-
Object
- Object
- Liquid::ParseContext
- Defined in:
- lib/liquid/parse_context.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#error_mode ⇒ Object
readonly
Returns the value of attribute error_mode.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#partial ⇒ Object
Returns the value of attribute partial.
-
#trim_whitespace ⇒ Object
Returns the value of attribute trim_whitespace.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #[](option_key) ⇒ Object
-
#initialize(options = Const::EMPTY_HASH) ⇒ ParseContext
constructor
A new instance of ParseContext.
- #new_block_body ⇒ Object
- #new_parser(input) ⇒ Object
- #new_tokenizer(source, start_line_number: nil, for_liquid_tag: false) ⇒ Object
- #parse_expression(markup) ⇒ Object
- #partial_options ⇒ Object
Constructor Details
#initialize(options = Const::EMPTY_HASH) ⇒ ParseContext
Returns a new instance of ParseContext.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/liquid/parse_context.rb', line 8 def initialize( = Const::EMPTY_HASH) @environment = .fetch(:environment, Environment.default) @template_options = ? .dup : {} @locale = @template_options[:locale] ||= I18n.new @warnings = [] # constructing new StringScanner in Lexer, Tokenizer, etc is expensive # This StringScanner will be shared by all of them @string_scanner = StringScanner.new("") @expression_cache = if [:expression_cache].nil? {} elsif [:expression_cache].respond_to?(:[]) && [:expression_cache].respond_to?(:[]=) [:expression_cache] elsif [:expression_cache] {} end self.depth = 0 self.partial = false end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
5 6 7 |
# File 'lib/liquid/parse_context.rb', line 5 def depth @depth end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/liquid/parse_context.rb', line 6 def environment @environment end |
#error_mode ⇒ Object (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_number ⇒ Object
Returns the value of attribute line_number.
5 6 7 |
# File 'lib/liquid/parse_context.rb', line 5 def line_number @line_number end |
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'lib/liquid/parse_context.rb', line 5 def locale @locale end |
#partial ⇒ Object
Returns the value of attribute partial.
6 7 8 |
# File 'lib/liquid/parse_context.rb', line 6 def partial @partial end |
#trim_whitespace ⇒ Object
Returns the value of attribute trim_whitespace.
5 6 7 |
# File 'lib/liquid/parse_context.rb', line 5 def trim_whitespace @trim_whitespace end |
#warnings ⇒ Object (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
31 32 33 |
# File 'lib/liquid/parse_context.rb', line 31 def [](option_key) @options[option_key] end |
#new_block_body ⇒ Object
35 36 37 |
# File 'lib/liquid/parse_context.rb', line 35 def new_block_body Liquid::BlockBody.new end |
#new_parser(input) ⇒ Object
39 40 41 42 |
# File 'lib/liquid/parse_context.rb', line 39 def new_parser(input) @string_scanner.string = input Parser.new(@string_scanner) end |
#new_tokenizer(source, start_line_number: nil, for_liquid_tag: false) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/liquid/parse_context.rb', line 44 def new_tokenizer(source, start_line_number: nil, for_liquid_tag: false) Tokenizer.new( source: source, string_scanner: @string_scanner, line_number: start_line_number, for_liquid_tag: for_liquid_tag, ) end |
#parse_expression(markup) ⇒ Object
53 54 55 |
# File 'lib/liquid/parse_context.rb', line 53 def parse_expression(markup) Expression.parse(markup, @string_scanner, @expression_cache) end |
#partial_options ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/liquid/parse_context.rb', line 64 def @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 |