Class: RBlade::CompilesStatements::CompilesConditionals

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

Instance Method Summary collapse

Instance Method Details

#compile_blank(args) ⇒ Object



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

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

  "if (#{args[0]}).blank?;"
end

#compile_case(args) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 78

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

  "case #{args[0]};"
end

#compile_checked(args) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 94

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

  "if #{args[0]};@output_buffer.raw_buffer<<-'checked';end;"
end

#compile_defined(args) ⇒ Object



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

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

  "if defined? #{args[0]};"
end

#compile_disabled(args) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 102

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

  "if #{args[0]};@output_buffer.raw_buffer<<-'disabled';end;"
end

#compile_else(args) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 62

def compile_else(args)
  unless args.nil?
    raise RBladeTemplateError.new "Else statement: wrong number of arguments (given #{args.count}, expecting 0)"
  end

  "else;"
end

#compile_elsif(args) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 54

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

  "elsif #{args[0]};"
end

#compile_empty(args) ⇒ Object



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

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

  "if (#{args[0]}).empty?;"
end

#compile_env(args) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 134

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

  environments = args[0].strip

  "if Array.wrap(#{environments}).include?(Rails.env);"
end

#compile_if(args) ⇒ Object



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

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

  "if #{args[0]};"
end

#compile_nil(args) ⇒ Object



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

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

  "if (#{args[0]}).nil?;"
end

#compile_present(args) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 46

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

  "if (#{args[0]}).present?;"
end

#compile_production(args) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 144

def compile_production(args)
  unless args.nil?
    raise RBladeTemplateError.new "Production statement: wrong number of arguments (given #{args.count}, expecting 0)"
  end

  "if Rails.env.production?;"
end

#compile_readonly(args) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 110

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

  "if #{args[0]};@output_buffer.raw_buffer<<-'readonly';end;"
end

#compile_required(args) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 118

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

  "if #{args[0]};@output_buffer.raw_buffer<<-'required';end;"
end

#compile_selected(args) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 126

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

  "if #{args[0]};@output_buffer.raw_buffer<<-'selected';end;"
end

#compile_unless(args) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 70

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

  "unless #{args[0]};"
end

#compile_when(args) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 86

def compile_when(args)
  if args.nil?
    raise RBladeTemplateError.new "When statement: wrong number of arguments (given 0, expecting at least 1)"
  end

  "when #{args.join ","};"
end