Sha256: ad3e5f840123ade4b831549fb0888b1cc70f1251cc24a60494973dfaea3c311b

Contents?: true

Size: 889 Bytes

Versions: 3

Compression:

Stored size: 889 Bytes

Contents

require 'tilt'

module Sprockets
  module Umodule
    class Wrapper < Tilt::Template
      @wrapper_template = File.read(File.join(File.dirname(__FILE__), 'umodule.js.erb'))

      class << self
        attr_reader :wrapper_template

        def engine_initialized?
          defined?(ERB)
        end
      end

      def initialize_engine
        require 'erb'
      end

      def prepare
        @erb = ERB.new(wrapper_template)
      end

      def evaluate(context, locals, &block)
        bind(@erb).render(context.logical_path, data)
      end

      private

      def wrapper_template
        self.class.wrapper_template
      end

      def bind(erb)
        Class.new do
          def initialize(erb)
            @erb = erb
          end

          def render(module_name, source)
            @erb.result(binding)
          end
        end.new(erb)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprockets-umodule-1.1.1 lib/sprockets/umodule/wrapper.rb
sprockets-umodule-1.1.0 lib/sprockets/umodule/wrapper.rb
sprockets-umodule-1.0.0 lib/sprockets/umodule/wrapper.rb