Module: Liquidscript::Generator::Javascript::Objects
- Included in:
- Liquidscript::Generator::Javascript
- Defined in:
- lib/liquidscript/generator/javascript/objects.rb
Instance Method Summary collapse
- #generate_call(code) ⇒ Object
- #generate_class(code) ⇒ Object
- #generate_expression(code) ⇒ Object
- #generate_module(code) ⇒ Object
- #generate_property(code) ⇒ Object
Instance Method Details
#generate_call(code) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/liquidscript/generator/javascript/objects.rb', line 10 def generate_call(code) call = buffer args = buffer args.set_join! ', ' call << "#{replace(code[1])}" code[2..-1].inject(args) do |b, arg| b << replace(arg) end call << "(" << args << ")" end |
#generate_class(code) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/liquidscript/generator/javascript/objects.rb', line 39 def generate_class(code) _context :name => code[1].value, :inherit => code[2], :parts => code[3], :existed => code[:existed], :inheritance => "%{name}.prototype.__proto__ = %{inherit}.prototype;\n", :identifier => "%{name}.prototype.%{value} = %{replace};\n", :istring => "%{name}.prototype[\"%{value}\"] = %{replace};\n", :property => "%{name}.%{value} = %{replace};\n", :head => "%{name} = %{name} || function %{name}() {\n#{indent!}" << "if(this.initialize) {\n#{indent!}this.initialize.apply(this, " + "arguments);\n#{unindent!}}\n#{unindent!}};\n" end |
#generate_expression(code) ⇒ Object
6 7 8 |
# File 'lib/liquidscript/generator/javascript/objects.rb', line 6 def generate_expression(code) "(#{replace(code[1])})" end |
#generate_module(code) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/liquidscript/generator/javascript/objects.rb', line 53 def generate_module(code) _context :name => code[1].value, :parts => code[2], :existed => code[:existed], :head => "%{name} = %{name} || {};\n", :identifier => "%{name}.%{value} = %{replace};\n", :istring => "%{name}[\"%{value}\"] = %{replace};\n", :property => false end |
#generate_property(code) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/liquidscript/generator/javascript/objects.rb', line 24 def generate_property(code) prop = buffer case code[1].type when :variable prop << code[1].to_s when :identifier prop << code[1].value else prop << replace(code[1]) end prop << "." << code[2] end |