Sha256: e65bac4d3462d97daddc2455d530e5eff78b46673a038db755979016e98e0fc4
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
class Jcompiler 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)', official_url: 'brand.blog_url', sex_group: 'brand.blog_sex_switch', image_medium: 'brand.image_file.url(:medium)', image_square: 'brand.image_file.url(:square)', url: 'brand_path(brand)' #labels: '"#{brand.new_arrival? ? \'["NEW"]\' : \'[]\'}"' }.map do |key, 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, bind) brands.map do |brand| "{#{b(brand, bind).join(',')}}" end end 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, binding)" end end ActionView::Template.register_template_handler :jcompiler, JcompilerHandler
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jcompiler-0.1.33 | lib/jcompiler.rb |