Sha256: f0fe92f9f724f78c4eb667d09e4e2d6fa4b0f1633fb9a590635dcf877413c621

Contents?: true

Size: 1.21 KB

Versions: 30

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true
module Sprockets
  # Public: JST transformer.
  #
  # Exports server side compiled templates to an object.
  #
  # Name your template "users/show.ejs", "users/new.eco", etc.
  #
  # To accept the default options
  #
  #     environment.register_transformer
  #       'application/javascript+function',
  #       'application/javascript', JstProcessor
  #
  # Change the default namespace.
  #
  #     environment.register_transformer
  #       'application/javascript+function',
  #       'application/javascript', JstProcessor.new(namespace: 'App.templates')
  #
  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(namespace: self.class.default_namespace)
      @namespace = 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

30 entries across 29 versions & 10 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sprockets-4.2.1/lib/sprockets/jst_processor.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/jst_processor.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/jst_processor.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/jst_processor.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/sprockets-4.1.1/lib/sprockets/jst_processor.rb
sprockets-4.2.1 lib/sprockets/jst_processor.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/sprockets-4.1.1/lib/sprockets/jst_processor.rb
sprockets-4.2.0 lib/sprockets/jst_processor.rb
sprockets-4.1.1 lib/sprockets/jst_processor.rb
sprockets-4.1.0 lib/sprockets/jst_processor.rb
sprockets-4.0.3 lib/sprockets/jst_processor.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/jst_processor.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/jst_processor.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/jst_processor.rb
sprockets-4.0.2 lib/sprockets/jst_processor.rb
sprockets-4.0.1 lib/sprockets/jst_processor.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/jst_processor.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/jst_processor.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/jst_processor.rb