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

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

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

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

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

def blank?
  @blank
end

#block_delimiterObject


49
50
51
# File 'lib/liquid/block.rb', line 49

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

#block_nameObject


45
46
47
# File 'lib/liquid/block.rb', line 45

def block_name
  @tag_name
end

#nodelistObject


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

def nodelist
  @body.nodelist
end

#parse(tokens) ⇒ Object


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

def parse(tokens)
  @body = BlockBody.new
  while parse_body(@body, tokens)
  end
end

#render(context) ⇒ Object

For backwards compatibility


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

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

#unknown_tag(tag, _params, _tokens) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/liquid/block.rb', line 31

def unknown_tag(tag, _params, _tokens)
  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