From 56a2dfc76dbc57713d05a135e031c6e73fd74657 Mon Sep 17 00:00:00 2001 From: Oskar Krawczyk Date: Sun, 19 Dec 2010 13:48:09 +0100 Subject: [PATCH 01/64] Added MooTools compat plugin --- mustache-mootools/mustache.js.tpl.post | 5 +++++ mustache-mootools/mustache.js.tpl.pre | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 mustache-mootools/mustache.js.tpl.post create mode 100644 mustache-mootools/mustache.js.tpl.pre diff --git a/mustache-mootools/mustache.js.tpl.post b/mustache-mootools/mustache.js.tpl.post new file mode 100644 index 0000000..a1b1b43 --- /dev/null +++ b/mustache-mootools/mustache.js.tpl.post @@ -0,0 +1,5 @@ + + Object.implement('mustache', function(view, partials){ + return Mustache.to_html(view, this, partials); + }); +})(); diff --git a/mustache-mootools/mustache.js.tpl.pre b/mustache-mootools/mustache.js.tpl.pre new file mode 100644 index 0000000..9839f99 --- /dev/null +++ b/mustache-mootools/mustache.js.tpl.pre @@ -0,0 +1,2 @@ +(function(){ + From deedba967ed3a19d7a3bfaa9882230b00dc8c0c6 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 13 Oct 2011 12:01:17 -0400 Subject: [PATCH 02/64] Condition module.exports to make commonjs version work in browsers and not throw an error. --- mustache-commonjs/mustache.js.tpl.post | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mustache-commonjs/mustache.js.tpl.post b/mustache-commonjs/mustache.js.tpl.post index 885803f..f566443 100644 --- a/mustache-commonjs/mustache.js.tpl.post +++ b/mustache-commonjs/mustache.js.tpl.post @@ -1,7 +1,8 @@ +if (typeof module !== 'undefined' && module.exports) { + exports.name = Mustache.name; + exports.version = Mustache.version; -exports.name = Mustache.name; -exports.version = Mustache.version; - -exports.to_html = function() { - return Mustache.to_html.apply(this, arguments); -}; + exports.to_html = function() { + return Mustache.to_html.apply(this, arguments); + }; +} From ae5f8aded0caf984f42e4fb4faae2c6b237d5c54 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 11:44:57 -0800 Subject: [PATCH 03/64] Ignore .rvmrc --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a7ed15c..33f7857 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store +.rvmrc runner.js jquery.mustache.js dojox From ff543bb74d0c1d8f5c85c2e274fbee396604110e Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 12 Dec 2011 16:48:26 -0800 Subject: [PATCH 04/64] Use native Array.isArray when available --- mustache.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mustache.js b/mustache.js index 5677871..038a9f7 100644 --- a/mustache.js +++ b/mustache.js @@ -8,6 +8,12 @@ var Mustache = function() { var regexCache = {}; var Renderer = function() {}; + var _toString = Object.prototype.toString; + + Array.isArray = Array.isArray || function (obj) { + return _toString.call(obj) == "[object Array]"; + } + Renderer.prototype = { otag: "{{", ctag: "}}", @@ -161,14 +167,14 @@ var Mustache = function() { value = that.find(name, context); if (type === "^") { // inverted section - if (!value || that.is_array(value) && value.length === 0) { + if (!value || Array.isArray(value) && value.length === 0) { // false or empty list, render it renderedContent = that.render(content, context, partials, true); } else { renderedContent = ""; } } else if (type === "#") { // normal section - if (that.is_array(value)) { // Enumerable, Let's loop! + if (Array.isArray(value)) { // Enumerable, Let's loop! renderedContent = that.map(value, function(row) { return that.render(content, that.create_context(row), partials, true); }).join(""); @@ -269,7 +275,7 @@ var Mustache = function() { } var value; - + // check for dot notation eg. foo.bar if(name.match(/([a-z_]+)\./ig)){ var childValue = this.walk_context(name, context); @@ -354,10 +360,6 @@ var Mustache = function() { return a && typeof a == "object"; }, - is_array: function(a) { - return Object.prototype.toString.call(a) === '[object Array]'; - }, - /* Gets rid of leading and trailing whitespace */ From f44254cc7ea3a796bd00eab7d9ffade5ec96dacb Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 12:02:21 -0800 Subject: [PATCH 05/64] Use native String#trim when available Uses a method similar to jQuery.trim in jQuery 1.7.1. --- mustache.js | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mustache.js b/mustache.js index 038a9f7..715422c 100644 --- a/mustache.js +++ b/mustache.js @@ -5,15 +5,39 @@ */ var Mustache = function() { - var regexCache = {}; - var Renderer = function() {}; - var _toString = Object.prototype.toString; Array.isArray = Array.isArray || function (obj) { return _toString.call(obj) == "[object Array]"; } + var _trim = String.prototype.trim, trim; + + if (_trim) { + trim = function (text) { + return text == null ? "" : _trim.call(text); + } + } else { + var trimLeft, trimRight; + + // IE doesn't match non-breaking spaces with \s. + if ((/\S/).test("\xA0")) { + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; + } else { + trimLeft = /^\s+/; + trimRight = /\s+$/; + } + + trim = function (text) { + return text == null ? "" : + text.toString().replace(trimLeft, "").replace(trimRight, ""); + } + } + + var regexCache = {}; + var Renderer = function () {}; + Renderer.prototype = { otag: "{{", ctag: "}}", @@ -111,7 +135,7 @@ var Mustache = function() { Tries to find a partial in the curent scope and render it */ render_partial: function(name, context, partials) { - name = this.trim(name); + name = trim(name); if(!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } @@ -267,7 +291,7 @@ var Mustache = function() { from the view object */ find: function(name, context) { - name = this.trim(name); + name = trim(name); // Checks whether a value is thruthy or false or 0 function is_kinda_truthy(bool) { @@ -360,13 +384,6 @@ var Mustache = function() { return a && typeof a == "object"; }, - /* - Gets rid of leading and trailing whitespace - */ - trim: function(s) { - return s.replace(/^\s*|\s*$/g, ""); - }, - /* Why, why, why? Because IE. Cry, cry cry. */ From a20cf0032b60950a5fba361dcc172304e7f0e90c Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 12 Dec 2011 17:01:27 -0800 Subject: [PATCH 06/64] Consistent spacing --- mustache.js | 111 ++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/mustache.js b/mustache.js index 715422c..374c818 100644 --- a/mustache.js +++ b/mustache.js @@ -4,7 +4,7 @@ See http://mustache.github.com/ for more info. */ -var Mustache = function() { +var Mustache = function () { var _toString = Object.prototype.toString; Array.isArray = Array.isArray || function (obj) { @@ -48,16 +48,16 @@ var Mustache = function() { }, context: {}, - render: function(template, context, partials, in_recursion) { + render: function (template, context, partials, in_recursion) { // reset buffer & set context - if(!in_recursion) { + if (!in_recursion) { this.context = context; this.buffer = []; // TODO: make this non-lazy } // fail fast - if(!this.includes("", template)) { - if(in_recursion) { + if (!this.includes("", template)) { + if (in_recursion) { return template; } else { this.send(template); @@ -86,13 +86,13 @@ var Mustache = function() { /* Sends parsed lines */ - send: function(line) { - if(line !== "") { + send: function (line) { + if (line !== "") { this.buffer.push(line); } }, - sendLines: function(text) { + sendLines: function (text) { if (text) { var lines = text.split("\n"); for (var i = 0; i < lines.length; i++) { @@ -104,25 +104,25 @@ var Mustache = function() { /* Looks for %PRAGMAS */ - render_pragmas: function(template) { + render_pragmas: function (template) { // no pragmas - if(!this.includes("%", template)) { + if (!this.includes("%", template)) { return template; } var that = this; - var regex = this.getCachedRegex("render_pragmas", function(otag, ctag) { + var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) { return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g"); }); - return template.replace(regex, function(match, pragma, options) { - if(!that.pragmas_implemented[pragma]) { + return template.replace(regex, function (match, pragma, options) { + if (!that.pragmas_implemented[pragma]) { throw({message: "This implementation of mustache doesn't understand the '" + pragma + "' pragma"}); } that.pragmas[pragma] = {}; - if(options) { + if (options) { var opts = options.split("="); that.pragmas[pragma][opts[0]] = opts[1]; } @@ -134,12 +134,12 @@ var Mustache = function() { /* Tries to find a partial in the curent scope and render it */ - render_partial: function(name, context, partials) { + render_partial: function (name, context, partials) { name = trim(name); - if(!partials || partials[name] === undefined) { + if (!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } - if(typeof(context[name]) != "object") { + if (typeof(context[name]) != "object") { return this.render(partials[name], context, partials, true); } return this.render(partials[name], context[name], partials, true); @@ -148,15 +148,15 @@ var Mustache = function() { /* Renders inverted (^) and normal (#) sections */ - render_section: function(template, context, partials) { - if(!this.includes("#", template) && !this.includes("^", template)) { + render_section: function (template, context, partials) { + if (!this.includes("#", template) && !this.includes("^", template)) { // did not render anything, there were no sections return false; } var that = this; - var regex = this.getCachedRegex("render_section", function(otag, ctag) { + var regex = this.getCachedRegex("render_section", function (otag, ctag) { // This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder return new RegExp( "^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1) @@ -178,7 +178,7 @@ var Mustache = function() { // for each {{#foo}}{{/foo}} section do... - return template.replace(regex, function(match, before, type, name, content, after) { + return template.replace(regex, function (match, before, type, name, content, after) { // before contains only tags, no sections var renderedBefore = before ? that.render_tags(before, context, partials, true) : "", @@ -199,7 +199,7 @@ var Mustache = function() { } } else if (type === "#") { // normal section if (Array.isArray(value)) { // Enumerable, Let's loop! - renderedContent = that.map(value, function(row) { + renderedContent = that.map(value, function (row) { return that.render(content, that.create_context(row), partials, true); }).join(""); } else if (that.is_object(value)) { // Object, Use it as subcontext! @@ -207,7 +207,7 @@ var Mustache = function() { partials, true); } else if (typeof value === "function") { // higher order section - renderedContent = value.call(context, content, function(text) { + renderedContent = value.call(context, content, function (text) { return that.render(text, context, partials, true); }); } else if (value) { // boolean section @@ -224,20 +224,20 @@ var Mustache = function() { /* Replace {{foo}} and friends with values from our view */ - render_tags: function(template, context, partials, in_recursion) { + render_tags: function (template, context, partials, in_recursion) { // tit for tat var that = this; - var new_regex = function() { - return that.getCachedRegex("render_tags", function(otag, ctag) { + var new_regex = function () { + return that.getCachedRegex("render_tags", function (otag, ctag) { return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g"); }); }; var regex = new_regex(); - var tag_replace_callback = function(match, operator, name) { + var tag_replace_callback = function (match, operator, name) { switch(operator) { case "!": // ignore comments return ""; @@ -256,25 +256,25 @@ var Mustache = function() { var lines = template.split("\n"); for(var i = 0; i < lines.length; i++) { lines[i] = lines[i].replace(regex, tag_replace_callback, this); - if(!in_recursion) { + if (!in_recursion) { this.send(lines[i]); } } - if(in_recursion) { + if (in_recursion) { return lines.join("\n"); } }, - set_delimiters: function(delimiters) { + set_delimiters: function (delimiters) { var dels = delimiters.split(" "); this.otag = this.escape_regex(dels[0]); this.ctag = this.escape_regex(dels[1]); }, - escape_regex: function(text) { + escape_regex: function (text) { // thank you Simon Willison - if(!arguments.callee.sRE) { + if (!arguments.callee.sRE) { var specials = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\' @@ -290,7 +290,7 @@ var Mustache = function() { find `name` in current `context`. That is find me a value from the view object */ - find: function(name, context) { + find: function (name, context) { name = trim(name); // Checks whether a value is thruthy or false or 0 @@ -301,41 +301,40 @@ var Mustache = function() { var value; // check for dot notation eg. foo.bar - if(name.match(/([a-z_]+)\./ig)){ + if (name.match(/([a-z_]+)\./ig)) { var childValue = this.walk_context(name, context); - if(is_kinda_truthy(childValue)) { + if (is_kinda_truthy(childValue)) { value = childValue; } - } - else{ - if(is_kinda_truthy(context[name])) { + } else { + if (is_kinda_truthy(context[name])) { value = context[name]; - } else if(is_kinda_truthy(this.context[name])) { + } else if (is_kinda_truthy(this.context[name])) { value = this.context[name]; } } - if(typeof value === "function") { + if (typeof value === "function") { return value.apply(context); } - if(value !== undefined) { + if (value !== undefined) { return value; } // silently ignore unkown variables return ""; }, - walk_context: function(name, context){ + walk_context: function (name, context) { var path = name.split('.'); // if the var doesn't exist in current context, check the top level context var value_context = (context[path[0]] != undefined) ? context : this.context; var value = value_context[path.shift()]; - while(value != undefined && path.length > 0){ + while (value != undefined && path.length > 0) { value_context = value; value = value[path.shift()]; } // if the value is a function, call it, binding the correct context - if(typeof value === "function") { + if (typeof value === "function") { return value.apply(value_context); } return value; @@ -344,16 +343,16 @@ var Mustache = function() { // Utility methods /* includes tag */ - includes: function(needle, haystack) { + includes: function (needle, haystack) { return haystack.indexOf(this.otag + needle) != -1; }, /* Does away with nasty characters */ - escape: function(s) { + escape: function (s) { s = String(s === null ? "" : s); - return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) { + return s.replace(/&(?!\w+;)|["'<>\\]/g, function (s) { switch(s) { case "&": return "&"; case '"': return '"'; @@ -366,12 +365,12 @@ var Mustache = function() { }, // by @langalex, support for arrays of strings - create_context: function(_context) { - if(this.is_object(_context)) { + create_context: function (_context) { + if (this.is_object(_context)) { return _context; } else { var iterator = "."; - if(this.pragmas["IMPLICIT-ITERATOR"]) { + if (this.pragmas["IMPLICIT-ITERATOR"]) { iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; } var ctx = {}; @@ -380,14 +379,14 @@ var Mustache = function() { } }, - is_object: function(a) { + is_object: function (a) { return a && typeof a == "object"; }, /* Why, why, why? Because IE. Cry, cry cry. */ - map: function(array, fn) { + map: function (array, fn) { if (typeof array.map == "function") { return array.map(fn); } else { @@ -400,7 +399,7 @@ var Mustache = function() { } }, - getCachedRegex: function(name, generator) { + getCachedRegex: function (name, generator) { var byOtag = regexCache[this.otag]; if (!byOtag) { byOtag = regexCache[this.otag] = {}; @@ -427,13 +426,13 @@ var Mustache = function() { /* Turns a template and view into HTML */ - to_html: function(template, view, partials, send_fun) { + to_html: function (template, view, partials, send_fun) { var renderer = new Renderer(); - if(send_fun) { + if (send_fun) { renderer.send = send_fun; } renderer.render(template, view || {}, partials); - if(!send_fun) { + if (!send_fun) { return renderer.buffer.join("\n"); } } From 93dd0ddb91159e60da314b3b06b7d78e01672ccf Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 12 Dec 2011 17:02:16 -0800 Subject: [PATCH 07/64] Consistent use of typeof --- mustache.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mustache.js b/mustache.js index 374c818..9d5fd01 100644 --- a/mustache.js +++ b/mustache.js @@ -139,7 +139,7 @@ var Mustache = function () { if (!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } - if (typeof(context[name]) != "object") { + if (typeof context[name] != "object") { return this.render(partials[name], context, partials, true); } return this.render(partials[name], context[name], partials, true); @@ -205,7 +205,7 @@ var Mustache = function () { } else if (that.is_object(value)) { // Object, Use it as subcontext! renderedContent = that.render(content, that.create_context(value), partials, true); - } else if (typeof value === "function") { + } else if (typeof value == "function") { // higher order section renderedContent = value.call(context, content, function (text) { return that.render(text, context, partials, true); @@ -314,7 +314,7 @@ var Mustache = function () { } } - if (typeof value === "function") { + if (typeof value == "function") { return value.apply(context); } if (value !== undefined) { @@ -334,7 +334,7 @@ var Mustache = function () { value = value[path.shift()]; } // if the value is a function, call it, binding the correct context - if (typeof value === "function") { + if (typeof value == "function") { return value.apply(value_context); } return value; From 3bbe1ab9d80854386e774047c16a18f89d3cb60e Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 13 Dec 2011 21:24:28 -0800 Subject: [PATCH 08/64] Fix rendering partials w/o data Thanks drobbins (see https://github.com/janl/mustache.js/pull/113) --- mustache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index 9d5fd01..3db6154 100644 --- a/mustache.js +++ b/mustache.js @@ -139,7 +139,7 @@ var Mustache = function () { if (!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } - if (typeof context[name] != "object") { + if (!context || typeof context[name] != "object") { return this.render(partials[name], context, partials, true); } return this.render(partials[name], context[name], partials, true); From 65eb4220ca866442317750142029cb0892885d24 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 13:33:58 -0800 Subject: [PATCH 09/64] Fix indentation --- Rakefile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Rakefile b/Rakefile index a19c5ea..f72af2a 100644 --- a/Rakefile +++ b/Rakefile @@ -11,6 +11,10 @@ task :spec do end end +def version + File.read("mustache.js").match('version: "([^\"]+)",$')[1] +end + def templated_build(name, opts={}) # Create a rule that uses the .tmpl.{pre,post} stuff to make a final, # wrapped, output file. @@ -25,7 +29,7 @@ def templated_build(name, opts={}) target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" puts "Packaging for #{name}" - sh "mkdir -p #{opts[:location]}" if opts[:location] + mkdir_p opts[:location] if opts[:location] sh "cat #{source}/#{target_js}.tpl.pre mustache.js \ #{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}" @@ -33,10 +37,9 @@ def templated_build(name, opts={}) if opts[:extra] sh "sed -e 's/{{version}}/#{version}/' #{source}/#{opts[:extra]} \ > #{opts[:location]}/#{opts[:extra]}" - end - - puts "Done, see #{opts[:location] || '.'}/#{target_js}" + end + puts "Done, see #{opts[:location] || '.'}/#{target_js}" end end @@ -47,12 +50,6 @@ templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" templated_build "requirejs" - -def version - File.read("mustache.js").match('version: "([^\"]+)",$')[1] -end - - desc "Remove temporary files." task :clean do sh "git clean -fdx" From 89863d714b7e52833418e655fb6991987be8febe Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 14:15:51 -0800 Subject: [PATCH 10/64] Use rake/clean --- Rakefile | 16 +++++++++------- test/mustache_spec.rb | 5 ++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Rakefile b/Rakefile index f72af2a..81dbccc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,8 @@ require 'rake' +require 'rake/clean' + +# See mustache_spec.rb +CLOBBER.include('runner.js') task :default => :spec @@ -23,13 +27,16 @@ def templated_build(name, opts={}) short = name.downcase source = "mustache-#{short}" dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") + target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" + + CLEAN.include(opts[:location] ? opts[:location] : target_js) desc "Package for #{name}" task short.to_sym => dependencies do - target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" - puts "Packaging for #{name}" + mkdir_p opts[:location] if opts[:location] + sh "cat #{source}/#{target_js}.tpl.pre mustache.js \ #{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}" @@ -49,8 +56,3 @@ templated_build "qooxdoo" templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" templated_build "requirejs" - -desc "Remove temporary files." -task :clean do - sh "git clean -fdx" -end diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb index 5ce8bea..2205882 100644 --- a/test/mustache_spec.rb +++ b/test/mustache_spec.rb @@ -175,8 +175,7 @@ describe "mustache" do end context "running in SpiderMonkey (Mozilla, Firefox)" do - p JS_PATH - if !JS_PATH.empty? + if File.exist?(JS_PATH) before(:each) do @run_js = :run_js_js end @@ -196,7 +195,7 @@ describe "mustache" do end context "running in JavaScriptCore (WebKit, Safari)" do - if File.exists?(JSC_PATH) + if File.exist?(JSC_PATH) before(:each) do @run_js = :run_js_jsc end From 9867b8d9172f951abbed30ea8798e26f42a0b860 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 14:31:23 -0800 Subject: [PATCH 11/64] Clean up runner.js --- Rakefile | 3 --- test/mustache_spec.rb | 29 +++++++++++++---------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Rakefile b/Rakefile index 81dbccc..3dd5750 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,6 @@ require 'rake' require 'rake/clean' -# See mustache_spec.rb -CLOBBER.include('runner.js') - task :default => :spec desc "Run all specs" diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb index 2205882..5e94cf9 100644 --- a/test/mustache_spec.rb +++ b/test/mustache_spec.rb @@ -249,22 +249,19 @@ describe "mustache" do end def run_js(runner, js) - send(runner, js) - end - - def run_js_js(js) - File.open("runner.js", 'w') {|f| f << js} - `#{JS_PATH} runner.js` - end - - def run_js_jsc(js) - File.open("runner.js", 'w') {|f| f << js} - `#{JSC_PATH} runner.js` - end + cmd = case runner + when :run_js_js + JS_PATH + when :run_js_jsc + JSC_PATH + when :run_js_rhino + "java #{RHINO_JAR}" + end - def run_js_rhino(js) - File.open("runner.js", 'w') {|f| f << js} - `java #{RHINO_JAR} runner.js` + runner_file = "runner.js" + File.open(runner_file, 'w') {|f| f << js} + `#{cmd} #{runner_file}` + ensure + FileUtils.rm_r(runner_file) end end - From ff40abbbbc73661f4696296b57f3c089dfb0d237 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 14:34:09 -0800 Subject: [PATCH 12/64] Format comment --- Rakefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 3dd5750..cc2830e 100644 --- a/Rakefile +++ b/Rakefile @@ -16,11 +16,10 @@ def version File.read("mustache.js").match('version: "([^\"]+)",$')[1] end +# Creates a rule that uses the .tmpl.{pre,post} stuff to make a final, +# wrapped, output file. There is some extra complexity because Dojo and YUI3 +# use different template files and final locations. def templated_build(name, opts={}) - # Create a rule that uses the .tmpl.{pre,post} stuff to make a final, - # wrapped, output file. - # There is some extra complexity because Dojo and YUI3 use different - # template files and final locations. short = name.downcase source = "mustache-#{short}" dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") From f6273dd6245d6df737753cbce5d2d9a6163987f2 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 5 Dec 2011 13:47:18 -0800 Subject: [PATCH 13/64] Move templates to wrappers directory --- .gitignore | 5 ++++- Rakefile | 6 +++--- mustache-commonjs/package.json | 7 ------- .../commonjs}/mustache.js.tpl.post | 0 .../commonjs}/mustache.js.tpl.pre | 0 {lib => wrappers/commonjs}/package.json | 4 ++-- {mustache-dojo => wrappers/dojo}/mustache.js.tpl.post | 0 {mustache-dojo => wrappers/dojo}/mustache.js.tpl.pre | 0 .../jquery}/jquery.mustache.js.tpl.post | 0 .../jquery}/jquery.mustache.js.tpl.pre | 0 .../qooxdoo}/qooxdoo.mustache.js.tpl.post | 0 .../qooxdoo}/qooxdoo.mustache.js.tpl.pre | 0 .../requirejs}/requirejs.mustache.js.tpl.post | 0 .../requirejs}/requirejs.mustache.js.tpl.pre | 0 {mustache-yui3 => wrappers/yui3}/mustache.js.tpl.post | 0 {mustache-yui3 => wrappers/yui3}/mustache.js.tpl.pre | 0 16 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 mustache-commonjs/package.json rename {mustache-commonjs => wrappers/commonjs}/mustache.js.tpl.post (100%) rename {mustache-commonjs => wrappers/commonjs}/mustache.js.tpl.pre (100%) rename {lib => wrappers/commonjs}/package.json (53%) rename {mustache-dojo => wrappers/dojo}/mustache.js.tpl.post (100%) rename {mustache-dojo => wrappers/dojo}/mustache.js.tpl.pre (100%) rename {mustache-jquery => wrappers/jquery}/jquery.mustache.js.tpl.post (100%) rename {mustache-jquery => wrappers/jquery}/jquery.mustache.js.tpl.pre (100%) rename {mustache-qooxdoo => wrappers/qooxdoo}/qooxdoo.mustache.js.tpl.post (100%) rename {mustache-qooxdoo => wrappers/qooxdoo}/qooxdoo.mustache.js.tpl.pre (100%) rename {mustache-requirejs => wrappers/requirejs}/requirejs.mustache.js.tpl.post (100%) rename {mustache-requirejs => wrappers/requirejs}/requirejs.mustache.js.tpl.pre (100%) rename {mustache-yui3 => wrappers/yui3}/mustache.js.tpl.post (100%) rename {mustache-yui3 => wrappers/yui3}/mustache.js.tpl.pre (100%) diff --git a/.gitignore b/.gitignore index 33f7857..c44d96c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ .DS_Store .rvmrc runner.js +lib jquery.mustache.js +qooxdoo.mustache.js dojox yui3 -commonjs.mustache.js +requirejs.mustache.js + diff --git a/Rakefile b/Rakefile index cc2830e..fb306f7 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ end # use different template files and final locations. def templated_build(name, opts={}) short = name.downcase - source = "mustache-#{short}" + source = File.join("wrappers", short) dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*") target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" @@ -34,12 +34,12 @@ def templated_build(name, opts={}) mkdir_p opts[:location] if opts[:location] sh "cat #{source}/#{target_js}.tpl.pre mustache.js \ - #{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}" + #{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}" # extra if opts[:extra] sh "sed -e 's/{{version}}/#{version}/' #{source}/#{opts[:extra]} \ - > #{opts[:location]}/#{opts[:extra]}" + > #{opts[:location]}/#{opts[:extra]}" end puts "Done, see #{opts[:location] || '.'}/#{target_js}" diff --git a/mustache-commonjs/package.json b/mustache-commonjs/package.json deleted file mode 100644 index 74d3aba..0000000 --- a/mustache-commonjs/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "mustache", - "author": "http://mustache.github.com/", - "description": "{{ mustache }} in JavaScript — Logic-less templates.", - "keywords": ["template"], - "version": "{{version}}" -} diff --git a/mustache-commonjs/mustache.js.tpl.post b/wrappers/commonjs/mustache.js.tpl.post similarity index 100% rename from mustache-commonjs/mustache.js.tpl.post rename to wrappers/commonjs/mustache.js.tpl.post diff --git a/mustache-commonjs/mustache.js.tpl.pre b/wrappers/commonjs/mustache.js.tpl.pre similarity index 100% rename from mustache-commonjs/mustache.js.tpl.pre rename to wrappers/commonjs/mustache.js.tpl.pre diff --git a/lib/package.json b/wrappers/commonjs/package.json similarity index 53% rename from lib/package.json rename to wrappers/commonjs/package.json index 4a4cbb1..ebd7b6f 100644 --- a/lib/package.json +++ b/wrappers/commonjs/package.json @@ -1,8 +1,8 @@ { "name": "mustache", "author": "http://mustache.github.com/", - "description": "{{ mustache }} in JavaScript — Logic-less templates.", + "description": "Logic-less {{mustache}} templates in JavaScript", "keywords": ["template"], - "version": "0.3.1-dev-twitter", + "version": "{{version}}", "main": "./mustache" } diff --git a/mustache-dojo/mustache.js.tpl.post b/wrappers/dojo/mustache.js.tpl.post similarity index 100% rename from mustache-dojo/mustache.js.tpl.post rename to wrappers/dojo/mustache.js.tpl.post diff --git a/mustache-dojo/mustache.js.tpl.pre b/wrappers/dojo/mustache.js.tpl.pre similarity index 100% rename from mustache-dojo/mustache.js.tpl.pre rename to wrappers/dojo/mustache.js.tpl.pre diff --git a/mustache-jquery/jquery.mustache.js.tpl.post b/wrappers/jquery/jquery.mustache.js.tpl.post similarity index 100% rename from mustache-jquery/jquery.mustache.js.tpl.post rename to wrappers/jquery/jquery.mustache.js.tpl.post diff --git a/mustache-jquery/jquery.mustache.js.tpl.pre b/wrappers/jquery/jquery.mustache.js.tpl.pre similarity index 100% rename from mustache-jquery/jquery.mustache.js.tpl.pre rename to wrappers/jquery/jquery.mustache.js.tpl.pre diff --git a/mustache-qooxdoo/qooxdoo.mustache.js.tpl.post b/wrappers/qooxdoo/qooxdoo.mustache.js.tpl.post similarity index 100% rename from mustache-qooxdoo/qooxdoo.mustache.js.tpl.post rename to wrappers/qooxdoo/qooxdoo.mustache.js.tpl.post diff --git a/mustache-qooxdoo/qooxdoo.mustache.js.tpl.pre b/wrappers/qooxdoo/qooxdoo.mustache.js.tpl.pre similarity index 100% rename from mustache-qooxdoo/qooxdoo.mustache.js.tpl.pre rename to wrappers/qooxdoo/qooxdoo.mustache.js.tpl.pre diff --git a/mustache-requirejs/requirejs.mustache.js.tpl.post b/wrappers/requirejs/requirejs.mustache.js.tpl.post similarity index 100% rename from mustache-requirejs/requirejs.mustache.js.tpl.post rename to wrappers/requirejs/requirejs.mustache.js.tpl.post diff --git a/mustache-requirejs/requirejs.mustache.js.tpl.pre b/wrappers/requirejs/requirejs.mustache.js.tpl.pre similarity index 100% rename from mustache-requirejs/requirejs.mustache.js.tpl.pre rename to wrappers/requirejs/requirejs.mustache.js.tpl.pre diff --git a/mustache-yui3/mustache.js.tpl.post b/wrappers/yui3/mustache.js.tpl.post similarity index 100% rename from mustache-yui3/mustache.js.tpl.post rename to wrappers/yui3/mustache.js.tpl.post diff --git a/mustache-yui3/mustache.js.tpl.pre b/wrappers/yui3/mustache.js.tpl.pre similarity index 100% rename from mustache-yui3/mustache.js.tpl.pre rename to wrappers/yui3/mustache.js.tpl.pre From 0e490020877c9bf41e32b9d39b132381ff233e95 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 09:42:54 -0800 Subject: [PATCH 14/64] Add node to test suite --- Rakefile | 2 +- test/mustache_spec.rb | 227 ++++++++++++++++++++++-------------------- 2 files changed, 118 insertions(+), 111 deletions(-) diff --git a/Rakefile b/Rakefile index fb306f7..442e151 100644 --- a/Rakefile +++ b/Rakefile @@ -51,4 +51,4 @@ templated_build "jQuery" templated_build "qooxdoo" templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" -templated_build "requirejs" +templated_build "RequireJS" diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb index 5e94cf9..f89f27c 100644 --- a/test/mustache_spec.rb +++ b/test/mustache_spec.rb @@ -1,55 +1,61 @@ require 'rubygems' require 'json' -__DIR__ = File.dirname(__FILE__) +ROOT = File.expand_path("../..", __FILE__) -testnames = Dir.glob(__DIR__ + '/../examples/*.js').map do |name| +MUSTACHE = File.read(File.join(ROOT, "mustache.js")) + +TESTS = Dir.glob(File.join(ROOT, 'examples', '*.js')).map do |name| File.basename name, '.js' end -non_partials = testnames.select{|t| not t.include? "partial"} -partials = testnames.select{|t| t.include? "partial"} - -def load_test(dir, name, partial=false) - view = File.read(dir + "/../examples/#{name}.js") - template = File.read(dir + "/../examples/#{name}.html").to_json - expect = File.read(dir + "/../examples/#{name}.txt") - if not partial - [view, template, expect] - else - partial = File.read(dir + "/../examples/#{name}.2.html").to_json - [view, template, partial, expect] - end -end +PARTIALS = TESTS.select {|t| t.include? "partial" } +NON_PARTIALS = TESTS.select {|t| not t.include? "partial" } -JS_PATH = `which js`.strip() +NODE_PATH = `which node`.strip +JS_PATH = `which js`.strip JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" RHINO_JAR = "org.mozilla.javascript.tools.shell.Main" -engines_run = 0 +def load_test(name, is_partial=false) + view = File.read(File.join(ROOT, "examples", "#{name}.js")) + template = File.read(File.join(ROOT, "examples", "#{name}.html")).to_json + expect = File.read(File.join(ROOT, "examples", "#{name}.txt")) -describe "mustache" do + test = [view, template, expect] - shared_examples_for "Mustache rendering" do + if is_partial + test << File.read(File.join(ROOT, "examples", "#{name}.2.html")).to_json + end - before(:all) do - engines_run += 1 - mustache = File.read(__DIR__ + "/../mustache.js") - stubbed_gettext = <<-JS - // Stubbed gettext translation method for {{_i}}{{/i}} tags in Mustache. - function _(params) { - if (typeof params === "string") { - return params - } - - return params.text; - } - JS + test +end - @boilerplate = <<-JS - #{mustache} - #{stubbed_gettext} - JS +def run_js(runner, js) + cmd = case runner + when :spidermonkey + JS_PATH + when :jsc + JSC_PATH + when :rhino + "java #{RHINO_JAR}" + when :node + NODE_PATH + end + + runner_file = "runner.js" + File.open(runner_file, 'w') {|file| file.write(js) } + `#{cmd} #{runner_file}` +ensure + FileUtils.rm_r(runner_file) +end + +$engines_run = 0 + +describe "mustache" do + shared_examples_for "mustache rendering" do + before(:all) do + $engines_run += 1 end it "should return the same when invoked multiple times" do @@ -58,8 +64,8 @@ describe "mustache" do Mustache.to_html("x") print(Mustache.to_html("x")); JS - run_js(@run_js, js).should == "x\n" + run_js(@runner, js).should == "x\n" end it "should clear the context after each run" do @@ -72,34 +78,34 @@ describe "mustache" do print('ERROR: ' + e.message); } JS - run_js(@run_js, js).should == "\n" + + run_js(@runner, js).should == "\n" end - non_partials.each do |testname| - describe testname do + NON_PARTIALS.each do |test| + describe test do it "should generate the correct html" do + view, template, expect = load_test(test) - view, template, expect = load_test(__DIR__, testname) - - runner = <<-JS + js = <<-JS try { #{@boilerplate} #{view} var template = #{template}; - var result = Mustache.to_html(template, #{testname}); + var result = Mustache.to_html(template, #{test}); print(result); } catch(e) { print('ERROR: ' + e.message); } JS - run_js(@run_js, runner).should == expect + run_js(@runner, js).should == expect end - it "should sendFun the correct html" do - view, template, expect = load_test(__DIR__, testname) + it "should sendFun the correct html" do + view, template, expect = load_test(test) - runner = <<-JS + js = <<-JS try { #{@boilerplate} #{view} @@ -110,26 +116,24 @@ describe "mustache" do } } var template = #{template}; - Mustache.to_html(template, #{testname}, null, sendFun); + Mustache.to_html(template, #{test}, null, sendFun); print(chunks.join("\\n")); } catch(e) { print('ERROR: ' + e.message); } JS - run_js(@run_js, runner).strip.should == expect.strip + run_js(@runner, js).strip.should == expect.strip end end end - partials.each do |testname| - describe testname do + PARTIALS.each do |test| + describe test do it "should generate the correct html" do + view, template, expect, partial = load_test(test, true) - view, template, partial, expect = - load_test(__DIR__, testname, true) - - runner = <<-JS + js = <<-JS try { #{@boilerplate} #{view} @@ -142,14 +146,13 @@ describe "mustache" do } JS - run_js(@run_js, runner).should == expect + run_js(@runner, js).should == expect end - it "should sendFun the correct html" do - view, template, partial, expect = - load_test(__DIR__, testname, true) + it "should sendFun the correct html" do + view, template, expect, partial = load_test(test, true) - runner = <<-JS + js = <<-JS try { #{@boilerplate} #{view}; @@ -168,100 +171,104 @@ describe "mustache" do } JS - run_js(@run_js, runner).strip.should == expect.strip + run_js(@runner, js).strip.should == expect.strip end end end end - context "running in SpiderMonkey (Mozilla, Firefox)" do - if File.exist?(JS_PATH) - before(:each) do - @run_js = :run_js_js + context "running in node" do + if File.exist?(NODE_PATH) + before(:all) do + $stdout.write "Testing in node " + @runner = :node + @boilerplate = MUSTACHE.dup + @boilerplate << <<-JS + function print(message) { + console.log(message); + } + JS + end + + after(:all) do + puts " Done!" end + it_should_behave_like "mustache rendering" + else + puts "Skipping tests in node (node not found)" + end + end + + context "running in SpiderMonkey (Mozilla, Firefox)" do + if File.exist?(JS_PATH) before(:all) do - puts "\nTesting mustache.js in SpiderMonkey:\n" + $stdout.write "Testing in SpiderMonkey " + @runner = :spidermonkey + @boilerplate = MUSTACHE.dup end after(:all) do - puts "\nDone\n" + puts " Done!" end - it_should_behave_like "Mustache rendering" + it_should_behave_like "mustache rendering" else - puts "\nSkipping tests in SpiderMonkey (js not found)\n" + puts "Skipping tests in SpiderMonkey (js not found)" end end context "running in JavaScriptCore (WebKit, Safari)" do if File.exist?(JSC_PATH) - before(:each) do - @run_js = :run_js_jsc - end - before(:all) do - puts "\nTesting mustache.js in JavaScriptCore:\n" + $stdout.write "Testing in JavaScriptCore " + @runner = :jsc + @boilerplate = MUSTACHE.dup end after(:all) do - puts "\nDone\n" + puts " Done!" end - it_should_behave_like "Mustache rendering" + it_should_behave_like "mustache rendering" else - puts "\nSkipping tests in JavaScriptCore (jsc not found)\n" + puts "Skipping tests in JavaScriptCore (jsc not found)" end end context "running in Rhino (Mozilla)" do - if !`java #{RHINO_JAR} 'foo' 2>&1`.match(/ClassNotFoundException/) - before(:each) do - @run_js = :run_js_rhino - end - + if `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/ before(:all) do - puts "\nTesting mustache.js in Rhino:\n" + $stdout.write "Testing in Rhino " + @runner = :rhino + @boilerplate = MUSTACHE.dup end after(:all) do - puts "\nDone\n" + puts " Done!" end - it_should_behave_like "Mustache rendering" + it_should_behave_like "mustache rendering" else - puts "\nSkipping tests in Rhino (JAR #{RHINO_JAR} was not found)\n" + puts "Skipping tests in Rhino (JAR #{RHINO_JAR} was not found)" end end context "suite" do - before(:all) do - puts "\nVerifying that we ran at the tests in at least one engine\n" + before(:each) do + $stdout.write "Verifying that we ran at the tests in at least one engine ... " end - after(:all) do - puts "\nDone\n" + after(:each) do + if @exception.nil? + puts "OK" + else + puts "ERROR!" + end end it "should have run at least one time" do - engines_run.should > 0 + $engines_run.should > 0 end end - - def run_js(runner, js) - cmd = case runner - when :run_js_js - JS_PATH - when :run_js_jsc - JSC_PATH - when :run_js_rhino - "java #{RHINO_JAR}" - end - - runner_file = "runner.js" - File.open(runner_file, 'w') {|f| f << js} - `#{cmd} #{runner_file}` - ensure - FileUtils.rm_r(runner_file) - end end From f127f48bf4adb5b159d5c36ee6079d2dd8a1fd57 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 09:59:26 -0800 Subject: [PATCH 15/64] Move all tests to spec directory --- Rakefile | 2 +- {examples => spec/_files}/apostrophe.html | 0 {examples => spec/_files}/apostrophe.js | 0 {examples => spec/_files}/apostrophe.txt | 0 .../array_of_partials_implicit_partial.2.html | 0 .../array_of_partials_implicit_partial.html | 0 .../_files}/array_of_partials_implicit_partial.js | 0 .../_files}/array_of_partials_implicit_partial.txt | 0 .../_files}/array_of_partials_partial.2.html | 0 .../_files}/array_of_partials_partial.html | 0 .../_files}/array_of_partials_partial.js | 0 .../_files}/array_of_partials_partial.txt | 0 {examples => spec/_files}/array_of_strings.html | 0 {examples => spec/_files}/array_of_strings.js | 0 {examples => spec/_files}/array_of_strings.txt | 0 .../_files}/array_of_strings_options.html | 0 .../_files}/array_of_strings_options.js | 0 .../_files}/array_of_strings_options.txt | 0 {examples => spec/_files}/array_partial.2.html | 0 {examples => spec/_files}/array_partial.html | 0 {examples => spec/_files}/array_partial.js | 0 {examples => spec/_files}/array_partial.txt | 0 .../_files}/bug_11_eating_whitespace.html | 0 .../_files}/bug_11_eating_whitespace.js | 0 .../_files}/bug_11_eating_whitespace.txt | 0 {examples => spec/_files}/comments.html | 0 {examples => spec/_files}/comments.js | 0 {examples => spec/_files}/comments.txt | 0 {examples => spec/_files}/complex.html | 0 {examples => spec/_files}/complex.js | 0 {examples => spec/_files}/complex.txt | 0 {examples => spec/_files}/delimiters.html | 0 {examples => spec/_files}/delimiters.js | 0 {examples => spec/_files}/delimiters.txt | 0 {examples => spec/_files}/dot_notation.html | 0 {examples => spec/_files}/dot_notation.js | 0 {examples => spec/_files}/dot_notation.txt | 0 {examples => spec/_files}/double_render.html | 0 {examples => spec/_files}/double_render.js | 0 {examples => spec/_files}/double_render.txt | 0 {examples => spec/_files}/empty_partial.2.html | 0 {examples => spec/_files}/empty_partial.html | 0 {examples => spec/_files}/empty_partial.js | 0 {examples => spec/_files}/empty_partial.txt | 0 {examples => spec/_files}/empty_sections.html | 0 {examples => spec/_files}/empty_sections.js | 0 {examples => spec/_files}/empty_sections.txt | 0 {examples => spec/_files}/empty_template.html | 0 {examples => spec/_files}/empty_template.js | 0 {examples => spec/_files}/empty_template.txt | 0 {examples => spec/_files}/error_not_found.html | 0 {examples => spec/_files}/error_not_found.js | 0 {examples => spec/_files}/error_not_found.txt | 0 {examples => spec/_files}/escaped.html | 0 {examples => spec/_files}/escaped.js | 0 {examples => spec/_files}/escaped.txt | 0 .../_files}/higher_order_sections.html | 0 {examples => spec/_files}/higher_order_sections.js | 0 .../_files}/higher_order_sections.txt | 0 {examples => spec/_files}/inverted_section.html | 0 {examples => spec/_files}/inverted_section.js | 0 {examples => spec/_files}/inverted_section.txt | 0 .../_files}/keys_with_questionmarks.html | 0 .../_files}/keys_with_questionmarks.js | 0 .../_files}/keys_with_questionmarks.txt | 0 {examples => spec/_files}/nesting.html | 0 {examples => spec/_files}/nesting.js | 0 {examples => spec/_files}/nesting.txt | 0 {examples => spec/_files}/null_string.html | 0 {examples => spec/_files}/null_string.js | 0 {examples => spec/_files}/null_string.txt | 0 {examples => spec/_files}/partial_recursion.2.html | 0 {examples => spec/_files}/partial_recursion.html | 0 {examples => spec/_files}/partial_recursion.js | 0 {examples => spec/_files}/partial_recursion.txt | 0 .../_files}/recursion_with_same_names.html | 0 .../_files}/recursion_with_same_names.js | 0 .../_files}/recursion_with_same_names.txt | 0 .../_files}/reuse_of_enumerables.html | 0 {examples => spec/_files}/reuse_of_enumerables.js | 0 {examples => spec/_files}/reuse_of_enumerables.txt | 0 {examples => spec/_files}/section_as_context.html | 0 {examples => spec/_files}/section_as_context.js | 0 {examples => spec/_files}/section_as_context.txt | 0 {examples => spec/_files}/simple.html | 0 {examples => spec/_files}/simple.js | 0 {examples => spec/_files}/simple.txt | 0 {examples => spec/_files}/template_partial.2.html | 0 {examples => spec/_files}/template_partial.html | 0 {examples => spec/_files}/template_partial.js | 0 {examples => spec/_files}/template_partial.txt | 0 {examples => spec/_files}/two_in_a_row.html | 0 {examples => spec/_files}/two_in_a_row.js | 0 {examples => spec/_files}/two_in_a_row.txt | 0 {examples => spec/_files}/two_sections.html | 0 {examples => spec/_files}/two_sections.js | 0 {examples => spec/_files}/two_sections.txt | 0 {examples => spec/_files}/unescaped.html | 0 {examples => spec/_files}/unescaped.js | 0 {examples => spec/_files}/unescaped.txt | 0 {examples => spec/_files}/unknown_pragma.html | 0 {examples => spec/_files}/unknown_pragma.js | 0 {examples => spec/_files}/unknown_pragma.txt | 0 {examples => spec/_files}/view_partial.2.html | 0 {examples => spec/_files}/view_partial.html | 0 {examples => spec/_files}/view_partial.js | 0 {examples => spec/_files}/view_partial.txt | 0 .../_files}/whitespace_partial.2.html | 0 {examples => spec/_files}/whitespace_partial.html | 0 {examples => spec/_files}/whitespace_partial.js | 0 {examples => spec/_files}/whitespace_partial.txt | 0 {test => spec}/mustache_spec.rb | 14 ++++++++------ 112 files changed, 9 insertions(+), 7 deletions(-) rename {examples => spec/_files}/apostrophe.html (100%) rename {examples => spec/_files}/apostrophe.js (100%) rename {examples => spec/_files}/apostrophe.txt (100%) rename {examples => spec/_files}/array_of_partials_implicit_partial.2.html (100%) rename {examples => spec/_files}/array_of_partials_implicit_partial.html (100%) rename {examples => spec/_files}/array_of_partials_implicit_partial.js (100%) rename {examples => spec/_files}/array_of_partials_implicit_partial.txt (100%) rename {examples => spec/_files}/array_of_partials_partial.2.html (100%) rename {examples => spec/_files}/array_of_partials_partial.html (100%) rename {examples => spec/_files}/array_of_partials_partial.js (100%) rename {examples => spec/_files}/array_of_partials_partial.txt (100%) rename {examples => spec/_files}/array_of_strings.html (100%) rename {examples => spec/_files}/array_of_strings.js (100%) rename {examples => spec/_files}/array_of_strings.txt (100%) rename {examples => spec/_files}/array_of_strings_options.html (100%) rename {examples => spec/_files}/array_of_strings_options.js (100%) rename {examples => spec/_files}/array_of_strings_options.txt (100%) rename {examples => spec/_files}/array_partial.2.html (100%) rename {examples => spec/_files}/array_partial.html (100%) rename {examples => spec/_files}/array_partial.js (100%) rename {examples => spec/_files}/array_partial.txt (100%) rename {examples => spec/_files}/bug_11_eating_whitespace.html (100%) rename {examples => spec/_files}/bug_11_eating_whitespace.js (100%) rename {examples => spec/_files}/bug_11_eating_whitespace.txt (100%) rename {examples => spec/_files}/comments.html (100%) rename {examples => spec/_files}/comments.js (100%) rename {examples => spec/_files}/comments.txt (100%) rename {examples => spec/_files}/complex.html (100%) rename {examples => spec/_files}/complex.js (100%) rename {examples => spec/_files}/complex.txt (100%) rename {examples => spec/_files}/delimiters.html (100%) rename {examples => spec/_files}/delimiters.js (100%) rename {examples => spec/_files}/delimiters.txt (100%) rename {examples => spec/_files}/dot_notation.html (100%) rename {examples => spec/_files}/dot_notation.js (100%) rename {examples => spec/_files}/dot_notation.txt (100%) rename {examples => spec/_files}/double_render.html (100%) rename {examples => spec/_files}/double_render.js (100%) rename {examples => spec/_files}/double_render.txt (100%) rename {examples => spec/_files}/empty_partial.2.html (100%) rename {examples => spec/_files}/empty_partial.html (100%) rename {examples => spec/_files}/empty_partial.js (100%) rename {examples => spec/_files}/empty_partial.txt (100%) rename {examples => spec/_files}/empty_sections.html (100%) rename {examples => spec/_files}/empty_sections.js (100%) rename {examples => spec/_files}/empty_sections.txt (100%) rename {examples => spec/_files}/empty_template.html (100%) rename {examples => spec/_files}/empty_template.js (100%) rename {examples => spec/_files}/empty_template.txt (100%) rename {examples => spec/_files}/error_not_found.html (100%) rename {examples => spec/_files}/error_not_found.js (100%) rename {examples => spec/_files}/error_not_found.txt (100%) rename {examples => spec/_files}/escaped.html (100%) rename {examples => spec/_files}/escaped.js (100%) rename {examples => spec/_files}/escaped.txt (100%) rename {examples => spec/_files}/higher_order_sections.html (100%) rename {examples => spec/_files}/higher_order_sections.js (100%) rename {examples => spec/_files}/higher_order_sections.txt (100%) rename {examples => spec/_files}/inverted_section.html (100%) rename {examples => spec/_files}/inverted_section.js (100%) rename {examples => spec/_files}/inverted_section.txt (100%) rename {examples => spec/_files}/keys_with_questionmarks.html (100%) rename {examples => spec/_files}/keys_with_questionmarks.js (100%) rename {examples => spec/_files}/keys_with_questionmarks.txt (100%) rename {examples => spec/_files}/nesting.html (100%) rename {examples => spec/_files}/nesting.js (100%) rename {examples => spec/_files}/nesting.txt (100%) rename {examples => spec/_files}/null_string.html (100%) rename {examples => spec/_files}/null_string.js (100%) rename {examples => spec/_files}/null_string.txt (100%) rename {examples => spec/_files}/partial_recursion.2.html (100%) rename {examples => spec/_files}/partial_recursion.html (100%) rename {examples => spec/_files}/partial_recursion.js (100%) rename {examples => spec/_files}/partial_recursion.txt (100%) rename {examples => spec/_files}/recursion_with_same_names.html (100%) rename {examples => spec/_files}/recursion_with_same_names.js (100%) rename {examples => spec/_files}/recursion_with_same_names.txt (100%) rename {examples => spec/_files}/reuse_of_enumerables.html (100%) rename {examples => spec/_files}/reuse_of_enumerables.js (100%) rename {examples => spec/_files}/reuse_of_enumerables.txt (100%) rename {examples => spec/_files}/section_as_context.html (100%) rename {examples => spec/_files}/section_as_context.js (100%) rename {examples => spec/_files}/section_as_context.txt (100%) rename {examples => spec/_files}/simple.html (100%) rename {examples => spec/_files}/simple.js (100%) rename {examples => spec/_files}/simple.txt (100%) rename {examples => spec/_files}/template_partial.2.html (100%) rename {examples => spec/_files}/template_partial.html (100%) rename {examples => spec/_files}/template_partial.js (100%) rename {examples => spec/_files}/template_partial.txt (100%) rename {examples => spec/_files}/two_in_a_row.html (100%) rename {examples => spec/_files}/two_in_a_row.js (100%) rename {examples => spec/_files}/two_in_a_row.txt (100%) rename {examples => spec/_files}/two_sections.html (100%) rename {examples => spec/_files}/two_sections.js (100%) rename {examples => spec/_files}/two_sections.txt (100%) rename {examples => spec/_files}/unescaped.html (100%) rename {examples => spec/_files}/unescaped.js (100%) rename {examples => spec/_files}/unescaped.txt (100%) rename {examples => spec/_files}/unknown_pragma.html (100%) rename {examples => spec/_files}/unknown_pragma.js (100%) rename {examples => spec/_files}/unknown_pragma.txt (100%) rename {examples => spec/_files}/view_partial.2.html (100%) rename {examples => spec/_files}/view_partial.html (100%) rename {examples => spec/_files}/view_partial.js (100%) rename {examples => spec/_files}/view_partial.txt (100%) rename {examples => spec/_files}/whitespace_partial.2.html (100%) rename {examples => spec/_files}/whitespace_partial.html (100%) rename {examples => spec/_files}/whitespace_partial.js (100%) rename {examples => spec/_files}/whitespace_partial.txt (100%) rename {test => spec}/mustache_spec.rb (94%) diff --git a/Rakefile b/Rakefile index 442e151..035c467 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ task :spec do require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| #t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.pattern = 'test/*_spec.rb' + t.pattern = 'spec/*_spec.rb' end end diff --git a/examples/apostrophe.html b/spec/_files/apostrophe.html similarity index 100% rename from examples/apostrophe.html rename to spec/_files/apostrophe.html diff --git a/examples/apostrophe.js b/spec/_files/apostrophe.js similarity index 100% rename from examples/apostrophe.js rename to spec/_files/apostrophe.js diff --git a/examples/apostrophe.txt b/spec/_files/apostrophe.txt similarity index 100% rename from examples/apostrophe.txt rename to spec/_files/apostrophe.txt diff --git a/examples/array_of_partials_implicit_partial.2.html b/spec/_files/array_of_partials_implicit_partial.2.html similarity index 100% rename from examples/array_of_partials_implicit_partial.2.html rename to spec/_files/array_of_partials_implicit_partial.2.html diff --git a/examples/array_of_partials_implicit_partial.html b/spec/_files/array_of_partials_implicit_partial.html similarity index 100% rename from examples/array_of_partials_implicit_partial.html rename to spec/_files/array_of_partials_implicit_partial.html diff --git a/examples/array_of_partials_implicit_partial.js b/spec/_files/array_of_partials_implicit_partial.js similarity index 100% rename from examples/array_of_partials_implicit_partial.js rename to spec/_files/array_of_partials_implicit_partial.js diff --git a/examples/array_of_partials_implicit_partial.txt b/spec/_files/array_of_partials_implicit_partial.txt similarity index 100% rename from examples/array_of_partials_implicit_partial.txt rename to spec/_files/array_of_partials_implicit_partial.txt diff --git a/examples/array_of_partials_partial.2.html b/spec/_files/array_of_partials_partial.2.html similarity index 100% rename from examples/array_of_partials_partial.2.html rename to spec/_files/array_of_partials_partial.2.html diff --git a/examples/array_of_partials_partial.html b/spec/_files/array_of_partials_partial.html similarity index 100% rename from examples/array_of_partials_partial.html rename to spec/_files/array_of_partials_partial.html diff --git a/examples/array_of_partials_partial.js b/spec/_files/array_of_partials_partial.js similarity index 100% rename from examples/array_of_partials_partial.js rename to spec/_files/array_of_partials_partial.js diff --git a/examples/array_of_partials_partial.txt b/spec/_files/array_of_partials_partial.txt similarity index 100% rename from examples/array_of_partials_partial.txt rename to spec/_files/array_of_partials_partial.txt diff --git a/examples/array_of_strings.html b/spec/_files/array_of_strings.html similarity index 100% rename from examples/array_of_strings.html rename to spec/_files/array_of_strings.html diff --git a/examples/array_of_strings.js b/spec/_files/array_of_strings.js similarity index 100% rename from examples/array_of_strings.js rename to spec/_files/array_of_strings.js diff --git a/examples/array_of_strings.txt b/spec/_files/array_of_strings.txt similarity index 100% rename from examples/array_of_strings.txt rename to spec/_files/array_of_strings.txt diff --git a/examples/array_of_strings_options.html b/spec/_files/array_of_strings_options.html similarity index 100% rename from examples/array_of_strings_options.html rename to spec/_files/array_of_strings_options.html diff --git a/examples/array_of_strings_options.js b/spec/_files/array_of_strings_options.js similarity index 100% rename from examples/array_of_strings_options.js rename to spec/_files/array_of_strings_options.js diff --git a/examples/array_of_strings_options.txt b/spec/_files/array_of_strings_options.txt similarity index 100% rename from examples/array_of_strings_options.txt rename to spec/_files/array_of_strings_options.txt diff --git a/examples/array_partial.2.html b/spec/_files/array_partial.2.html similarity index 100% rename from examples/array_partial.2.html rename to spec/_files/array_partial.2.html diff --git a/examples/array_partial.html b/spec/_files/array_partial.html similarity index 100% rename from examples/array_partial.html rename to spec/_files/array_partial.html diff --git a/examples/array_partial.js b/spec/_files/array_partial.js similarity index 100% rename from examples/array_partial.js rename to spec/_files/array_partial.js diff --git a/examples/array_partial.txt b/spec/_files/array_partial.txt similarity index 100% rename from examples/array_partial.txt rename to spec/_files/array_partial.txt diff --git a/examples/bug_11_eating_whitespace.html b/spec/_files/bug_11_eating_whitespace.html similarity index 100% rename from examples/bug_11_eating_whitespace.html rename to spec/_files/bug_11_eating_whitespace.html diff --git a/examples/bug_11_eating_whitespace.js b/spec/_files/bug_11_eating_whitespace.js similarity index 100% rename from examples/bug_11_eating_whitespace.js rename to spec/_files/bug_11_eating_whitespace.js diff --git a/examples/bug_11_eating_whitespace.txt b/spec/_files/bug_11_eating_whitespace.txt similarity index 100% rename from examples/bug_11_eating_whitespace.txt rename to spec/_files/bug_11_eating_whitespace.txt diff --git a/examples/comments.html b/spec/_files/comments.html similarity index 100% rename from examples/comments.html rename to spec/_files/comments.html diff --git a/examples/comments.js b/spec/_files/comments.js similarity index 100% rename from examples/comments.js rename to spec/_files/comments.js diff --git a/examples/comments.txt b/spec/_files/comments.txt similarity index 100% rename from examples/comments.txt rename to spec/_files/comments.txt diff --git a/examples/complex.html b/spec/_files/complex.html similarity index 100% rename from examples/complex.html rename to spec/_files/complex.html diff --git a/examples/complex.js b/spec/_files/complex.js similarity index 100% rename from examples/complex.js rename to spec/_files/complex.js diff --git a/examples/complex.txt b/spec/_files/complex.txt similarity index 100% rename from examples/complex.txt rename to spec/_files/complex.txt diff --git a/examples/delimiters.html b/spec/_files/delimiters.html similarity index 100% rename from examples/delimiters.html rename to spec/_files/delimiters.html diff --git a/examples/delimiters.js b/spec/_files/delimiters.js similarity index 100% rename from examples/delimiters.js rename to spec/_files/delimiters.js diff --git a/examples/delimiters.txt b/spec/_files/delimiters.txt similarity index 100% rename from examples/delimiters.txt rename to spec/_files/delimiters.txt diff --git a/examples/dot_notation.html b/spec/_files/dot_notation.html similarity index 100% rename from examples/dot_notation.html rename to spec/_files/dot_notation.html diff --git a/examples/dot_notation.js b/spec/_files/dot_notation.js similarity index 100% rename from examples/dot_notation.js rename to spec/_files/dot_notation.js diff --git a/examples/dot_notation.txt b/spec/_files/dot_notation.txt similarity index 100% rename from examples/dot_notation.txt rename to spec/_files/dot_notation.txt diff --git a/examples/double_render.html b/spec/_files/double_render.html similarity index 100% rename from examples/double_render.html rename to spec/_files/double_render.html diff --git a/examples/double_render.js b/spec/_files/double_render.js similarity index 100% rename from examples/double_render.js rename to spec/_files/double_render.js diff --git a/examples/double_render.txt b/spec/_files/double_render.txt similarity index 100% rename from examples/double_render.txt rename to spec/_files/double_render.txt diff --git a/examples/empty_partial.2.html b/spec/_files/empty_partial.2.html similarity index 100% rename from examples/empty_partial.2.html rename to spec/_files/empty_partial.2.html diff --git a/examples/empty_partial.html b/spec/_files/empty_partial.html similarity index 100% rename from examples/empty_partial.html rename to spec/_files/empty_partial.html diff --git a/examples/empty_partial.js b/spec/_files/empty_partial.js similarity index 100% rename from examples/empty_partial.js rename to spec/_files/empty_partial.js diff --git a/examples/empty_partial.txt b/spec/_files/empty_partial.txt similarity index 100% rename from examples/empty_partial.txt rename to spec/_files/empty_partial.txt diff --git a/examples/empty_sections.html b/spec/_files/empty_sections.html similarity index 100% rename from examples/empty_sections.html rename to spec/_files/empty_sections.html diff --git a/examples/empty_sections.js b/spec/_files/empty_sections.js similarity index 100% rename from examples/empty_sections.js rename to spec/_files/empty_sections.js diff --git a/examples/empty_sections.txt b/spec/_files/empty_sections.txt similarity index 100% rename from examples/empty_sections.txt rename to spec/_files/empty_sections.txt diff --git a/examples/empty_template.html b/spec/_files/empty_template.html similarity index 100% rename from examples/empty_template.html rename to spec/_files/empty_template.html diff --git a/examples/empty_template.js b/spec/_files/empty_template.js similarity index 100% rename from examples/empty_template.js rename to spec/_files/empty_template.js diff --git a/examples/empty_template.txt b/spec/_files/empty_template.txt similarity index 100% rename from examples/empty_template.txt rename to spec/_files/empty_template.txt diff --git a/examples/error_not_found.html b/spec/_files/error_not_found.html similarity index 100% rename from examples/error_not_found.html rename to spec/_files/error_not_found.html diff --git a/examples/error_not_found.js b/spec/_files/error_not_found.js similarity index 100% rename from examples/error_not_found.js rename to spec/_files/error_not_found.js diff --git a/examples/error_not_found.txt b/spec/_files/error_not_found.txt similarity index 100% rename from examples/error_not_found.txt rename to spec/_files/error_not_found.txt diff --git a/examples/escaped.html b/spec/_files/escaped.html similarity index 100% rename from examples/escaped.html rename to spec/_files/escaped.html diff --git a/examples/escaped.js b/spec/_files/escaped.js similarity index 100% rename from examples/escaped.js rename to spec/_files/escaped.js diff --git a/examples/escaped.txt b/spec/_files/escaped.txt similarity index 100% rename from examples/escaped.txt rename to spec/_files/escaped.txt diff --git a/examples/higher_order_sections.html b/spec/_files/higher_order_sections.html similarity index 100% rename from examples/higher_order_sections.html rename to spec/_files/higher_order_sections.html diff --git a/examples/higher_order_sections.js b/spec/_files/higher_order_sections.js similarity index 100% rename from examples/higher_order_sections.js rename to spec/_files/higher_order_sections.js diff --git a/examples/higher_order_sections.txt b/spec/_files/higher_order_sections.txt similarity index 100% rename from examples/higher_order_sections.txt rename to spec/_files/higher_order_sections.txt diff --git a/examples/inverted_section.html b/spec/_files/inverted_section.html similarity index 100% rename from examples/inverted_section.html rename to spec/_files/inverted_section.html diff --git a/examples/inverted_section.js b/spec/_files/inverted_section.js similarity index 100% rename from examples/inverted_section.js rename to spec/_files/inverted_section.js diff --git a/examples/inverted_section.txt b/spec/_files/inverted_section.txt similarity index 100% rename from examples/inverted_section.txt rename to spec/_files/inverted_section.txt diff --git a/examples/keys_with_questionmarks.html b/spec/_files/keys_with_questionmarks.html similarity index 100% rename from examples/keys_with_questionmarks.html rename to spec/_files/keys_with_questionmarks.html diff --git a/examples/keys_with_questionmarks.js b/spec/_files/keys_with_questionmarks.js similarity index 100% rename from examples/keys_with_questionmarks.js rename to spec/_files/keys_with_questionmarks.js diff --git a/examples/keys_with_questionmarks.txt b/spec/_files/keys_with_questionmarks.txt similarity index 100% rename from examples/keys_with_questionmarks.txt rename to spec/_files/keys_with_questionmarks.txt diff --git a/examples/nesting.html b/spec/_files/nesting.html similarity index 100% rename from examples/nesting.html rename to spec/_files/nesting.html diff --git a/examples/nesting.js b/spec/_files/nesting.js similarity index 100% rename from examples/nesting.js rename to spec/_files/nesting.js diff --git a/examples/nesting.txt b/spec/_files/nesting.txt similarity index 100% rename from examples/nesting.txt rename to spec/_files/nesting.txt diff --git a/examples/null_string.html b/spec/_files/null_string.html similarity index 100% rename from examples/null_string.html rename to spec/_files/null_string.html diff --git a/examples/null_string.js b/spec/_files/null_string.js similarity index 100% rename from examples/null_string.js rename to spec/_files/null_string.js diff --git a/examples/null_string.txt b/spec/_files/null_string.txt similarity index 100% rename from examples/null_string.txt rename to spec/_files/null_string.txt diff --git a/examples/partial_recursion.2.html b/spec/_files/partial_recursion.2.html similarity index 100% rename from examples/partial_recursion.2.html rename to spec/_files/partial_recursion.2.html diff --git a/examples/partial_recursion.html b/spec/_files/partial_recursion.html similarity index 100% rename from examples/partial_recursion.html rename to spec/_files/partial_recursion.html diff --git a/examples/partial_recursion.js b/spec/_files/partial_recursion.js similarity index 100% rename from examples/partial_recursion.js rename to spec/_files/partial_recursion.js diff --git a/examples/partial_recursion.txt b/spec/_files/partial_recursion.txt similarity index 100% rename from examples/partial_recursion.txt rename to spec/_files/partial_recursion.txt diff --git a/examples/recursion_with_same_names.html b/spec/_files/recursion_with_same_names.html similarity index 100% rename from examples/recursion_with_same_names.html rename to spec/_files/recursion_with_same_names.html diff --git a/examples/recursion_with_same_names.js b/spec/_files/recursion_with_same_names.js similarity index 100% rename from examples/recursion_with_same_names.js rename to spec/_files/recursion_with_same_names.js diff --git a/examples/recursion_with_same_names.txt b/spec/_files/recursion_with_same_names.txt similarity index 100% rename from examples/recursion_with_same_names.txt rename to spec/_files/recursion_with_same_names.txt diff --git a/examples/reuse_of_enumerables.html b/spec/_files/reuse_of_enumerables.html similarity index 100% rename from examples/reuse_of_enumerables.html rename to spec/_files/reuse_of_enumerables.html diff --git a/examples/reuse_of_enumerables.js b/spec/_files/reuse_of_enumerables.js similarity index 100% rename from examples/reuse_of_enumerables.js rename to spec/_files/reuse_of_enumerables.js diff --git a/examples/reuse_of_enumerables.txt b/spec/_files/reuse_of_enumerables.txt similarity index 100% rename from examples/reuse_of_enumerables.txt rename to spec/_files/reuse_of_enumerables.txt diff --git a/examples/section_as_context.html b/spec/_files/section_as_context.html similarity index 100% rename from examples/section_as_context.html rename to spec/_files/section_as_context.html diff --git a/examples/section_as_context.js b/spec/_files/section_as_context.js similarity index 100% rename from examples/section_as_context.js rename to spec/_files/section_as_context.js diff --git a/examples/section_as_context.txt b/spec/_files/section_as_context.txt similarity index 100% rename from examples/section_as_context.txt rename to spec/_files/section_as_context.txt diff --git a/examples/simple.html b/spec/_files/simple.html similarity index 100% rename from examples/simple.html rename to spec/_files/simple.html diff --git a/examples/simple.js b/spec/_files/simple.js similarity index 100% rename from examples/simple.js rename to spec/_files/simple.js diff --git a/examples/simple.txt b/spec/_files/simple.txt similarity index 100% rename from examples/simple.txt rename to spec/_files/simple.txt diff --git a/examples/template_partial.2.html b/spec/_files/template_partial.2.html similarity index 100% rename from examples/template_partial.2.html rename to spec/_files/template_partial.2.html diff --git a/examples/template_partial.html b/spec/_files/template_partial.html similarity index 100% rename from examples/template_partial.html rename to spec/_files/template_partial.html diff --git a/examples/template_partial.js b/spec/_files/template_partial.js similarity index 100% rename from examples/template_partial.js rename to spec/_files/template_partial.js diff --git a/examples/template_partial.txt b/spec/_files/template_partial.txt similarity index 100% rename from examples/template_partial.txt rename to spec/_files/template_partial.txt diff --git a/examples/two_in_a_row.html b/spec/_files/two_in_a_row.html similarity index 100% rename from examples/two_in_a_row.html rename to spec/_files/two_in_a_row.html diff --git a/examples/two_in_a_row.js b/spec/_files/two_in_a_row.js similarity index 100% rename from examples/two_in_a_row.js rename to spec/_files/two_in_a_row.js diff --git a/examples/two_in_a_row.txt b/spec/_files/two_in_a_row.txt similarity index 100% rename from examples/two_in_a_row.txt rename to spec/_files/two_in_a_row.txt diff --git a/examples/two_sections.html b/spec/_files/two_sections.html similarity index 100% rename from examples/two_sections.html rename to spec/_files/two_sections.html diff --git a/examples/two_sections.js b/spec/_files/two_sections.js similarity index 100% rename from examples/two_sections.js rename to spec/_files/two_sections.js diff --git a/examples/two_sections.txt b/spec/_files/two_sections.txt similarity index 100% rename from examples/two_sections.txt rename to spec/_files/two_sections.txt diff --git a/examples/unescaped.html b/spec/_files/unescaped.html similarity index 100% rename from examples/unescaped.html rename to spec/_files/unescaped.html diff --git a/examples/unescaped.js b/spec/_files/unescaped.js similarity index 100% rename from examples/unescaped.js rename to spec/_files/unescaped.js diff --git a/examples/unescaped.txt b/spec/_files/unescaped.txt similarity index 100% rename from examples/unescaped.txt rename to spec/_files/unescaped.txt diff --git a/examples/unknown_pragma.html b/spec/_files/unknown_pragma.html similarity index 100% rename from examples/unknown_pragma.html rename to spec/_files/unknown_pragma.html diff --git a/examples/unknown_pragma.js b/spec/_files/unknown_pragma.js similarity index 100% rename from examples/unknown_pragma.js rename to spec/_files/unknown_pragma.js diff --git a/examples/unknown_pragma.txt b/spec/_files/unknown_pragma.txt similarity index 100% rename from examples/unknown_pragma.txt rename to spec/_files/unknown_pragma.txt diff --git a/examples/view_partial.2.html b/spec/_files/view_partial.2.html similarity index 100% rename from examples/view_partial.2.html rename to spec/_files/view_partial.2.html diff --git a/examples/view_partial.html b/spec/_files/view_partial.html similarity index 100% rename from examples/view_partial.html rename to spec/_files/view_partial.html diff --git a/examples/view_partial.js b/spec/_files/view_partial.js similarity index 100% rename from examples/view_partial.js rename to spec/_files/view_partial.js diff --git a/examples/view_partial.txt b/spec/_files/view_partial.txt similarity index 100% rename from examples/view_partial.txt rename to spec/_files/view_partial.txt diff --git a/examples/whitespace_partial.2.html b/spec/_files/whitespace_partial.2.html similarity index 100% rename from examples/whitespace_partial.2.html rename to spec/_files/whitespace_partial.2.html diff --git a/examples/whitespace_partial.html b/spec/_files/whitespace_partial.html similarity index 100% rename from examples/whitespace_partial.html rename to spec/_files/whitespace_partial.html diff --git a/examples/whitespace_partial.js b/spec/_files/whitespace_partial.js similarity index 100% rename from examples/whitespace_partial.js rename to spec/_files/whitespace_partial.js diff --git a/examples/whitespace_partial.txt b/spec/_files/whitespace_partial.txt similarity index 100% rename from examples/whitespace_partial.txt rename to spec/_files/whitespace_partial.txt diff --git a/test/mustache_spec.rb b/spec/mustache_spec.rb similarity index 94% rename from test/mustache_spec.rb rename to spec/mustache_spec.rb index f89f27c..7edc071 100644 --- a/test/mustache_spec.rb +++ b/spec/mustache_spec.rb @@ -1,11 +1,13 @@ require 'rubygems' require 'json' -ROOT = File.expand_path("../..", __FILE__) +ROOT = File.expand_path('../..', __FILE__) +SPEC = File.join(ROOT, 'spec') +FILES = File.join(SPEC, '_files') MUSTACHE = File.read(File.join(ROOT, "mustache.js")) -TESTS = Dir.glob(File.join(ROOT, 'examples', '*.js')).map do |name| +TESTS = Dir.glob(File.join(FILES, '*.js')).map do |name| File.basename name, '.js' end @@ -18,14 +20,14 @@ JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resou RHINO_JAR = "org.mozilla.javascript.tools.shell.Main" def load_test(name, is_partial=false) - view = File.read(File.join(ROOT, "examples", "#{name}.js")) - template = File.read(File.join(ROOT, "examples", "#{name}.html")).to_json - expect = File.read(File.join(ROOT, "examples", "#{name}.txt")) + view = File.read(File.join(FILES, "#{name}.js")) + template = File.read(File.join(FILES, "#{name}.html")).to_json + expect = File.read(File.join(FILES, "#{name}.txt")) test = [view, template, expect] if is_partial - test << File.read(File.join(ROOT, "examples", "#{name}.2.html")).to_json + test << File.read(File.join(FILES, "#{name}.2.html")).to_json end test From 3ac02f342a8cd68a8a56530a794120a57014298c Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 10:26:13 -0800 Subject: [PATCH 16/64] Use .mustache file extension --- spec/_files/{apostrophe.html => apostrophe.mustache} | 0 ...2.html => array_of_partials_implicit_partial.2.mustache} | 0 ...ial.html => array_of_partials_implicit_partial.mustache} | 0 ..._partial.2.html => array_of_partials_partial.2.mustache} | 0 ...ials_partial.html => array_of_partials_partial.mustache} | 0 .../{array_of_strings.html => array_of_strings.mustache} | 0 ...rings_options.html => array_of_strings_options.mustache} | 0 .../{array_partial.2.html => array_partial.2.mustache} | 0 spec/_files/{array_partial.html => array_partial.mustache} | 0 ...ng_whitespace.html => bug_11_eating_whitespace.mustache} | 0 spec/_files/{comments.html => comments.mustache} | 0 spec/_files/{complex.html => complex.mustache} | 0 spec/_files/{delimiters.html => delimiters.mustache} | 0 spec/_files/{dot_notation.html => dot_notation.mustache} | 0 spec/_files/{double_render.html => double_render.mustache} | 0 .../{empty_partial.2.html => empty_partial.2.mustache} | 0 spec/_files/{empty_partial.html => empty_partial.mustache} | 0 .../_files/{empty_sections.html => empty_sections.mustache} | 0 .../_files/{empty_template.html => empty_template.mustache} | 0 .../{error_not_found.html => error_not_found.mustache} | 0 spec/_files/{escaped.html => escaped.mustache} | 0 ...r_order_sections.html => higher_order_sections.mustache} | 0 .../{inverted_section.html => inverted_section.mustache} | 0 ..._questionmarks.html => keys_with_questionmarks.mustache} | 0 spec/_files/{nesting.html => nesting.mustache} | 0 spec/_files/{null_string.html => null_string.mustache} | 0 ...artial_recursion.2.html => partial_recursion.2.mustache} | 0 .../{partial_recursion.html => partial_recursion.mustache} | 0 ...h_same_names.html => recursion_with_same_names.mustache} | 0 ...se_of_enumerables.html => reuse_of_enumerables.mustache} | 0 ...{section_as_context.html => section_as_context.mustache} | 0 spec/_files/{simple.html => simple.mustache} | 0 ...{template_partial.2.html => template_partial.2.mustache} | 0 .../{template_partial.html => template_partial.mustache} | 0 spec/_files/{two_in_a_row.html => two_in_a_row.mustache} | 0 spec/_files/{two_sections.html => two_sections.mustache} | 0 spec/_files/{unescaped.html => unescaped.mustache} | 0 .../_files/{unknown_pragma.html => unknown_pragma.mustache} | 0 .../_files/{view_partial.2.html => view_partial.2.mustache} | 0 spec/_files/{view_partial.html => view_partial.mustache} | 0 ...tespace_partial.2.html => whitespace_partial.2.mustache} | 0 ...{whitespace_partial.html => whitespace_partial.mustache} | 0 spec/mustache_spec.rb | 6 +++--- 43 files changed, 3 insertions(+), 3 deletions(-) rename spec/_files/{apostrophe.html => apostrophe.mustache} (100%) rename spec/_files/{array_of_partials_implicit_partial.2.html => array_of_partials_implicit_partial.2.mustache} (100%) rename spec/_files/{array_of_partials_implicit_partial.html => array_of_partials_implicit_partial.mustache} (100%) rename spec/_files/{array_of_partials_partial.2.html => array_of_partials_partial.2.mustache} (100%) rename spec/_files/{array_of_partials_partial.html => array_of_partials_partial.mustache} (100%) rename spec/_files/{array_of_strings.html => array_of_strings.mustache} (100%) rename spec/_files/{array_of_strings_options.html => array_of_strings_options.mustache} (100%) rename spec/_files/{array_partial.2.html => array_partial.2.mustache} (100%) rename spec/_files/{array_partial.html => array_partial.mustache} (100%) rename spec/_files/{bug_11_eating_whitespace.html => bug_11_eating_whitespace.mustache} (100%) rename spec/_files/{comments.html => comments.mustache} (100%) rename spec/_files/{complex.html => complex.mustache} (100%) rename spec/_files/{delimiters.html => delimiters.mustache} (100%) rename spec/_files/{dot_notation.html => dot_notation.mustache} (100%) rename spec/_files/{double_render.html => double_render.mustache} (100%) rename spec/_files/{empty_partial.2.html => empty_partial.2.mustache} (100%) rename spec/_files/{empty_partial.html => empty_partial.mustache} (100%) rename spec/_files/{empty_sections.html => empty_sections.mustache} (100%) rename spec/_files/{empty_template.html => empty_template.mustache} (100%) rename spec/_files/{error_not_found.html => error_not_found.mustache} (100%) rename spec/_files/{escaped.html => escaped.mustache} (100%) rename spec/_files/{higher_order_sections.html => higher_order_sections.mustache} (100%) rename spec/_files/{inverted_section.html => inverted_section.mustache} (100%) rename spec/_files/{keys_with_questionmarks.html => keys_with_questionmarks.mustache} (100%) rename spec/_files/{nesting.html => nesting.mustache} (100%) rename spec/_files/{null_string.html => null_string.mustache} (100%) rename spec/_files/{partial_recursion.2.html => partial_recursion.2.mustache} (100%) rename spec/_files/{partial_recursion.html => partial_recursion.mustache} (100%) rename spec/_files/{recursion_with_same_names.html => recursion_with_same_names.mustache} (100%) rename spec/_files/{reuse_of_enumerables.html => reuse_of_enumerables.mustache} (100%) rename spec/_files/{section_as_context.html => section_as_context.mustache} (100%) rename spec/_files/{simple.html => simple.mustache} (100%) rename spec/_files/{template_partial.2.html => template_partial.2.mustache} (100%) rename spec/_files/{template_partial.html => template_partial.mustache} (100%) rename spec/_files/{two_in_a_row.html => two_in_a_row.mustache} (100%) rename spec/_files/{two_sections.html => two_sections.mustache} (100%) rename spec/_files/{unescaped.html => unescaped.mustache} (100%) rename spec/_files/{unknown_pragma.html => unknown_pragma.mustache} (100%) rename spec/_files/{view_partial.2.html => view_partial.2.mustache} (100%) rename spec/_files/{view_partial.html => view_partial.mustache} (100%) rename spec/_files/{whitespace_partial.2.html => whitespace_partial.2.mustache} (100%) rename spec/_files/{whitespace_partial.html => whitespace_partial.mustache} (100%) diff --git a/spec/_files/apostrophe.html b/spec/_files/apostrophe.mustache similarity index 100% rename from spec/_files/apostrophe.html rename to spec/_files/apostrophe.mustache diff --git a/spec/_files/array_of_partials_implicit_partial.2.html b/spec/_files/array_of_partials_implicit_partial.2.mustache similarity index 100% rename from spec/_files/array_of_partials_implicit_partial.2.html rename to spec/_files/array_of_partials_implicit_partial.2.mustache diff --git a/spec/_files/array_of_partials_implicit_partial.html b/spec/_files/array_of_partials_implicit_partial.mustache similarity index 100% rename from spec/_files/array_of_partials_implicit_partial.html rename to spec/_files/array_of_partials_implicit_partial.mustache diff --git a/spec/_files/array_of_partials_partial.2.html b/spec/_files/array_of_partials_partial.2.mustache similarity index 100% rename from spec/_files/array_of_partials_partial.2.html rename to spec/_files/array_of_partials_partial.2.mustache diff --git a/spec/_files/array_of_partials_partial.html b/spec/_files/array_of_partials_partial.mustache similarity index 100% rename from spec/_files/array_of_partials_partial.html rename to spec/_files/array_of_partials_partial.mustache diff --git a/spec/_files/array_of_strings.html b/spec/_files/array_of_strings.mustache similarity index 100% rename from spec/_files/array_of_strings.html rename to spec/_files/array_of_strings.mustache diff --git a/spec/_files/array_of_strings_options.html b/spec/_files/array_of_strings_options.mustache similarity index 100% rename from spec/_files/array_of_strings_options.html rename to spec/_files/array_of_strings_options.mustache diff --git a/spec/_files/array_partial.2.html b/spec/_files/array_partial.2.mustache similarity index 100% rename from spec/_files/array_partial.2.html rename to spec/_files/array_partial.2.mustache diff --git a/spec/_files/array_partial.html b/spec/_files/array_partial.mustache similarity index 100% rename from spec/_files/array_partial.html rename to spec/_files/array_partial.mustache diff --git a/spec/_files/bug_11_eating_whitespace.html b/spec/_files/bug_11_eating_whitespace.mustache similarity index 100% rename from spec/_files/bug_11_eating_whitespace.html rename to spec/_files/bug_11_eating_whitespace.mustache diff --git a/spec/_files/comments.html b/spec/_files/comments.mustache similarity index 100% rename from spec/_files/comments.html rename to spec/_files/comments.mustache diff --git a/spec/_files/complex.html b/spec/_files/complex.mustache similarity index 100% rename from spec/_files/complex.html rename to spec/_files/complex.mustache diff --git a/spec/_files/delimiters.html b/spec/_files/delimiters.mustache similarity index 100% rename from spec/_files/delimiters.html rename to spec/_files/delimiters.mustache diff --git a/spec/_files/dot_notation.html b/spec/_files/dot_notation.mustache similarity index 100% rename from spec/_files/dot_notation.html rename to spec/_files/dot_notation.mustache diff --git a/spec/_files/double_render.html b/spec/_files/double_render.mustache similarity index 100% rename from spec/_files/double_render.html rename to spec/_files/double_render.mustache diff --git a/spec/_files/empty_partial.2.html b/spec/_files/empty_partial.2.mustache similarity index 100% rename from spec/_files/empty_partial.2.html rename to spec/_files/empty_partial.2.mustache diff --git a/spec/_files/empty_partial.html b/spec/_files/empty_partial.mustache similarity index 100% rename from spec/_files/empty_partial.html rename to spec/_files/empty_partial.mustache diff --git a/spec/_files/empty_sections.html b/spec/_files/empty_sections.mustache similarity index 100% rename from spec/_files/empty_sections.html rename to spec/_files/empty_sections.mustache diff --git a/spec/_files/empty_template.html b/spec/_files/empty_template.mustache similarity index 100% rename from spec/_files/empty_template.html rename to spec/_files/empty_template.mustache diff --git a/spec/_files/error_not_found.html b/spec/_files/error_not_found.mustache similarity index 100% rename from spec/_files/error_not_found.html rename to spec/_files/error_not_found.mustache diff --git a/spec/_files/escaped.html b/spec/_files/escaped.mustache similarity index 100% rename from spec/_files/escaped.html rename to spec/_files/escaped.mustache diff --git a/spec/_files/higher_order_sections.html b/spec/_files/higher_order_sections.mustache similarity index 100% rename from spec/_files/higher_order_sections.html rename to spec/_files/higher_order_sections.mustache diff --git a/spec/_files/inverted_section.html b/spec/_files/inverted_section.mustache similarity index 100% rename from spec/_files/inverted_section.html rename to spec/_files/inverted_section.mustache diff --git a/spec/_files/keys_with_questionmarks.html b/spec/_files/keys_with_questionmarks.mustache similarity index 100% rename from spec/_files/keys_with_questionmarks.html rename to spec/_files/keys_with_questionmarks.mustache diff --git a/spec/_files/nesting.html b/spec/_files/nesting.mustache similarity index 100% rename from spec/_files/nesting.html rename to spec/_files/nesting.mustache diff --git a/spec/_files/null_string.html b/spec/_files/null_string.mustache similarity index 100% rename from spec/_files/null_string.html rename to spec/_files/null_string.mustache diff --git a/spec/_files/partial_recursion.2.html b/spec/_files/partial_recursion.2.mustache similarity index 100% rename from spec/_files/partial_recursion.2.html rename to spec/_files/partial_recursion.2.mustache diff --git a/spec/_files/partial_recursion.html b/spec/_files/partial_recursion.mustache similarity index 100% rename from spec/_files/partial_recursion.html rename to spec/_files/partial_recursion.mustache diff --git a/spec/_files/recursion_with_same_names.html b/spec/_files/recursion_with_same_names.mustache similarity index 100% rename from spec/_files/recursion_with_same_names.html rename to spec/_files/recursion_with_same_names.mustache diff --git a/spec/_files/reuse_of_enumerables.html b/spec/_files/reuse_of_enumerables.mustache similarity index 100% rename from spec/_files/reuse_of_enumerables.html rename to spec/_files/reuse_of_enumerables.mustache diff --git a/spec/_files/section_as_context.html b/spec/_files/section_as_context.mustache similarity index 100% rename from spec/_files/section_as_context.html rename to spec/_files/section_as_context.mustache diff --git a/spec/_files/simple.html b/spec/_files/simple.mustache similarity index 100% rename from spec/_files/simple.html rename to spec/_files/simple.mustache diff --git a/spec/_files/template_partial.2.html b/spec/_files/template_partial.2.mustache similarity index 100% rename from spec/_files/template_partial.2.html rename to spec/_files/template_partial.2.mustache diff --git a/spec/_files/template_partial.html b/spec/_files/template_partial.mustache similarity index 100% rename from spec/_files/template_partial.html rename to spec/_files/template_partial.mustache diff --git a/spec/_files/two_in_a_row.html b/spec/_files/two_in_a_row.mustache similarity index 100% rename from spec/_files/two_in_a_row.html rename to spec/_files/two_in_a_row.mustache diff --git a/spec/_files/two_sections.html b/spec/_files/two_sections.mustache similarity index 100% rename from spec/_files/two_sections.html rename to spec/_files/two_sections.mustache diff --git a/spec/_files/unescaped.html b/spec/_files/unescaped.mustache similarity index 100% rename from spec/_files/unescaped.html rename to spec/_files/unescaped.mustache diff --git a/spec/_files/unknown_pragma.html b/spec/_files/unknown_pragma.mustache similarity index 100% rename from spec/_files/unknown_pragma.html rename to spec/_files/unknown_pragma.mustache diff --git a/spec/_files/view_partial.2.html b/spec/_files/view_partial.2.mustache similarity index 100% rename from spec/_files/view_partial.2.html rename to spec/_files/view_partial.2.mustache diff --git a/spec/_files/view_partial.html b/spec/_files/view_partial.mustache similarity index 100% rename from spec/_files/view_partial.html rename to spec/_files/view_partial.mustache diff --git a/spec/_files/whitespace_partial.2.html b/spec/_files/whitespace_partial.2.mustache similarity index 100% rename from spec/_files/whitespace_partial.2.html rename to spec/_files/whitespace_partial.2.mustache diff --git a/spec/_files/whitespace_partial.html b/spec/_files/whitespace_partial.mustache similarity index 100% rename from spec/_files/whitespace_partial.html rename to spec/_files/whitespace_partial.mustache diff --git a/spec/mustache_spec.rb b/spec/mustache_spec.rb index 7edc071..e04bec1 100644 --- a/spec/mustache_spec.rb +++ b/spec/mustache_spec.rb @@ -21,13 +21,13 @@ RHINO_JAR = "org.mozilla.javascript.tools.shell.Main" def load_test(name, is_partial=false) view = File.read(File.join(FILES, "#{name}.js")) - template = File.read(File.join(FILES, "#{name}.html")).to_json + template = File.read(File.join(FILES, "#{name}.mustache")).to_json expect = File.read(File.join(FILES, "#{name}.txt")) test = [view, template, expect] if is_partial - test << File.read(File.join(FILES, "#{name}.2.html")).to_json + test << File.read(File.join(FILES, "#{name}.2.mustache")).to_json end test @@ -238,7 +238,7 @@ describe "mustache" do end end - context "running in Rhino (Mozilla)" do + context "running in Rhino (Mozilla, Java)" do if `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/ before(:all) do $stdout.write "Testing in Rhino " From 846d1d349827a03dbd65465a12fd937b3cf9a819 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 10:27:01 -0800 Subject: [PATCH 17/64] Update testing instructions --- TESTING.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ TESTS_HELP.md | 54 -------------------------------------------- 2 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 TESTING.md delete mode 100644 TESTS_HELP.md diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..6abec93 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,62 @@ +## Running the mustache.js Test Suite + +The mustache.js test suite uses the [RSpec](http://rspec.info/) testing +framework. In order to run the tests you'll need to install [Ruby](http://ruby-lang.org/) +as well as the `rake`, `rspec` (>=2), and `json` [RubyGems](http://rubygems.org/). + +### How to install Ruby and the required gems from source + +Make sure you have the required tools to compile it: + + $ apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev + +Download and extract the Ruby source, and install it: + + $ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz + $ tar xvzf stable-snapshot.tar.gz + $ cd ruby + $ ./configure && make && make install + +Download and extract RubyGems, and install it: + + $ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.12.tgz + $ tar xzvf rubygems-1.8.12.tgz + $ cd rubygems-1.8.12 + $ ruby setup.rb + +If you want to update RubyGems: + + $ gem update --system + +Install the required gems: + + $ gem install rake rspec json + +That's it! + +### How to run the tests + +The mustache.js test suite currently uses 4 different JavaScript runtime engines +to maximize portability across platforms and browsers. They are: + + * node + * SpiderMonkey (Mozilla, Firefox) + * JavaScriptCore (WebKit, Safari) + * Rhino (Mozilla, Java) + +When the test suite runs it will automatically determine which platforms are +available on your machine and run on all of them. The suite must run on at least +one platform in order to succeed. + +Once you have at least one JavaScript platform installed, you can run the test +suite with the following command: + + $ rake + +### How to create a test + +All test files live in the spec/_files directory. To create a new test: + + * Create a template file `somename.mustache` + * Create a javascript file with data and functions `somename.js` + * Create a file the expected result `somename.txt` diff --git a/TESTS_HELP.md b/TESTS_HELP.md deleted file mode 100644 index 82a03e5..0000000 --- a/TESTS_HELP.md +++ /dev/null @@ -1,54 +0,0 @@ -## How to run the tests - -To run the test, you need ruby and the following gems installed : rake, rspec (>=2), json - -### How to install ruby and the required gems from source - -Make sure you have the required tools to compile it - - # apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev - -Download ruby source and extract the source - - $ cd ~/ - $ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz - $ tar xvzf stable-snapshot.tar.gz - -Install it - - $ ./configure && make - # make install - -download the last version of RubyGems from here -http://rubyforge.org/frs/?group_id=126 - -Extract the source - - $ tar xzvf rubygems-1.8.4.tgz - -Install it - - $ cd rubygems-1.8.4 - # ruby setup.rb - -If you want to update RubyGems - - # gem update --system - -Install the required gems - - # gem install rake rspec json - -That's it! - -### How to run the tests - - $ rake - -### How to create a test - -- Create a template file `somename.html` -- Create a javascript file with data and functions `somename.js` -- Create a file the expected result `somename.txt` - -Done! From 2f4ccb950f064d56b473f184b5d5a7986b85e40d Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 10:59:51 -0800 Subject: [PATCH 18/64] Update README --- README.md | 169 ++++++++++++++------------------- Rakefile | 2 +- THANKS.md | 22 ----- wrappers/commonjs/package.json | 4 +- 4 files changed, 73 insertions(+), 124 deletions(-) delete mode 100644 THANKS.md diff --git a/README.md b/README.md index f86e7fd..578df7c 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,55 @@ -# mustache.js — Logic-less templates with JavaScript +# mustache.js — Logic-less {{mustache}} templates with JavaScript > What could be more logical awesome than no logic at all? -For a list of implementations (other than JavaScript) and editor -plugins, see . +[mustache.js](http://github.com/janl/mustache.js) is an implementation of the +[Mustache](http://mustache.github.com/) templating system in JavaScript. +[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can +be used for HTML, config files, source code - anything. It works by expanding +tags in a template using values provided in a hash or object. -## Where to Use? +We call it "logic-less" because there are no if statements, else clauses, or for +loops. Instead there are only tags. Some tags are replaced with a value, some +nothing, and others a series of values. -You can use mustache.js rendering stuff in various scenarios. E.g. you can -render templates in your browser, or rendering server-side stuff with -[node.js][node.js], use it for rendering stuff in [CouchDB][couchdb]’s views. +For a language-agnostic overview of Mustache's template syntax, see the +`mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). +## Where to use mustache.js? -## Who Uses Mustache? +You can use mustache.js to render templates in many various scenarios where you +can use JavaScript. For example, you can render templates in a browser, +server-side using [node](http://nodejs.org/), in [CouchDB](http://couchdb.apache.org/) +views, or in almost any other environment where you can use JavaScript. -An updated list is kept on the Github wiki. Add yourself, if you use -mustache.js: +## Who uses mustache.js? +An updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). +Add yourself or your company if you use mustache.js! ## Usage -A quick example how to use mustache.js: +Below is quick example how to use mustache.js: var view = { title: "Joe", calc: function() { return 2 + 4; } - } - - var template = "{{title}} spends {{calc}}"; + }; - var html = Mustache.to_html(template, view); + var html = Mustache.to_html("{{title}} spends {{calc}}", view); -`template` is a simple string with mustache tags and `view` is a JavaScript -object containing the data and any code to render the template. +In this example, the `Mustache.to_html` function takes two parameters: 1) the +[mustache](http://mustache.github.com/) template and 2) a `view` object that +contains the data and code needed to render the template. ## Template Tag Types There are several types of tags currently implemented in mustache.js. -For a language-agnostic overview of Mustache’s template syntax, see the -`mustache(5)` manpage or . - ### Simple Tags Tags are always surrounded by mustaches like this `{{foobar}}`. @@ -267,82 +272,48 @@ own iteration marker: {{bob}} {{/foo}} -## More Examples and Documentation - -See `examples/` for more goodies and read the [original mustache docs][m] - -## Command Line - -See `mustache(1)` man page or - -for command line docs. - -Or just install it as a RubyGem: - - $ gem install mustache - $ mustache -h - -[m]: http://github.com/defunkt/mustache/#readme -[node.js]: http://nodejs.org -[couchdb]: http://couchdb.apache.org - - -## Plugins for jQuery, Dojo, Yui, CommonJS, qooxdoo - -This repository lets you build modules for [jQuery][], [Dojo][], [Yui][] and -[CommonJS][] / [Node.js][] with the help of `rake`. - -NOTE: The default `rake` task is only used for testing and require rspec to be -installed (see below). - -Run `rake jquery` to get a jQuery compatible plugin file in the -`mustache-jquery/` directory. - -Run `rake dojo` to get a Dojo compatible plugin file in the `mustache-dojo/` -directory. - -Run `rake yui` to get a Yui compatible plugin file in the `mustache-yui/` -directory. - -Run `rake commonjs` to get a CommonJS compatible plugin file in the -`mustache-commonjs/` directory which you can also use with [Node.js][]. - -Run `rake qooxdoo` to get a qooxdoo compatible file named `qooxdoo.mustache.js`. - -## Testing - -NOTE: You will need to install rspec first by running `gem install rspec`. - -To run the mustache.js test suite, run `rake spec`. All specs will be run first with JavaScriptCore (using `jsc`) -and again with Rhino, using `java org.mozilla.javascript.tools.shell.Main`. - -JavaScriptCore is used from the OSX default location: - - /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc - -To install Rhino on OSX, follow [these instructions](Rhino Install). - -### Adding Tests - -Tests are located in the `examples/` directory. Adding a new test requires three files. Here's an example to add a test named "foo": - -`examples/foo.html` (the template): - - foo {{bar}} - -`examples/foo.js` (the view context): - - var foo = { - bar: "baz" - }; - -`examples/foo.txt` (the expected output): - - foo baz - -[jQuery]: http://jquery.com/ -[Dojo]: http://www.dojotoolkit.org/ -[Yui]: http://developer.yahoo.com/yui/ -[CommonJS]: http://www.commonjs.org/ -[Node.js]: http://nodejs.org/ -[Rhino Install]: http://michaux.ca/articles/installing-rhino-on-os-x +## Plugins for JavaScript Libraries + +mustache.js may be built specifically for several different client libraries +and platforms, including the following: + + - [node](http://nodejs.org/) (or other CommonJS platforms) + - [jQuery](http://jquery.com/) + - [Dojo](http://www.dojotoolkit.org/) + - [YUI](http://developer.yahoo.com/yui/) + - [RequireJS](http://requirejs.org/) + - [qooxdoo](http://qooxdoo.org/) + +These may be built using [Rake](http://rake.rubyforge.org/) and one of the +following commands: + + $ rake commonjs + $ rake jquery + $ rake dojo + $ rake yui + $ rake requirejs + $ rake qooxdoo + +## Thanks + +Mustache.js wouldn't kick ass if it weren't for these fine souls: + + * Chris Wanstrath / defunkt + * Alexander Lang / langalex + * Sebastian Cohnen / tisba + * J Chris Anderson / jchris + * Tom Robinson / tlrobinson + * Aaron Quint / quirkey + * Douglas Crockford + * Nikita Vasilyev / NV + * Elise Wood / glytch + * Damien Mathieu / dmathieu + * Jakub Kuźma / qoobaa + * Will Leinweber / will + * dpree + * Jason Smith / jhs + * Aaron Gibralter / agibralter + * Ross Boucher / boucher + * Matt Sanford / mzsanford + * Ben Cherry / bcherry + * Michael Jackson / mjijackson diff --git a/Rakefile b/Rakefile index 035c467..16bc724 100644 --- a/Rakefile +++ b/Rakefile @@ -48,7 +48,7 @@ end templated_build "CommonJS", :location => "lib", :extra => "package.json" templated_build "jQuery" -templated_build "qooxdoo" templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" templated_build "RequireJS" +templated_build "qooxdoo" diff --git a/THANKS.md b/THANKS.md deleted file mode 100644 index 22418c8..0000000 --- a/THANKS.md +++ /dev/null @@ -1,22 +0,0 @@ -# Thanks - -Mustache.js wouldn't kick ass if it weren't for these fine souls: - - * Chris Wanstrath / defunkt - * Alexander Lang / langalex - * Sebastian Cohnen / tisba - * J Chris Anderson / jchris - * Tom Robinson / tlrobinson - * Aaron Quint / quirkey - * Douglas Crockford - * Nikita Vasilyev / NV - * Elise Wood / glytch - * Damien Mathieu / dmathieu - * Jakub Kuźma / qoobaa - * Will Leinweber / will - * dpree - * Jason Smith / jhs - * Aaron Gibralter / agibralter - * Ross Boucher / boucher - * Matt Sanford / mzsanford - * Ben Cherry / bcherry diff --git a/wrappers/commonjs/package.json b/wrappers/commonjs/package.json index ebd7b6f..8e13993 100644 --- a/wrappers/commonjs/package.json +++ b/wrappers/commonjs/package.json @@ -1,8 +1,8 @@ { "name": "mustache", "author": "http://mustache.github.com/", - "description": "Logic-less {{mustache}} templates in JavaScript", - "keywords": ["template"], + "description": "Logic-less {{mustache}} templates with JavaScript", + "keywords": ["template", "templates", "mustache"], "version": "{{version}}", "main": "./mustache" } From 9a8ff7638ac7cabe1513378423b4c567029ebc21 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 14 Dec 2011 11:10:56 -0800 Subject: [PATCH 19/64] Refactor escapeHTML --- mustache.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/mustache.js b/mustache.js index 3db6154..47def07 100644 --- a/mustache.js +++ b/mustache.js @@ -35,6 +35,15 @@ var Mustache = function () { } } + function escapeHTML(string) { + return String(string) + .replace(/&(?!\w+;)/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + } + var regexCache = {}; var Renderer = function () {}; @@ -228,8 +237,6 @@ var Mustache = function () { // tit for tat var that = this; - - var new_regex = function () { return that.getCachedRegex("render_tags", function (otag, ctag) { return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g"); @@ -250,7 +257,7 @@ var Mustache = function () { case "{": // the triple mustache is unescaped return that.find(name, context); default: // escape the value - return that.escape(that.find(name, context)); + return escapeHTML(that.find(name, context)); } }; var lines = template.split("\n"); @@ -347,23 +354,6 @@ var Mustache = function () { return haystack.indexOf(this.otag + needle) != -1; }, - /* - Does away with nasty characters - */ - escape: function (s) { - s = String(s === null ? "" : s); - return s.replace(/&(?!\w+;)|["'<>\\]/g, function (s) { - switch(s) { - case "&": return "&"; - case '"': return '"'; - case "'": return '''; - case "<": return "<"; - case ">": return ">"; - default: return s; - } - }); - }, - // by @langalex, support for arrays of strings create_context: function (_context) { if (this.is_object(_context)) { From ceafe886cb187960f467dbe7e7859259a77d5ad4 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Mon, 19 Dec 2011 11:52:49 +0100 Subject: [PATCH 20/64] Travis builders are now on Ubuntu 11.04 "Natty". The xulrunner package name is now "xulrunner-2.0". We need this to run our tests in SpiderMonkey. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d599f87..af073a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ rvm: - 1.9.2 before_script: - - sudo apt-get install xulrunner-1.9 + - sudo apt-get install xulrunner-2.0 - gem install rspec From 99b5aa1a3df92733db8384796a01f8a99eee1408 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Mon, 19 Dec 2011 15:36:25 +0100 Subject: [PATCH 21/64] -y oh -y --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af073a3..b52599e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ rvm: - 1.9.2 before_script: - - sudo apt-get install xulrunner-2.0 + - sudo apt-get -y install xulrunner-2.0 - gem install rspec From db5f5ece0b6c87bbb2d0584010b97f8723dde69d Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 19 Dec 2011 16:39:47 -0800 Subject: [PATCH 22/64] Faster escapeHTML See http://jsperf.com/string-replace-function --- mustache.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mustache.js b/mustache.js index 47def07..cc42f3d 100644 --- a/mustache.js +++ b/mustache.js @@ -35,13 +35,18 @@ var Mustache = function () { } } + var escapeMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''' + }; + function escapeHTML(string) { - return String(string) - .replace(/&(?!\w+;)/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); + return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) { + return escapeMap[s] || s; + }); } var regexCache = {}; From bf95689f4282d0a60162e8e093933c8cd07c73f1 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 28 Dec 2011 12:31:16 -0800 Subject: [PATCH 23/64] Support for partial paths (fixes #91) Uses the work done by @nateware in pull request 92. Thanks! --- mustache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index cc42f3d..1ff6d08 100644 --- a/mustache.js +++ b/mustache.js @@ -244,7 +244,7 @@ var Mustache = function () { var new_regex = function () { return that.getCachedRegex("render_tags", function (otag, ctag) { - return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g"); + return new RegExp(otag + "(=|!|>|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g"); }); }; From 634b29d27528f40bb33748302bc8d7377977270c Mon Sep 17 00:00:00 2001 From: Don Brown Date: Tue, 1 Mar 2011 11:28:41 +1100 Subject: [PATCH 24/64] 83: Add support for & operator for unescaping Conflicts: mustache.js --- mustache.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index 1ff6d08..977c3c1 100644 --- a/mustache.js +++ b/mustache.js @@ -244,7 +244,7 @@ var Mustache = function () { var new_regex = function () { return that.getCachedRegex("render_tags", function (otag, ctag) { - return new RegExp(otag + "(=|!|>|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g"); + return new RegExp(otag + "(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g"); }); }; @@ -260,6 +260,7 @@ var Mustache = function () { case ">": // render partial return that.render_partial(name, context, partials); case "{": // the triple mustache is unescaped + case "&": // & operator is an alternative unescape method return that.find(name, context); default: // escape the value return escapeHTML(that.find(name, context)); From def81a0700cc22fbf03025e38e3ae52cf6d18c21 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 28 Dec 2011 12:43:25 -0800 Subject: [PATCH 25/64] Add spec for & tags (fixes #83) --- spec/_files/ampersand_escape.js | 3 +++ spec/_files/ampersand_escape.mustache | 1 + spec/_files/ampersand_escape.txt | 1 + 3 files changed, 5 insertions(+) create mode 100644 spec/_files/ampersand_escape.js create mode 100644 spec/_files/ampersand_escape.mustache create mode 100644 spec/_files/ampersand_escape.txt diff --git a/spec/_files/ampersand_escape.js b/spec/_files/ampersand_escape.js new file mode 100644 index 0000000..645efe1 --- /dev/null +++ b/spec/_files/ampersand_escape.js @@ -0,0 +1,3 @@ +var ampersand_escape = { + message: "Some " +}; diff --git a/spec/_files/ampersand_escape.mustache b/spec/_files/ampersand_escape.mustache new file mode 100644 index 0000000..6501a48 --- /dev/null +++ b/spec/_files/ampersand_escape.mustache @@ -0,0 +1 @@ +{{&message}} diff --git a/spec/_files/ampersand_escape.txt b/spec/_files/ampersand_escape.txt new file mode 100644 index 0000000..2ed3fd3 --- /dev/null +++ b/spec/_files/ampersand_escape.txt @@ -0,0 +1 @@ +Some From 3f15f72fbf87bbcacf8754cee1fae8fb92eb3cf8 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 4 Jan 2012 20:05:46 +0100 Subject: [PATCH 26/64] 0.4.0 --- mustache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index 977c3c1..91ec828 100644 --- a/mustache.js +++ b/mustache.js @@ -417,7 +417,7 @@ var Mustache = function () { return({ name: "mustache.js", - version: "0.4.0-dev", + version: "0.4.0", /* Turns a template and view into HTML From 5df7be5ae7bea92ef723a8d6c26f45d43400eec8 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 4 Jan 2012 20:07:28 +0100 Subject: [PATCH 27/64] master is now 0.5.0 --- mustache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index 91ec828..da2c410 100644 --- a/mustache.js +++ b/mustache.js @@ -417,7 +417,7 @@ var Mustache = function () { return({ name: "mustache.js", - version: "0.4.0", + version: "0.5.0-dev", /* Turns a template and view into HTML From eb01be04702388fd3cf98e509d3d14f1f9243f09 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 16 Dec 2011 22:42:48 -0800 Subject: [PATCH 28/64] Parser rewrite This commit is a complete rewrite of the core mustache.js file with two main goals: 1) a major performance boost and 2) better compliance with the mustache spec. In order to improve performance templates are pre-compiled to JavaScript functions. These compiled functions take a view, a partials object, and an optional callback as arguments. They are cached to prevent unnecessary re-compilation of an already compiled template. Both of these enhancements facilitate a generous boost in performance. A few other notes: - The mustache.js file is now both browser and CommonJS ready without any modification. - The API exposes two main methods: Mustache.compile and Mustache.render. The former is used to generate a function for a given template, while the latter is a higher-level function that is used to compile and render a template in one shot. Mustache.to_html is still available for backwards compatibility. - The concept of pragmas is removed to conform more closely to the original mustache spec. The dot symbol still works to reference the current item in an array. - The parser is much more strict about whitespace than it was before. The rule is simple: if a line contains only a non-variable tag (i.e. not {{tag}} or {{{tag}}}) and whitespace, that line is ignored in the output. Users may use the "space" option when compiling templates to preserve every whitespace character in the original template. - The parser is able to provide detailed information about where errors occur when parsing and rendering templates, including the line number and surrounding code context. --- .gitignore | 1 - README.md | 10 +- Rakefile | 9 +- TESTING.md | 8 +- mustache.js | 816 ++++++++++-------- package.json | 8 + .../array_of_partials_implicit_partial.js | 3 - spec/_files/array_of_strings.mustache | 2 +- spec/_files/array_of_strings_options.js | 1 - spec/_files/array_of_strings_options.mustache | 2 - spec/_files/array_of_strings_options.txt | 1 - spec/_files/array_partial.js | 5 - spec/_files/complex.mustache | 2 +- spec/_files/complex.txt | 6 +- spec/_files/delimiters.mustache | 2 +- spec/_files/empty_partial.2.mustache | 1 - spec/_files/empty_partial.js | 3 - spec/_files/empty_template.txt | 2 +- spec/_files/error_not_found.txt | 1 - spec/_files/inverted_section.txt | 1 + spec/_files/nesting.txt | 7 +- spec/_files/null_string.js | 1 + spec/_files/null_string.mustache | 3 +- spec/_files/null_string.txt | 1 + spec/_files/partial_array.js | 3 + ...artial.mustache => partial_array.mustache} | 0 ...rtial.2.mustache => partial_array.partial} | 2 +- .../{array_partial.txt => partial_array.txt} | 1 - ...artial.js => partial_array_of_partials.js} | 2 +- ...che => partial_array_of_partials.mustache} | 0 ...ache => partial_array_of_partials.partial} | 0 ...tial.txt => partial_array_of_partials.txt} | 0 .../partial_array_of_partials_implicit.js | 3 + ...rtial_array_of_partials_implicit.mustache} | 0 ...artial_array_of_partials_implicit.partial} | 0 ...=> partial_array_of_partials_implicit.txt} | 0 spec/_files/partial_empty.js | 3 + ...artial.mustache => partial_empty.mustache} | 0 spec/_files/partial_empty.partial | 1 + .../{empty_partial.txt => partial_empty.txt} | 0 spec/_files/partial_recursion.js | 2 +- spec/_files/partial_recursion.mustache | 2 +- ...n.2.mustache => partial_recursion.partial} | 2 +- spec/_files/partial_template.js | 6 + ...ial.mustache => partial_template.mustache} | 2 +- spec/_files/partial_template.partial | 1 + ...plate_partial.txt => partial_template.txt} | 0 spec/_files/partial_view.js | 16 + ...partial.mustache => partial_view.mustache} | 2 +- ...artial.2.mustache => partial_view.partial} | 0 .../{view_partial.txt => partial_view.txt} | 1 - spec/_files/partial_whitespace.js | 17 + ...l.mustache => partial_whitespace.mustache} | 2 +- ....2.mustache => partial_whitespace.partial} | 0 ...ace_partial.txt => partial_whitespace.txt} | 1 - spec/_files/reuse_of_enumerables.js | 2 +- spec/_files/section_as_context.txt | 6 +- spec/_files/simple.mustache | 2 +- spec/_files/template_partial.2.mustache | 1 - spec/_files/template_partial.js | 8 - spec/_files/two_in_a_row.mustache | 2 +- spec/_files/two_sections.txt | 1 - spec/_files/unescaped.mustache | 2 +- spec/_files/unknown_pragma.js | 1 - spec/_files/unknown_pragma.mustache | 1 - spec/_files/unknown_pragma.txt | 1 - spec/_files/view_partial.js | 19 - spec/_files/whitespace_partial.js | 19 - spec/mustache_spec.rb | 138 +-- wrappers/commonjs/mustache.js.tpl.post | 8 - wrappers/commonjs/mustache.js.tpl.pre | 6 - wrappers/commonjs/package.json | 8 - 72 files changed, 596 insertions(+), 594 deletions(-) create mode 100644 package.json delete mode 100644 spec/_files/array_of_partials_implicit_partial.js delete mode 100644 spec/_files/array_of_strings_options.js delete mode 100644 spec/_files/array_of_strings_options.mustache delete mode 100644 spec/_files/array_of_strings_options.txt delete mode 100644 spec/_files/array_partial.js delete mode 100644 spec/_files/empty_partial.2.mustache delete mode 100644 spec/_files/empty_partial.js create mode 100644 spec/_files/partial_array.js rename spec/_files/{array_partial.mustache => partial_array.mustache} (100%) rename spec/_files/{array_partial.2.mustache => partial_array.partial} (83%) rename spec/_files/{array_partial.txt => partial_array.txt} (98%) rename spec/_files/{array_of_partials_partial.js => partial_array_of_partials.js} (61%) rename spec/_files/{array_of_partials_implicit_partial.mustache => partial_array_of_partials.mustache} (100%) rename spec/_files/{array_of_partials_partial.2.mustache => partial_array_of_partials.partial} (100%) rename spec/_files/{array_of_partials_implicit_partial.txt => partial_array_of_partials.txt} (100%) create mode 100644 spec/_files/partial_array_of_partials_implicit.js rename spec/_files/{array_of_partials_partial.mustache => partial_array_of_partials_implicit.mustache} (100%) rename spec/_files/{array_of_partials_implicit_partial.2.mustache => partial_array_of_partials_implicit.partial} (100%) rename spec/_files/{array_of_partials_partial.txt => partial_array_of_partials_implicit.txt} (100%) create mode 100644 spec/_files/partial_empty.js rename spec/_files/{empty_partial.mustache => partial_empty.mustache} (100%) create mode 100644 spec/_files/partial_empty.partial rename spec/_files/{empty_partial.txt => partial_empty.txt} (100%) rename spec/_files/{partial_recursion.2.mustache => partial_recursion.partial} (72%) create mode 100644 spec/_files/partial_template.js rename spec/_files/{template_partial.mustache => partial_template.mustache} (59%) create mode 100644 spec/_files/partial_template.partial rename spec/_files/{template_partial.txt => partial_template.txt} (100%) create mode 100644 spec/_files/partial_view.js rename spec/_files/{view_partial.mustache => partial_view.mustache} (61%) rename spec/_files/{view_partial.2.mustache => partial_view.partial} (100%) rename spec/_files/{view_partial.txt => partial_view.txt} (99%) create mode 100644 spec/_files/partial_whitespace.js rename spec/_files/{whitespace_partial.mustache => partial_whitespace.mustache} (63%) rename spec/_files/{whitespace_partial.2.mustache => partial_whitespace.partial} (100%) rename spec/_files/{whitespace_partial.txt => partial_whitespace.txt} (99%) delete mode 100644 spec/_files/template_partial.2.mustache delete mode 100644 spec/_files/template_partial.js delete mode 100644 spec/_files/unknown_pragma.js delete mode 100644 spec/_files/unknown_pragma.mustache delete mode 100644 spec/_files/unknown_pragma.txt delete mode 100644 spec/_files/view_partial.js delete mode 100644 spec/_files/whitespace_partial.js delete mode 100644 wrappers/commonjs/mustache.js.tpl.post delete mode 100644 wrappers/commonjs/mustache.js.tpl.pre delete mode 100644 wrappers/commonjs/package.json diff --git a/.gitignore b/.gitignore index c44d96c..bd08399 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .DS_Store .rvmrc runner.js -lib jquery.mustache.js qooxdoo.mustache.js dojox diff --git a/README.md b/README.md index 578df7c..7d941df 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ > What could be more logical awesome than no logic at all? [mustache.js](http://github.com/janl/mustache.js) is an implementation of the -[Mustache](http://mustache.github.com/) templating system in JavaScript. +[Mustache](http://mustache.github.com/) template system in JavaScript. [Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding @@ -274,10 +274,11 @@ own iteration marker: ## Plugins for JavaScript Libraries -mustache.js may be built specifically for several different client libraries -and platforms, including the following: +By default mustache.js may be used in a browser or any [CommonJS](http://www.commonjs.org/) +environment, including [node](http://nodejs.org/). Additionally, mustache.js may +be built specifically for several different client libraries and platforms, +including the following: - - [node](http://nodejs.org/) (or other CommonJS platforms) - [jQuery](http://jquery.com/) - [Dojo](http://www.dojotoolkit.org/) - [YUI](http://developer.yahoo.com/yui/) @@ -287,7 +288,6 @@ and platforms, including the following: These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands: - $ rake commonjs $ rake jquery $ rake dojo $ rake yui diff --git a/Rakefile b/Rakefile index 16bc724..b2a83b9 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ task :spec do end def version - File.read("mustache.js").match('version: "([^\"]+)",$')[1] + File.read("mustache.js").match('version = "([^\"]+)";$')[1] end # Creates a rule that uses the .tmpl.{pre,post} stuff to make a final, @@ -36,17 +36,10 @@ def templated_build(name, opts={}) sh "cat #{source}/#{target_js}.tpl.pre mustache.js \ #{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}" - # extra - if opts[:extra] - sh "sed -e 's/{{version}}/#{version}/' #{source}/#{opts[:extra]} \ - > #{opts[:location]}/#{opts[:extra]}" - end - puts "Done, see #{opts[:location] || '.'}/#{target_js}" end end -templated_build "CommonJS", :location => "lib", :extra => "package.json" templated_build "jQuery" templated_build "Dojo", :location => "dojox/string" templated_build "YUI3", :location => "yui3/mustache" diff --git a/TESTING.md b/TESTING.md index 6abec93..47d15e4 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,4 +1,4 @@ -## Running the mustache.js Test Suite +## Running the mustache.js test suite The mustache.js test suite uses the [RSpec](http://rspec.info/) testing framework. In order to run the tests you'll need to install [Ruby](http://ruby-lang.org/) @@ -57,6 +57,6 @@ suite with the following command: All test files live in the spec/_files directory. To create a new test: - * Create a template file `somename.mustache` - * Create a javascript file with data and functions `somename.js` - * Create a file the expected result `somename.txt` + * Create a template file called `somename.mustache` + * Create a JavaScript file containing the view called `somename.js` + * Create a text file with the expected result called `somename.txt` diff --git a/mustache.js b/mustache.js index da2c410..0121abc 100644 --- a/mustache.js +++ b/mustache.js @@ -1,38 +1,75 @@ -/* - mustache.js — Logic-less templates in JavaScript +/*! + * mustache.js - Logic-less {{mustache}} templates with JavaScript + * http://github.com/janl/mustache.js + */ +var Mustache = (typeof module !== "undefined" && module.exports) || {}; - See http://mustache.github.com/ for more info. -*/ +(function (exports) { + + exports.name = "mustache.js"; + exports.version = "0.5.0-dev"; + exports.tags = ["{{", "}}"]; + exports.parse = parse; + exports.compile = compile; + exports.render = render; + exports.clearCache = clearCache; + + exports.to_html = render; // keep backwards compatibility -var Mustache = function () { var _toString = Object.prototype.toString; + var _isArray = Array.isArray; + var _forEach = Array.prototype.forEach; + var _trim = String.prototype.trim; - Array.isArray = Array.isArray || function (obj) { - return _toString.call(obj) == "[object Array]"; + var isArray; + if (_isArray) { + isArray = _isArray; + } else { + isArray = function (obj) { + return _toString.call(obj) === "[object Array]"; + }; + } + + var forEach; + if (_forEach) { + forEach = function (obj, callback, scope) { + return _forEach.call(obj, callback, scope); + }; + } else { + forEach = function (obj, callback, scope) { + for (var i = 0, len = obj.length; i < len; ++i) { + callback.call(scope, obj[i], i, obj); + } + }; } - var _trim = String.prototype.trim, trim; + var spaceRe = /^\s*$/; + function isWhitespace(string) { + return spaceRe.test(string); + } + + var trim; if (_trim) { - trim = function (text) { - return text == null ? "" : _trim.call(text); - } + trim = function (string) { + return string == null ? "" : _trim.call(string); + }; } else { var trimLeft, trimRight; - // IE doesn't match non-breaking spaces with \s. - if ((/\S/).test("\xA0")) { - trimLeft = /^[\s\xA0]+/; - trimRight = /[\s\xA0]+$/; - } else { + if (isWhitespace("\xA0")) { trimLeft = /^\s+/; trimRight = /\s+$/; + } else { + // IE doesn't match non-breaking spaces with \s, thanks jQuery. + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; } - trim = function (text) { - return text == null ? "" : - text.toString().replace(trimLeft, "").replace(trimRight, ""); - } + trim = function (string) { + return string == null ? "" : + String(string).replace(trimLeft, "").replace(trimRight, ""); + }; } var escapeMap = { @@ -49,388 +86,451 @@ var Mustache = function () { }); } - var regexCache = {}; - var Renderer = function () {}; - - Renderer.prototype = { - otag: "{{", - ctag: "}}", - pragmas: {}, - buffer: [], - pragmas_implemented: { - "IMPLICIT-ITERATOR": true - }, - context: {}, - - render: function (template, context, partials, in_recursion) { - // reset buffer & set context - if (!in_recursion) { - this.context = context; - this.buffer = []; // TODO: make this non-lazy - } + /** + * Adds the `template`, `line`, and `file` properties to the given error + * object and alters the message to provide more useful debugging information. + */ + function debug(e, template, line, file) { + file = file || "