Class: Liquid::Block

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

Direct Known Subclasses

Capture, Case, Comment, For, If, Ifchanged, Raw, TableRow

Constant Summary collapse

MAX_DEPTH =
100

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #parse_context, #tag_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tag

disable_tags, #name, parse, #raw, #render_to_output_buffer

Methods included from ParserSwitching

#parse_with_selected_parser, #strict_parse_with_error_mode_fallback

Constructor Details

#initialize(tag_name, markup, options) ⇒ Block

Returns a new instance of Block.



7
8
9
10
# File 'lib/liquid/block.rb', line 7

def initialize(tag_name, markup, options)
  super
  @blank = true
end

Class Method Details

.raise_unknown_tag(tag, block_name, block_delimiter, parse_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/liquid/block.rb', line 37

def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
  if tag == 'else'
    raise SyntaxError, parse_context.locale.t(
      "errors.syntax.unexpected_else",
      block_name: block_name,
    )
  elsif tag.start_with?('end')
    raise SyntaxError, parse_context.locale.t(
      "errors.syntax.invalid_delimiter",
      tag: tag,
      block_name: block_name,
      block_delimiter: block_delimiter,
    )
  else
    raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/liquid/block.rb', line 24

def blank?
  @blank
end

#block_delimiterObject



63
64
65
# File 'lib/liquid/block.rb', line 63

def block_delimiter
  @block_delimiter ||= "end#{block_name}"
end

#block_nameObject



59
60
61
# File 'lib/liquid/block.rb', line 59

def block_name
  @tag_name
end

#nodelistObject



28
29
30
# File 'lib/liquid/block.rb', line 28

def nodelist
  @body.nodelist
end

#parse(tokens) ⇒ Object



12
13
14
15
16
17
# File 'lib/liquid/block.rb', line 12

def parse(tokens)
  @body = new_body
  while parse_body(@body, tokens)
  end
  @body.freeze
end

#raise_tag_never_closed(block_name) ⇒ Object

Raises:



55
56
57
# File 'lib/liquid/block.rb', line 55

def raise_tag_never_closed(block_name)
  raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
end

#render(context) ⇒ Object

For backwards compatibility



20
21
22
# File 'lib/liquid/block.rb', line 20

def render(context)
  @body.render(context)
end

#unknown_tag(tag_name, _markup, _tokenizer) ⇒ Object



32
33
34
# File 'lib/liquid/block.rb', line 32

def unknown_tag(tag_name, _markup, _tokenizer)
  Block.raise_unknown_tag(tag_name, block_name, block_delimiter, parse_context)
end