Sha256: 4a9c3c90a0a5db33d6b70e861c1825d14b8fe29cbbbd8e7b2984f9f7addc1a33
Contents?: true
Size: 839 Bytes
Versions: 16
Compression:
Stored size: 839 Bytes
Contents
module Opal module Rails class TemplateHandler def self.call(template) new.call(template) end def call(template) escaped = template.source.gsub(':', '\:') string = '%q:' + escaped + ':' "Opal.parse('Object.new.instance_eval {' << #{assigns} << #{local_assigns} << #{string} << '}')" end private def local_assigns <<-'RUBY'.strip JSON.parse(local_assigns.to_json).map { |key, val| "#{key} = #{val.inspect};" }.join RUBY end def assigns <<-'RUBY'.strip JSON.parse(@_assigns.to_json).map { |key, val| "@#{key} = #{val.inspect};" }.join RUBY end end end end ActiveSupport.on_load(:action_view) do ActionView::Template.register_template_handler :opal, Opal::Rails::TemplateHandler end
Version data entries
16 entries across 16 versions & 1 rubygems