Class: Xaases::Js
- Inherits:
-
Object
- Object
- Xaases::Js
- Defined in:
- lib/xaases/js.rb,
lib/xaases/js/function.rb
Defined Under Namespace
Classes: Function
Instance Method Summary collapse
- #call(name, *params) ⇒ Object
- #const(list) ⇒ Object
- #export(name, f) ⇒ Object
- #hash(data) ⇒ Object
- #if(*conditions) ⇒ Object
-
#initialize ⇒ Js
constructor
A new instance of Js.
- #render ⇒ Object
- #strict! ⇒ Object
Constructor Details
#initialize ⇒ Js
Returns a new instance of Js.
4 5 6 |
# File 'lib/xaases/js.rb', line 4 def initialize @s = '' end |
Instance Method Details
#call(name, *params) ⇒ Object
18 19 20 |
# File 'lib/xaases/js.rb', line 18 def call(name, *params) @s += "#{name}(#{params.join(',')});" end |
#const(list) ⇒ Object
12 13 14 15 16 |
# File 'lib/xaases/js.rb', line 12 def const(list) @s += 'const ' + list.map do |key, value| key.to_s + '=' + value.to_s end.join(',') + ';' end |
#export(name, f) ⇒ Object
42 43 44 |
# File 'lib/xaases/js.rb', line 42 def export(name, f) @s += "module.exports.#{name}=(#{f.params.join(',')})=>{#{f.render}};" end |
#hash(data) ⇒ Object
22 23 24 25 26 |
# File 'lib/xaases/js.rb', line 22 def hash(data) @s += '{' + data.map do |key, value| key.to_s + ':' + value.to_s end.join(',') + '}' end |
#if(*conditions) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xaases/js.rb', line 28 def if(*conditions) i = -1 conditions.map do |condition| i += 1 if i == 0 'if{' + condition + '}' elsif i == conditions.length - 1 'else{' + condition + '}' else 'elsif{' + condition + '}' end end.join end |
#render ⇒ Object
46 47 48 |
# File 'lib/xaases/js.rb', line 46 def render @s end |
#strict! ⇒ Object
8 9 10 |
# File 'lib/xaases/js.rb', line 8 def strict! @s = "'use strict';" end |