Class: RablToJbuilder::SimpleTransformer
- Defined in:
- lib/rabl_to_jbuilder/transformer.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from RablToJbuilder::Base
Instance Method Details
#rewrite_call(exp) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rabl_to_jbuilder/transformer.rb', line 124 def rewrite_call(exp) _, target, meth, *args = exp return exp unless target.nil? if meth == :object || meth == :collection empty elsif meth == :attributes raise "called attributes before declaring `object` or `collection`" unless @object s(:call, json, nil, @object, *args) elsif meth == :attribute raise "called attributes before declaring `object` or `collection`" unless @object # FIXME: options hash and conditions s(:call, json, args[0][1], s(:call, @object, args[0][1])) elsif meth == :extends if @object raise "extends must take a string" unless args[0][0] == :str template = args[0][1] variable = File.basename(File.dirname(args[0][1])).singularize locals_hash = s(:hash, s(:lit, variable.to_sym), @object) s(:call, json, :partial!, args[0], locals_hash) else s(:call, json, :partial!, args[0]) end else exp end end |