Class: Liquid::Block
Direct Known Subclasses
Capture, Case, Comment, Document, Extends, For, If, Ifchanged, InheritedBlock, Raw, TableRow
Constant Summary
collapse
- IsTag =
/^#{TagStart}/o
- IsVariable =
/^#{VariableStart}/o
- FullToken =
/^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o
- ContentOfVariable =
/^#{VariableStart}(.*)#{VariableEnd}$/o
Instance Attribute Summary
Attributes inherited from Tag
#context, #nodelist
Instance Method Summary
collapse
Methods inherited from Tag
#initialize, #name
Constructor Details
This class inherits a constructor from Liquid::Tag
Instance Method Details
#block_delimiter ⇒ Object
66
67
68
|
# File 'lib/liquid/block.rb', line 66
def block_delimiter
"end#{block_name}"
end
|
#block_name ⇒ Object
70
71
72
|
# File 'lib/liquid/block.rb', line 70
def block_name
@tag_name
end
|
#create_variable(token) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/liquid/block.rb', line 74
def create_variable(token)
token.scan(ContentOfVariable) do |content|
return Variable.new(content.first)
end
raise SyntaxError.new("Variable '#{token}' was not properly terminated with regexp: #{VariableEnd.inspect} ")
end
|
#end_tag ⇒ Object
52
53
|
# File 'lib/liquid/block.rb', line 52
def end_tag
end
|
#parse(tokens) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/liquid/block.rb', line 9
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
case token
when IsTag
if token =~ FullToken
if block_delimiter == $1
end_tag
return
end
if tag = Template.tags[$1]
@nodelist << tag.new($1, $2, tokens, @context)
else
unknown_tag($1, $2, tokens)
end
else
raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} "
end
when IsVariable
@nodelist << create_variable(token)
when ''
else
@nodelist << token
end
end
assert_missing_delimitation!
end
|
#render(context) ⇒ Object
81
82
83
|
# File 'lib/liquid/block.rb', line 81
def render(context)
render_all(@nodelist, context)
end
|
#unknown_tag(tag, params, tokens) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/liquid/block.rb', line 55
def unknown_tag(tag, params, tokens)
case tag
when 'else'
raise SyntaxError, "#{block_name} tag does not expect else tag"
when 'end'
raise SyntaxError, "'end' is not a valid delimiter for #{block_name} tags. use #{block_delimiter}"
else
raise SyntaxError, "Unknown tag '#{tag}'"
end
end
|