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

#compileBlank(args) ⇒ Object



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

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

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

#compileCase(args) ⇒ Object



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

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

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

#compileChecked(args) ⇒ Object



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

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

  "if #{args[0]};_out<<'checked';end;"
end

#compileDefined(args) ⇒ Object



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

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

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

#compileDisabled(args) ⇒ Object



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

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

  "if #{args[0]};_out<<'disabled';end;"
end

#compileElse(args) ⇒ Object



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

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

  "else;"
end

#compileElsif(args) ⇒ Object



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

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

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

#compileEmpty(args) ⇒ Object



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

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

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

#compileEnv(args) ⇒ Object



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

def compileEnv args
  if args&.count != 1
    raise StandardError.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

#compileIf(args) ⇒ Object



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

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

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

#compileNil(args) ⇒ Object



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

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

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

#compilePresent(args) ⇒ Object



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

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

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

#compileProduction(args) ⇒ Object



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

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

  "if Rails.env.production?;"
end

#compileReadonly(args) ⇒ Object



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

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

  "if #{args[0]};_out<<'readonly';end;"
end

#compileRequired(args) ⇒ Object



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

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

  "if #{args[0]};_out<<'required';end;"
end

#compileSelected(args) ⇒ Object



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

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

  "if #{args[0]};_out<<'selected';end;"
end

#compileUnless(args) ⇒ Object



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

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

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

#compileWhen(args) ⇒ Object



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

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

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