Permalink
Browse files

Make JST namespace configurable

  • Loading branch information...
1 parent 9483f5d commit 9f3474d5df03011dd998ce09e34629f9c4a6c636 @josh josh committed Oct 11, 2011
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/sprockets/jst_processor.rb
@@ -6,14 +6,21 @@ def self.default_mime_type
'application/javascript'
end
+ def self.default_namespace
+ 'this.JST'
+ end
+
def prepare
+ @namespace = self.class.default_namespace
end
+ attr_reader :namespace
+
def evaluate(scope, locals, &block)
<<-JST
(function() {
- this.JST || (this.JST = {});
- this.JST[#{scope.logical_path.inspect}] = #{indent(data)};
+ #{namespace} || (#{namespace} = {});
+ #{namespace}[#{scope.logical_path.inspect}] = #{indent(data)};
}).call(this);
JST
end

1 comment on commit 9f3474d

@first-developer

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.