Class: Liquid::Document

Inherits:
Object
  • Object
show all
Includes:
DocumentProfilingHook
Defined in:
lib/liquid/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse_context) ⇒ Document

Returns a new instance of Document.



13
14
15
16
# File 'lib/liquid/document.rb', line 13

def initialize(parse_context)
  @parse_context = parse_context
  @body = new_body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/liquid/document.rb', line 11

def body
  @body
end

#parse_contextObject (readonly)

Returns the value of attribute parse_context.



11
12
13
# File 'lib/liquid/document.rb', line 11

def parse_context
  @parse_context
end

Class Method Details

.parse(tokens, parse_context) ⇒ Object



5
6
7
8
9
# File 'lib/liquid/document.rb', line 5

def self.parse(tokens, parse_context)
  doc = new(parse_context)
  doc.parse(tokens, parse_context)
  doc
end

Instance Method Details

#nodelistObject



18
19
20
# File 'lib/liquid/document.rb', line 18

def nodelist
  @body.nodelist
end

#parse(tokenizer, parse_context) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/liquid/document.rb', line 22

def parse(tokenizer, parse_context)
  while parse_body(tokenizer)
  end
  @body.freeze
rescue SyntaxError => e
  e.line_number ||= parse_context.line_number
  raise
end

#render(context) ⇒ Object



44
45
46
# File 'lib/liquid/document.rb', line 44

def render(context)
  render_to_output_buffer(context, +'')
end

#render_to_output_buffer(context, output) ⇒ Object



40
41
42
# File 'lib/liquid/document.rb', line 40

def render_to_output_buffer(context, output)
  @body.render_to_output_buffer(context, output)
end

#unknown_tag(tag, _markup, _tokenizer) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/liquid/document.rb', line 31

def unknown_tag(tag, _markup, _tokenizer)
  case tag
  when 'else', 'end'
    raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_outer_tag", tag: tag)
  else
    raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
  end
end