Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Make JST namespace configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Oct 11, 2011
1 parent 9483f5d commit 9f3474d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/sprockets/jst_processor.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ def self.default_mime_type
'application/javascript' 'application/javascript'
end end


def self.default_namespace
'this.JST'
end

def prepare def prepare
@namespace = self.class.default_namespace
end end


attr_reader :namespace

def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
<<-JST <<-JST
(function() { (function() {
this.JST || (this.JST = {}); #{namespace} || (#{namespace} = {});
this.JST[#{scope.logical_path.inspect}] = #{indent(data)}; #{namespace}[#{scope.logical_path.inspect}] = #{indent(data)};
}).call(this); }).call(this);
JST JST
end end
Expand Down

1 comment on commit 9f3474d

@first-developer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please I need some detals about this commit.

what the purpose of those functions :
'&block' : where is it used?
def evaluate(scope, locals, &block)
<<-JST
(function() {

{namespace} || (#{namespace} = {});

{namespace}[#{scope.logical_path.inspect}] = #{indent(data)};

}).call(this);
JST
end

def indent(string)
string.gsub(/$(.)/m, "\1 ").strip
end

Do you have some more examples ?

I'm lost :D !!! help

Please sign in to comment.