Class: Liquid::Block

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

Direct Known Subclasses

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

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #options

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



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

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

#block_nameObject



52
53
54
# File 'lib/liquid/block.rb', line 52

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 more = 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



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

def unknown_tag(tag, params, tokens)
  case tag
  when 'else'.freeze
    raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze,
                                             :block_name => block_name))
  when 'end'.freeze
    raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze,
                                             :block_name => block_name,
                                             :block_delimiter => block_delimiter))
  else
    raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, :tag => tag))
  end
end

#warningsObject

warnings of this block and all sub-tags



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

def warnings
  all_warnings = []
  all_warnings.concat(@warnings) if @warnings

  (nodelist || []).each do |node|
    all_warnings.concat(node.warnings || []) if node.respond_to?(:warnings)
  end

  all_warnings
end