Class: RBlade::CompilesStatements::CompilesOnce
- Inherits:
-
Object
- Object
- RBlade::CompilesStatements::CompilesOnce
- Defined in:
- lib/rblade/compiler/statements/compiles_once.rb
Instance Method Summary collapse
- #compile_once(args) ⇒ Object
- #compile_prepend_once(args) ⇒ Object
- #compile_push_once(args) ⇒ Object
-
#initialize ⇒ CompilesOnce
constructor
A new instance of CompilesOnce.
Constructor Details
#initialize ⇒ CompilesOnce
Returns a new instance of CompilesOnce.
6 7 8 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 6 def initialize @once_counter = 0 end |
Instance Method Details
#compile_once(args) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 10 def compile_once(args) if args&.count&.> 1 raise RBladeTemplateError.new "Once statement: wrong number of arguments (given #{args.count}, expecting 0 or 1)" end once_id = args.nil? ? ":_#{@once_counter += 1}" : args[0] "unless @_rblade_once_tokens.include? #{once_id};@_rblade_once_tokens<<#{once_id};" end |
#compile_prepend_once(args) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 30 def compile_prepend_once(args) if args&.count != 1 && args&.count != 2 raise RBladeTemplateError.new "Prepend once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)" end @once_counter += 1 once_id = args[1].nil? ? ":_#{@once_counter}" : args[1] "(@_rblade_once_tokens.include? #{once_id}) || @_rblade_once_tokens<<#{once_id} && @_rblade_stack_manager.prepend(#{args[0]}, @output_buffer) do;" end |
#compile_push_once(args) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 20 def compile_push_once(args) if args&.count != 1 && args&.count != 2 raise RBladeTemplateError.new "Push once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)" end @once_counter += 1 once_id = args[1].nil? ? ":_#{@once_counter}" : args[1] "(@_rblade_once_tokens.include? #{once_id}) || @_rblade_once_tokens<<#{once_id} && @_rblade_stack_manager.push(#{args[0]}, @output_buffer) do;" end |