Sha256: fa45f4b7126b202f1fdbf1135ed3e5f5be809801283088bfca635aecdf440ff6

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

require "sprockets"
require "sprockets/traceur/version"
require "traceur-rb"

module Sprockets
  module Traceur
    class Template < Tilt::Template
      self.default_mime_type = 'application/javascript'

      def self.engine_initialized?
        true
      end

      def initialize_engine
      end

      def prepare
      end

      def evaluate(scope, locals, &block)
        name = module_name(scope)
        ::Traceur.compile(data, module_name: name, filename: name)
      end

      private

      def module_name(scope)
        asset_paths = scope.environment.paths
        asset_paths.each do |path|
          if file.start_with?(path)
            return basename(file.gsub(path, ''))
          end
        end
        basename(file)
      end

      def basename(file)
        file.gsub(/\.[^\/]+$/, '').gsub(/^\//, '')
      end
    end
  end

  register_engine '.next', Traceur::Template
  register_engine '.es6', Traceur::Template
  append_path ::Traceur.assets_path
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-traceur-0.0.1 lib/sprockets/traceur.rb