Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 43 lines (39 sloc) 1.032 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
module Sprockets
  # Public: .jst engine.
  #
  # Exports server side compliled templates to an object.
  #
  # Name your template "users/show.ejs.jst", "users/new.eco.jst", 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

    def self.call(*args)
      new.call(*args)
    end

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

    def call(input)
      data = input[:data].gsub(/$(.)/m, "\\1 ").strip
      key = input[:logical_path]
      <<-JST
(function() { #{@namespace} || (#{@namespace} = {}); #{@namespace}[#{key.inspect}] = #{data};
}).call(this);
JST
    end
  end
end
Something went wrong with that request. Please try again.