diff --git a/.gitignore b/.gitignore index 252c5ae..a7ed15c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ runner.js jquery.mustache.js dojox yui3 +commonjs.mustache.js diff --git a/Rakefile b/Rakefile index 3298479..2941527 100644 --- a/Rakefile +++ b/Rakefile @@ -11,44 +11,30 @@ end desc "Run all specs" task :spec -desc "Package for CommonJS" -task :commonjs do - puts "Packaging for CommonJS" - `mkdir lib` - `cp mustache.js lib/mustache.js` - puts "Done." +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.*") + + desc "Package for #{name}" + task short.to_sym => dependencies do + target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js" + + puts "Packaging for #{name}" + sh "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}" + puts "Done, see #{opts[:location] || '.'}/#{target_js}" + end end -desc "Package for jQuery" -task :jquery do - puts "Packaging for jQuery" - source = "mustache-jquery" - target_jq = "jquery.mustache.js" - `cat #{source}/#{target_jq}.tpl.pre mustache.js #{source}/#{target_jq}.tpl.post > #{target_jq}` - puts "Done, see ./#{target_jq}" -end - -desc "Package for dojo" -task :dojo do - puts "Packaging for dojo" - source = "mustache-dojo" - target_js = "mustache.js" - `mkdir -p dojox; mkdir -p dojox/string` - `cat #{source}/#{target_js}.tpl.pre mustache.js #{source}/#{target_js}.tpl.post > dojox/string/#{target_js}` - puts "Done, see ./dojox/string/#{target_js} Include using dojo.require('dojox.string.mustache.'); " -end - -desc "Package for YUI3" -task :yui3 do - puts "Packaging for YUI3" - source = "mustache-yui3" - target_js = "mustache.js" - `mkdir -p yui3; mkdir -p yui3/mustache` - `cat #{source}/#{target_js}.tpl.pre mustache.js #{source}/#{target_js}.tpl.post > yui3/mustache/#{target_js}` - puts "Done, see ./yui3/mustache/#{target_js}" -end +templated_build "CommonJS" +templated_build "jQuery" +templated_build "Dojo", :location => "dojox/string" +templated_build "YUI3", :location => "yui3/mustache" desc "Remove temporary files." task :clean do - `git clean -fdx` + sh "git clean -fdx" end diff --git a/mustache-commonjs/commonjs.mustache.js.tpl.post b/mustache-commonjs/commonjs.mustache.js.tpl.post new file mode 100644 index 0000000..885803f --- /dev/null +++ b/mustache-commonjs/commonjs.mustache.js.tpl.post @@ -0,0 +1,7 @@ + +exports.name = Mustache.name; +exports.version = Mustache.version; + +exports.to_html = function() { + return Mustache.to_html.apply(this, arguments); +}; diff --git a/mustache-commonjs/commonjs.mustache.js.tpl.pre b/mustache-commonjs/commonjs.mustache.js.tpl.pre new file mode 100644 index 0000000..5e33b34 --- /dev/null +++ b/mustache-commonjs/commonjs.mustache.js.tpl.pre @@ -0,0 +1,6 @@ +/* + * CommonJS-compatible mustache.js module + * + * See http://github.com/janl/mustache.js for more info. + */ +