From 1edff659601745fc438296ebf928a0dd20bdfa1e Mon Sep 17 00:00:00 2001 From: tlrobinson Date: Fri, 16 Oct 2009 12:58:42 -0700 Subject: [PATCH 1/3] Added missing "var"s --- mustache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mustache.js b/mustache.js index 333a032..0f5da76 100644 --- a/mustache.js +++ b/mustache.js @@ -29,7 +29,7 @@ var Mustache = { } // keep context around for recursive calls - this.context = context = this.merge((this.context || {}), view); + var context = this.context = this.merge((this.context || {}), view); // first, render all sections var html = this.render_section(template); @@ -105,7 +105,7 @@ var Mustache = { // tit for tat var that = this; - regex = new_regex(); + var regex = new_regex(); var lines = template; // for each {{(!<{)?foo}} tag, do... From 96004e3d71943b6db411de1564f92651730a63c6 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sun, 18 Oct 2009 18:33:56 +0200 Subject: [PATCH 2/3] add commonjs package generation, run `rake commonjs `, somebody please port this to ruby :) --- .gitignore | 29 +++++++++++++++++++++++++++++ Rakefile | 23 ++++++++++++++++++----- mustache-commonjs/package.json | 6 ++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 mustache-commonjs/package.json diff --git a/.gitignore b/.gitignore index 1a6d8fe..1886df5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,30 @@ runner.js +mustache-commonjs/LICENSE +mustache-commonjs/README.md +mustache-commonjs/examples/comments.html +mustache-commonjs/examples/comments.js +mustache-commonjs/examples/comments.txt +mustache-commonjs/examples/complex.html +mustache-commonjs/examples/complex.js +mustache-commonjs/examples/complex.txt +mustache-commonjs/examples/delimiters.html +mustache-commonjs/examples/delimiters.js +mustache-commonjs/examples/delimiters.txt +mustache-commonjs/examples/escaped.html +mustache-commonjs/examples/escaped.js +mustache-commonjs/examples/escaped.txt +mustache-commonjs/examples/simple.html +mustache-commonjs/examples/simple.js +mustache-commonjs/examples/simple.txt +mustache-commonjs/examples/template_partial.html +mustache-commonjs/examples/template_partial.js +mustache-commonjs/examples/template_partial.txt +mustache-commonjs/examples/unescaped.html +mustache-commonjs/examples/unescaped.js +mustache-commonjs/examples/unescaped.txt +mustache-commonjs/examples/view_partial.html +mustache-commonjs/examples/view_partial.js +mustache-commonjs/examples/view_partial.txt +mustache-commonjs/lib/mustache.js +mustache-commonjs/test/mustache_test.js +mustache-commonjs/test/mustache_test.rb diff --git a/Rakefile b/Rakefile index eee70c8..ab2bab9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,24 @@ +require 'rake' require 'rake/testtask' task :default => :test -Rake::TestTask.new do |t| - Dir.glob("examples/*.html") do |file| - test = File.basename(file, ".html") - cmd = "ruby test/mustache_test.rb #{test}" - print `#{cmd}` +task :test do + Rake::TestTask.new do |t| + Dir.glob("examples/*.html") do |file| + test = File.basename(file, ".html") + cmd = "ruby test/mustache_test.rb #{test}" + print `#{cmd}` + end end end + +task :commonjs do + print "Packaging for CommonJS\n" + target = "mustache-commonjs" + files = "LICENSE README.md test examples" + `cp -r #{files} #{target}` + `mkdir #{target}/lib` + `cp mustache.js #{target}/lib` + print "Done, see ./#{target}\n" +end diff --git a/mustache-commonjs/package.json b/mustache-commonjs/package.json new file mode 100644 index 0000000..8ba2db4 --- /dev/null +++ b/mustache-commonjs/package.json @@ -0,0 +1,6 @@ +{ + "name": "mustache", + "author": "Jan Lehnardt", + "description": "{{mustaches}} in JavaScript — shameless port from @defunkt", + "keywords": ["template"] +} From dadf072d405fb44782afd016488e0d9db04c6e66 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sun, 18 Oct 2009 19:04:24 +0200 Subject: [PATCH 3/3] add jquery package generation, run `rake jquery`, somebody please port this to ruby :) --- .gitignore | 5 +++++ Rakefile | 18 ++++++++++++++++-- mustache-jquery/jquery.mustache.js.tpl.post | 6 ++++++ mustache-jquery/jquery.mustache.js.tpl.pre | 9 +++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 mustache-jquery/jquery.mustache.js.tpl.post create mode 100644 mustache-jquery/jquery.mustache.js.tpl.pre diff --git a/.gitignore b/.gitignore index 1886df5..34478aa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,8 @@ mustache-commonjs/examples/view_partial.txt mustache-commonjs/lib/mustache.js mustache-commonjs/test/mustache_test.js mustache-commonjs/test/mustache_test.rb +mustache-jquery/jquery.mustache.js +mustache-jquery/LICENSE +mustache-jquery/README.md +mustache-jquery/examples/ +mustache-jquery/test/ diff --git a/Rakefile b/Rakefile index ab2bab9..24bd6c1 100644 --- a/Rakefile +++ b/Rakefile @@ -16,9 +16,23 @@ end task :commonjs do print "Packaging for CommonJS\n" target = "mustache-commonjs" - files = "LICENSE README.md test examples" - `cp -r #{files} #{target}` + copy_distfiles(target); `mkdir #{target}/lib` `cp mustache.js #{target}/lib` print "Done, see ./#{target}\n" end + +task :jquery do + print "Packaging for jQuery\n" + target = "mustache-jquery/" + target_jq = "#{target}/jquery.mustache.js" + `cat #{target_jq}.tpl.pre mustache.js #{target_jq}.tpl.post > #{target_jq}` + copy_distfiles(target); + print "Done, see ./#{target}\n" +end + +private +def copy_distfiles(target) + files = "LICENSE README.md test examples" + `cp -r #{files} #{target}` +end diff --git a/mustache-jquery/jquery.mustache.js.tpl.post b/mustache-jquery/jquery.mustache.js.tpl.post new file mode 100644 index 0000000..bcc9907 --- /dev/null +++ b/mustache-jquery/jquery.mustache.js.tpl.post @@ -0,0 +1,6 @@ + + $.mustache = function(template, view) { + return Mustache.to_html(template, view); + }; + +})(jQuery); diff --git a/mustache-jquery/jquery.mustache.js.tpl.pre b/mustache-jquery/jquery.mustache.js.tpl.pre new file mode 100644 index 0000000..b4d8af5 --- /dev/null +++ b/mustache-jquery/jquery.mustache.js.tpl.pre @@ -0,0 +1,9 @@ +/* +Shameless port of a shameless port +@defunkt => @janl => @aq + +See http://github.com/defunkt/mustache for more info. +*/ + +;(function($) { +