Sha256: d7b2024d1c47a5a10047b69a8905840c6300efc430ae4bb9a321a321670fbe32

Contents?: true

Size: 647 Bytes

Versions: 3

Compression:

Stored size: 647 Bytes

Contents

require 'typescript/rails/compiler'

class Typescript::Rails::TemplateHandler
  class << self
    def erb_handler
      @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
    end

    def call(template)
      compiled_source = erb_handler.call(template)
      path = template.identifier.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
      <<-EOS
        ::Typescript::Rails::Compiler.compile('#{path}', (begin;#{compiled_source};end))
      EOS
    end
  end
end

ActiveSupport.on_load(:action_view) do
  ActionView::Template.register_template_handler :ts, Typescript::Rails::TemplateHandler
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typescript-rails-0.6.2 lib/typescript/rails/template_handler.rb
typescript-rails-0.6.1 lib/typescript/rails/template_handler.rb
typescript-rails-0.6.0 lib/typescript/rails/template_handler.rb