Class: Twig::Node::Yield
Instance Attribute Summary
Attributes inherited from Base
#attributes, #lineno, #nodes, #source_context, #tag
Instance Method Summary collapse
- #compile(compiler) ⇒ Object
-
#initialize(expr, body, arguments, lineno) ⇒ Yield
constructor
A new instance of Yield.
Methods inherited from Base
Constructor Details
#initialize(expr, body, arguments, lineno) ⇒ Yield
Returns a new instance of Yield.
6 7 8 9 |
# File 'lib/twig/node/yield.rb', line 6 def initialize(expr, body, arguments, lineno) arguments = arguments.empty? ? {} : { arguments: } super({ expr:, body: }, arguments, lineno) end |
Instance Method Details
#compile(compiler) ⇒ Object
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 51 |
# File 'lib/twig/node/yield.rb', line 11 def compile(compiler) compiler. write('@output_buffer.append = ('). subcompile(nodes[:expr]). raw(' do') if attributes.key?(:arguments) compiler. raw(" |#{attributes[:arguments].join(', ')}|") end compiler. raw("\n"). indent if attributes.key?(:arguments) compiler. write("context.push_stack\n"). write('context.merge!({') attributes[:arguments].each do |argument| compiler.raw("#{argument}:,") end compiler. raw("})\n") end compiler. subcompile(nodes[:body]). raw("\n") if attributes.key?(:arguments) compiler. write("context.pop_stack\n") end compiler. outdent. write("end);\n") end |