Class: RBlade::CompilesStatements::CompilesStacks

Inherits:
Object
  • Object
show all
Defined in:
lib/rblade/compiler/statements/compiles_stacks.rb

Instance Method Summary collapse

Instance Method Details

#compile_prepend(args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 14

def compile_prepend(args)
  if args&.count != 1
    raise RBladeTemplateError.new "Prepend statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "@_rblade_stack_manager.prepend(#{args[0]}, @output_buffer) do;"
end

#compile_prepend_if(args) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 22

def compile_prepend_if(args)
  if args&.count != 2
    raise RBladeTemplateError.new "Prepend if statement: wrong number of arguments (given #{args&.count}, expecting 2)"
  end

  "(#{args[0]}) && @_rblade_stack_manager.prepend(#{args[1]}, @output_buffer) do;"
end

#compile_push(args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 30

def compile_push(args)
  if args&.count != 1
    raise RBladeTemplateError.new "Push statement: wrong number of arguments (given #{args&.count}, expecting 1)"
  end

  "@_rblade_stack_manager.push(#{args[0]}, @output_buffer) do;"
end

#compile_push_if(args) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 38

def compile_push_if(args)
  if args&.count != 2
    raise RBladeTemplateError.new "Push if statement: wrong number of arguments (given #{args&.count || 0}, expecting 2)"
  end

  "(#{args[0]}) && @_rblade_stack_manager.push(#{args[1]}, @output_buffer) do;"
end

#compile_stack(args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 6

def compile_stack(args)
  if args&.count != 1
    raise RBladeTemplateError.new "Stack statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "@_rblade_stack_manager.initialize_stack(#{args[0]}, @output_buffer);_stacks.push(#{args[0]});"
end