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

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #parse_context, #tag_name

Instance Method Summary collapse

Methods inherited from Tag

#name, parse, #raw

Methods included from ParserSwitching

#parse_with_selected_parser

Constructor Details

#initialize(tag_name, markup, options) ⇒ Block

Returns a new instance of Block.



3
4
5
6
# File 'lib/liquid/block.rb', line 3

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

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


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

def blank?
  @blank
end

#block_delimiterObject



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

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

#block_nameObject



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

def block_name
  @tag_name
end

#nodelistObject



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

def nodelist
  @body.nodelist
end

#parse(tokens) ⇒ Object



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

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

#render(context) ⇒ Object



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

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

#unknown_tag(tag, _params, _tokens) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/liquid/block.rb', line 26

def unknown_tag(tag, _params, _tokens)
  case tag
  when 'else'.freeze
    raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_else".freeze,
      block_name: block_name))
  when 'end'.freeze
    raise SyntaxError.new(parse_context.locale.t("errors.syntax.invalid_delimiter".freeze,
      block_name: block_name,
      block_delimiter: block_delimiter))
  else
    raise SyntaxError.new(parse_context.locale.t("errors.syntax.unknown_tag".freeze, tag: tag))
  end
end