Sha256: 9c3f4f97e71af377ede93b03b0edc6ce450743e0a95c5a18d4196e25eba33d81

Contents?: true

Size: 1.16 KB

Versions: 83

Compression:

Stored size: 1.16 KB

Contents

module Sprockets
  # Public: .jst engine.
  #
  # Exports server side compiled templates to an object.
  #
  # Name your template "users/show.jst.ejs", "users/new.jst.eco", etc.
  #
  # To accept the default options
  #
  #     environment.register_engine '.jst',
  #       JstProcessor,
  #       mime_type: 'application/javascript'
  #
  # Change the default namespace.
  #
  #     environment.register_engine '.jst',
  #       JstProcessor.new(namespace: 'App.templates'),
  #       mime_type: 'application/javascript'
  #
  class JstProcessor
    def self.default_namespace
      'this.JST'
    end

    # Public: Return singleton instance with default options.
    #
    # Returns JstProcessor object.
    def self.instance
      @instance ||= new
    end

    def self.call(input)
      instance.call(input)
    end

    def initialize(options = {})
      @namespace = options[:namespace] || self.class.default_namespace
    end

    def call(input)
      data = input[:data].gsub(/$(.)/m, "\\1  ").strip
      key  = input[:name]
      <<-JST
(function() { #{@namespace} || (#{@namespace} = {}); #{@namespace}[#{key.inspect}] = #{data};
}).call(this);
      JST
    end
  end
end

Version data entries

83 entries across 77 versions & 15 rubygems

Version Path
tdiary-5.0.2 vendor/bundle/gems/sprockets-3.7.0/lib/sprockets/jst_processor.rb
sprockets-3.7.0 lib/sprockets/jst_processor.rb
sprockets-3.6.3 lib/sprockets/jst_processor.rb
tdiary-5.0.1 vendor/bundle/gems/sprockets-3.6.2/lib/sprockets/jst_processor.rb
sprockets-3.6.2 lib/sprockets/jst_processor.rb
sprockets-3.6.1 lib/sprockets/jst_processor.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-3.6.0/lib/sprockets/jst_processor.rb
sprockets-3.6.0 lib/sprockets/jst_processor.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/sprockets-3.3.3/lib/sprockets/jst_processor.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/sprockets-3.3.3/lib/sprockets/jst_processor.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.2/lib/sprockets/jst_processor.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/jst_processor.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/sprockets-3.5.1/lib/sprockets/jst_processor.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.1/lib/sprockets/jst_processor.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/sprockets-3.3.3/lib/sprockets/jst_processor.rb
sprockets-3.5.2 lib/sprockets/jst_processor.rb
sprockets-3.5.1 lib/sprockets/jst_processor.rb
sprockets-3.5.0 lib/sprockets/jst_processor.rb
sprockets-3.4.1 lib/sprockets/jst_processor.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/jst_processor.rb