Class: Sprockets::JstProcessor
- Inherits:
-
Object
- Object
- Sprockets::JstProcessor
- Defined in:
- lib/sprockets/jst_processor.rb
Overview
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 Method Summary collapse
- .call(input) ⇒ Object
- .default_namespace ⇒ Object
-
.instance ⇒ Object
Public: Return singleton instance with default options.
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(options = {}) ⇒ JstProcessor
constructor
A new instance of JstProcessor.
Constructor Details
#initialize(options = {}) ⇒ JstProcessor
Returns a new instance of JstProcessor.
36 37 38 |
# File 'lib/sprockets/jst_processor.rb', line 36 def initialize( = {}) @namespace = [:namespace] || self.class.default_namespace end |
Class Method Details
.call(input) ⇒ Object
32 33 34 |
# File 'lib/sprockets/jst_processor.rb', line 32 def self.call(input) instance.call(input) end |
.default_namespace ⇒ Object
21 22 23 |
# File 'lib/sprockets/jst_processor.rb', line 21 def self.default_namespace 'this.JST' end |
.instance ⇒ Object
Public: Return singleton instance with default options.
Returns JstProcessor object.
28 29 30 |
# File 'lib/sprockets/jst_processor.rb', line 28 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 |