class Sprockets::JstProcessor

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'

Public Class Methods

call(input) click to toggle source
# File lib/sprockets/jst_processor.rb, line 32
def self.call(input)
  instance.call(input)
end
default_namespace() click to toggle source
# File lib/sprockets/jst_processor.rb, line 21
def self.default_namespace
  'this.JST'
end
instance() click to toggle source

Public: Return singleton instance with default options.

Returns JstProcessor object.

# File lib/sprockets/jst_processor.rb, line 28
def self.instance
  @instance ||= new
end
new(options = {}) click to toggle source
# File lib/sprockets/jst_processor.rb, line 36
def initialize(options = {})
  @namespace = options[:namespace] || self.class.default_namespace
end

Public Instance Methods

call(input) click to toggle source
# File lib/sprockets/jst_processor.rb, line 40
    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