Class: Luoma::AssignTag
- Defined in:
- lib/luoma/tags/assign.rb,
sig/luoma/tags/assign.rbs
Instance Attribute Summary collapse
-
#bindings ⇒ Object
readonly
Returns the value of attribute bindings.
Attributes inherited from Markup
Class Method Summary collapse
-
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup.
Instance Method Summary collapse
- #expressions ⇒ Object
-
#initialize(token, tag_name, bindings) ⇒ AssignTag
constructor
(t_token, Array) -> void.
- #render(context, buffer) ⇒ Object
- #template_scope ⇒ Object
Methods inherited from Markup
#block_scope, #children, #partial
Constructor Details
Instance Attribute Details
#bindings ⇒ Object (readonly)
Returns the value of attribute bindings.
5 6 7 |
# File 'lib/luoma/tags/assign.rb', line 5 def bindings @bindings end |
Class Method Details
.parse(token, tag_name, parser) ⇒ Markup
(t_token, String, Parser) -> Markup
8 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 |
# File 'lib/luoma/tags/assign.rb', line 8 def self.parse(token, tag_name, parser) bindings = [] #: Array[Item] name = parser.parse_ident assign_token = parser.eat( :token_assign, message: "bad identifier or missing assignment operator" ) bindings << Item.new(assign_token, name, parser.parse_expression) until parser.kind != :token_comma parser.next name = parser.parse_ident assign_token = parser.eat( :token_assign, message: "bad identifier or missing assignment operator" ) bindings << Item.new(assign_token, name, parser.parse_expression) end parser.carry_whitespace_control parser.eat( :token_tag_end, message: "bad expression or missing markup delimiter" ) new(token, tag_name, bindings) end |
Instance Method Details
#expressions ⇒ Object
54 55 56 |
# File 'lib/luoma/tags/assign.rb', line 54 def expressions @bindings.map(&:expr) end |
#render(context, buffer) ⇒ Object
47 48 49 50 51 |
# File 'lib/luoma/tags/assign.rb', line 47 def render(context, buffer) @bindings.each do |binding| context.assign(binding.key.value, binding.expr.evaluate(context)) end end |
#template_scope ⇒ Object
59 60 61 |
# File 'lib/luoma/tags/assign.rb', line 59 def template_scope @bindings.map(&:key) end |