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
sprockets-3.7.5 lib/sprockets/jst_processor.rb
sprockets-3.7.4 lib/sprockets/jst_processor.rb
sprockets-3.7.3 lib/sprockets/jst_processor.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
spiral_form-0.1.1 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
spiral_form-0.1.0 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
tdiary-5.0.11 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/jst_processor.rb
sprokovuln-0.2.0 vendor/ruby/gems/sprockets-3.7.1/lib/sprockets/jst_processor.rb