Permalink
Browse files

Add lint task using JSHint

  • Loading branch information...
mjackson committed Jun 22, 2012
1 parent f7e8434 commit 9079bd88f21e51f44f8de38d1322d6f86419956f
Showing with 21 additions and 7 deletions.
  1. +5 −0 .jshintrc
  2. +5 −0 Rakefile
  3. +11 −7 mustache.js
View
@@ -0,0 +1,5 @@
+{
+ "eqnull": true,
+ "evil": true
+}
+
View
@@ -25,6 +25,11 @@ task :minify do
sh "uglifyjs mustache.js > #{minified_file}"
end
+desc "Run JSHint, requires jshint (see http://www.jshint.com)"
+task :lint do
+ sh "jshint mustache.js"
+end
+
# Creates a task that uses the various template wrappers to make a wrapped
# output file. There is some extra complexity because Dojo and YUI use
# different final locations.
View
@@ -64,7 +64,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
}
function escapeRe(string) {
- return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+ return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}
var entityMap = {
@@ -243,21 +243,25 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
case "object":
if (isArray(value)) {
var buffer = "";
+
for (var i = 0, len = value.length; i < len; ++i) {
buffer += callback(context.push(value[i]), this);
}
+
return buffer;
- } else {
- return callback(context.push(value), this);
}
- break;
+
+ return callback(context.push(value), this);
case "function":
- var sectionText = callback(context, this), self = this;
+ // TODO: The text should be passed to the callback plain, not rendered.
+ var sectionText = callback(context, this),
+ self = this;
+
var scopedRender = function (template) {
return self.render(template, context);
};
+
return value.call(context.view, sectionText, scopedRender) || "";
- break;
default:
if (value) {
return callback(context, this);
@@ -549,7 +553,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// The high-level clearCache, compile, compilePartial, and render functions
// use this default renderer.
- var _renderer = new Renderer;
+ var _renderer = new Renderer();
/**
* Clears all cached templates and partials.

0 comments on commit 9079bd8

Please sign in to comment.