lib/jcompiler.rb in jcompiler-0.1.28 vs lib/jcompiler.rb in jcompiler-0.1.29
- old
+ new
@@ -1,7 +1,8 @@
class Jcompiler
- def self.b(brand)
+ def self.b(brand, bind)
+ bind.local_variable_set(:brand, brand)
{
id: 'brand.id',
name: 'brand.name',
description: 'brand.description',
published_at: 'brand.published_at.utc.iso8601(3)',
@@ -10,31 +11,32 @@
image_medium: 'absolute_url(brand.image_file.url(:medium))',
image_square: 'absolute_url(brand.image_file.url(:square))',
# url: brand_
#labels: '"#{brand.new_arrival? ? \'["NEW"]\' : \'[]\'}"'
}.map do |key, code|
- v = eval(code)
+ v = eval(code, bind)
"\"#{key}\":#{v.is_a?(String) ? ActiveSupport::JSON.encode(v) : v ? v.to_s : 'null'}"
end
end
- def self.a(brands)
+ def self.a(brands, bind)
brands.map do |brand|
- "{#{b(brand).join(',')}}"
+ "{#{b(brand, bind).join(',')}}"
end
end
- def self.code(brands)
- "[#{a(brands).join(',')}]"
+ def self.code(brands, bind)
+ bind.local_variable_set(:brands, brands)
+ "[#{a(brands, bind).join(',')}]"
end
end
class JcompilerHandler
cattr_accessor :default_format
self.default_format = Mime::JSON
def self.call(template)
- "Jcompiler.code(@brands)"
+ "Jcompiler.code(@brands, binding)"
end
end
ActionView::Template.register_template_handler :jcompiler, JcompilerHandler