Sha256: 585a9978525de043924a6e2a733fa65ad4e73043844a9d47fa50bf051aa46a3c

Contents?: true

Size: 626 Bytes

Versions: 7

Compression:

Stored size: 626 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

7 entries across 7 versions & 1 rubygems

Version Path
typescript-rails-0.6.2.4 lib/typescript/rails/template_handler.rb
typescript-rails-0.6.2.3 lib/typescript/rails/template_handler.rb
typescript-rails-0.6.2.2 lib/typescript/rails/template_handler.rb
typescript-rails-0.5.0 lib/typescript/rails/template_handler.rb
typescript-rails-0.4.2 lib/typescript/rails/template_handler.rb
typescript-rails-0.4.1 lib/typescript/rails/template_handler.rb
typescript-rails-0.4.0 lib/typescript/rails/template_handler.rb