Class: Liquid2::MacroTag
- Defined in:
- lib/liquid2/nodes/tags/macro.rb
Overview
The macro tag.
Constant Summary collapse
- END_BLOCK =
Set["endmacro"]
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#macro_name ⇒ Object
readonly
Returns the value of attribute macro_name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
- #block_scope ⇒ Object
- #children(_static_context, include_partials: true) ⇒ Object
- #expressions ⇒ Object
-
#initialize(token, name, params, block) ⇒ MacroTag
constructor
A new instance of MacroTag.
- #render(context, _buffer) ⇒ Object
Methods inherited from Tag
Methods inherited from Node
#partial_scope, #render_with_disabled_tag_check, #template_scope
Constructor Details
#initialize(token, name, params, block) ⇒ MacroTag
Returns a new instance of MacroTag.
27 28 29 30 31 32 33 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 27 def initialize(token, name, params, block) super(token) @macro_name = name @params = params @block = block @blank = true end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
8 9 10 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 8 def block @block end |
#macro_name ⇒ Object (readonly)
Returns the value of attribute macro_name.
8 9 10 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 8 def macro_name @macro_name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 8 def params @params end |
Class Method Details
.parse(token, parser) ⇒ MacroTag
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 15 def self.parse(token, parser) name = parser.parse_name parser.next if parser.current_kind == :token_comma params = parser.parse_parameters parser.next if parser.current_kind == :token_comma parser.carry_whitespace_control parser.eat(:token_tag_end) block = parser.parse_block(END_BLOCK) parser.eat_empty_tag("endmacro") new(token, name, params, block) end |
Instance Method Details
#block_scope ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 44 def block_scope [ Identifier.new([:token_word, "args", @token.last]), Identifier.new([:token_word, "kwargs", @token.last]), *@params.values.map { |param| Identifier.new([:token_word, param.name, param.token.last]) } ] end |
#children(_static_context, include_partials: true) ⇒ Object
41 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 41 def children(_static_context, include_partials: true) = [@block] |
#expressions ⇒ Object
42 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 42 def expressions = @params.values.filter_map(&:value) |
#render(context, _buffer) ⇒ Object
35 36 37 38 39 |
# File 'lib/liquid2/nodes/tags/macro.rb', line 35 def render(context, _buffer) # Macro tags don't render or evaluate anything, just store their parameter list # and block on the render context so it can be called later by a `call` tag. context.tag_namespace[:macros][@macro_name] = [@params, @block] end |