From aac5e75e4b1342ad0cb346feac8ab8db4600f650 Mon Sep 17 00:00:00 2001 From: Sahab Yazdani Date: Wed, 9 Nov 2011 11:31:15 -0500 Subject: [PATCH] Replace Rakefile with Jakefile and add compression using UglifyJS --- .gitignore | 7 +- CHANGES.md | 2 +- Jakefile | 110 ++++++++++++++++++ Rakefile | 58 --------- THANKS.md | 7 ++ lib/package.json | 8 -- mustache-commonjs/package.json | 8 +- .../mustache.js.tpl.post | 0 .../mustache.js.tpl.pre | 0 ...tache.js.tpl.post => mustache.js.tpl.post} | 0 ...ustache.js.tpl.pre => mustache.js.tpl.pre} | 0 ...tache.js.tpl.post => mustache.js.tpl.post} | 0 ...ustache.js.tpl.pre => mustache.js.tpl.pre} | 0 mustache.min.js | 1 + 14 files changed, 127 insertions(+), 74 deletions(-) create mode 100644 Jakefile delete mode 100644 Rakefile delete mode 100644 lib/package.json rename {mustache-dojo => mustache-dojox}/mustache.js.tpl.post (100%) rename {mustache-dojo => mustache-dojox}/mustache.js.tpl.pre (100%) rename mustache-jquery/{jquery.mustache.js.tpl.post => mustache.js.tpl.post} (100%) rename mustache-jquery/{jquery.mustache.js.tpl.pre => mustache.js.tpl.pre} (100%) rename mustache-requirejs/{requirejs.mustache.js.tpl.post => mustache.js.tpl.post} (100%) rename mustache-requirejs/{requirejs.mustache.js.tpl.pre => mustache.js.tpl.pre} (100%) create mode 100644 mustache.min.js diff --git a/.gitignore b/.gitignore index a7ed15c..e53b207 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -runner.js -jquery.mustache.js -dojox -yui3 -commonjs.mustache.js +packages/** +support/** diff --git a/CHANGES.md b/CHANGES.md index b405cd3..23f7cea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # mustache.js Changes -## 0.5.1-vsc +## 0.5.1-vcs * Added Dot Notation Support diff --git a/Jakefile b/Jakefile new file mode 100644 index 0000000..42dd79a --- /dev/null +++ b/Jakefile @@ -0,0 +1,110 @@ +var fs = require('fs'), + sys = require('sys'), + util = require('util'), + uglify = require('uglify-js'); + +function copyFile(src, dst, cb) { + function copy(err) { + var is, os; + + if (!err) { + return cb(new Error("File " + dst + " exists.")); + } + + fs.stat(src, function (err) { + if (err) { + return cb(err); + } + + is = fs.createReadStream(src); + os = fs.createWriteStream(dst); + util.pump(is, os, cb); + }); + } + + fs.stat(dst, copy); +} + +function makeDirectoryIfNotExists(path) { + try { + var stats = fs.statSync(path); + if (!stats.isDirectory()) { + fs.mkdirSync(path, 0); + } + } catch (e) { + fs.mkdirSync(path, 0); + } +} + +desc('Obfuscation and Compression'); +task('minify', function() { + var all = fs.readFileSync('mustache.js').toString(), + out = fs.openSync('mustache.min.js', 'w+'), + ast = uglify.parser.parse(all); + + ast = uglify.uglify.ast_mangle(ast); + ast = uglify.uglify.ast_squeeze(ast); + + fs.writeSync(out, uglify.uglify.gen_code(ast)); +}); + +task('package', function() { + function package(id, location) { + var files = [ + , 'mustache.js' + ]; + + files.unshift('mustache-' + id + '/mustache.js.tpl.pre'); + files.push('mustache-' + id + '/mustache.js.tpl.post'); + + var all = ''; + files.forEach(function(file, i) { + all += fs.readFileSync(file).toString(); + all += '\n'; + }); + + var outPath; + if (location) { + makeDirectoryIfNotExists('packages/' + id); + + if (location === true) { + outPath = 'packages/' + id + '/mustache.js'; + } else { + outPath = 'packages/' + id + '/' + location + '/mustache.js'; + + makeDirectoryIfNotExists('packages/' + id + '/' + location); + } + } else { + outPath = 'packages/' + id + '.mustache.js'; + } + var out = fs.openSync(outPath, 'w+'); + fs.writeSync(out, all); + } + + var params = Array.prototype.slice.call(arguments); + + makeDirectoryIfNotExists('packages'); + + for (var i = 0, n = params.length; i :spec - -Spec::Rake::SpecTask.new(:spec) do |t| - #t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] - t.spec_files = FileList['test/*_spec.rb'] -end - -desc "Run all specs" -task :spec - -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}" - - # 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" -templated_build "requirejs" - - -def version - File.read("mustache.js").match('version: "([^\"]+)",$')[1] -end - - -desc "Remove temporary files." -task :clean do - sh "git clean -fdx" -end diff --git a/THANKS.md b/THANKS.md index 6dac939..674591b 100644 --- a/THANKS.md +++ b/THANKS.md @@ -2,6 +2,8 @@ Mustache.js wouldn't kick ass if it weren't for these fine souls: +## janl (mainline) Branch: + * Chris Wanstrath / defunkt * Alexander Lang / langalex * Sebastian Cohnen / tisba @@ -18,3 +20,8 @@ Mustache.js wouldn't kick ass if it weren't for these fine souls: * Jason Smith / jhs * Aaron Gibralter / agibralter * Ross Boucher / boucher + +## doodad Branch: + + * Gregory Jacobs / gjslick + \ No newline at end of file diff --git a/lib/package.json b/lib/package.json deleted file mode 100644 index 6325b4e..0000000 --- a/lib/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "mustache", - "author": "http://mustache.github.com/", - "description": "{{ mustache }} in JavaScript — Logic-less templates.", - "keywords": ["template"], - "version": "0.3.1-dev", - "main": "./mustache" -} diff --git a/mustache-commonjs/package.json b/mustache-commonjs/package.json index 74d3aba..e712068 100644 --- a/mustache-commonjs/package.json +++ b/mustache-commonjs/package.json @@ -1,7 +1,11 @@ { "name": "mustache", - "author": "http://mustache.github.com/", + "author": "Vastardis Capital Services", + "contributors": [ + "Mustache " + ], "description": "{{ mustache }} in JavaScript — Logic-less templates.", "keywords": ["template"], - "version": "{{version}}" + "version": "0.5.1-vsc", + "main": "./mustache" } diff --git a/mustache-dojo/mustache.js.tpl.post b/mustache-dojox/mustache.js.tpl.post similarity index 100% rename from mustache-dojo/mustache.js.tpl.post rename to mustache-dojox/mustache.js.tpl.post diff --git a/mustache-dojo/mustache.js.tpl.pre b/mustache-dojox/mustache.js.tpl.pre similarity index 100% rename from mustache-dojo/mustache.js.tpl.pre rename to mustache-dojox/mustache.js.tpl.pre diff --git a/mustache-jquery/jquery.mustache.js.tpl.post b/mustache-jquery/mustache.js.tpl.post similarity index 100% rename from mustache-jquery/jquery.mustache.js.tpl.post rename to mustache-jquery/mustache.js.tpl.post diff --git a/mustache-jquery/jquery.mustache.js.tpl.pre b/mustache-jquery/mustache.js.tpl.pre similarity index 100% rename from mustache-jquery/jquery.mustache.js.tpl.pre rename to mustache-jquery/mustache.js.tpl.pre diff --git a/mustache-requirejs/requirejs.mustache.js.tpl.post b/mustache-requirejs/mustache.js.tpl.post similarity index 100% rename from mustache-requirejs/requirejs.mustache.js.tpl.post rename to mustache-requirejs/mustache.js.tpl.post diff --git a/mustache-requirejs/requirejs.mustache.js.tpl.pre b/mustache-requirejs/mustache.js.tpl.pre similarity index 100% rename from mustache-requirejs/requirejs.mustache.js.tpl.pre rename to mustache-requirejs/mustache.js.tpl.pre diff --git a/mustache.min.js b/mustache.min.js new file mode 100644 index 0000000..9e77fcc --- /dev/null +++ b/mustache.min.js @@ -0,0 +1 @@ +var Mustache=function(a){function c(){}function e(a){if(!d){var b=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];d=new RegExp("(\\"+b.join("|\\")+")","g")}return a.replace(d,"\\$1")}function f(a){return a.match(/\r?\n/)}function g(a){return a&&typeof a=="function"}function h(a){return a&&typeof a=="object"}function i(a){return Object.prototype.toString.call(a)==="[object Array]"}function k(b,d){var e,g,h;for(e=b.tokens.length;b.cursor]?\\s*[^!{=]\\S*?\\s*"+i+")","("+h+"{\\s*\\S*?\\s*}"+i+")","("+h+"=\\S*?\\s*\\S*?="+i+")"];g=new RegExp(j.join("|"))}var k=[],m={metrics:{partial:null,line:1,character:1},template:a||"",partials:c||{},openTag:d,closeTag:f,parser:w,pragmas:{},code:k,send_code_func:function(a){k.push(a)}};return o(m),m.tokens=b.call(m.template,g),m.cursor=0,m}function o(b){function c(a,b){return b.indexOf("{{"+a)!==-1}if(!c("%",b.template))return b.template;b.template=b.template.replace(/{{%([\w-]+)(\s*)(.*?(?=}}))}}/g,function(c,d,e,f){var h=a,i,k,l,m;if(f.length>0){i=f.split(","),h={};for(l=0,m=i.length;l1){d=p(b,c[0]);if(d!==a)return d}return a}function r(b,c){var d=b.split("."),e=1,f=d.length,g=q(d[0],c);while(g&&e/g,">")}var f,g,h;d==="{"?f=g=h=!0:d==="&"&&(f=g=!0);var i=y(b,c,g,h),j=(b.pragmas["IMPLICIT-ITERATOR"]||{iterator:"."}).iterator;b.send_code_func(function(b,c){return function(d,f){var g;b===j?(g={},g[j]=d[d.length-1],g=p(b,g)):g=r(b,d),g!==a&&(c||(g=e(""+g)),f(""+g))}}(i,f))}function u(a,b){var d=y(a,b,!0),e,f;if(!a.partials[d])throw new j('Unknown partial "'+d+'".',a.metrics);if(!g(a.partials[d])){e=a.partials[d],a.partials[d]=c;var h=m(e,a.partials);h.metrics.partial=d,f=k(h),a.partials[d]=function(a,b){var c=q(d,a);c&&a.push(c),f(a,b),c&&a.pop()}}a.send_code_func(function(b,c){a.partials[d](b,c)})}function v(a){var b=a.section,c=b.template_buffer.join(""),d,e=m(c,a.partials,a.openTag,a.closeTag);e.metrics=b.metrics,e.pragmas=a.pragmas,d=k(e),b.inverted?a.send_code_func(function(a,b){return function(c,d){var e=r(b,c);(!e||i(e)&&e.length===0)&&a(c,d)}}(d,b.variable)):a.send_code_func(function(a,b,c,d){return function(e,f){var j=r(b,e);if(i(j))for(var l=0,n=j.length;l0){var d=a.section.child_sections[a.section.child_sections.length-1];if(d===c)a.section.child_sections.pop(),a.section.template_buffer.push(b);else throw new j('Unexpected section end tag "'+c+'", expected "'+d+'".',a.metrics)}else if(a.section.variable===c)v(a),delete a.section,a.parser=w;else throw new j('Unexpected section end tag "'+c+'", expected "'+a.section.variable+'".',a.metrics)}var b=function(){function c(c){var d=this,e=a;if(Object.prototype.toString.call(c)!=="[object RegExp]")return String.prototype.split.call(d,c,e);var f=[],g=0,h=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.sticky?"y":""),c=RegExp(c.source,h+"g"),i,j,k,l;d+="",b||(i=RegExp("^"+c.source+"$(?!\\s)",h));if(e===a||+e<0)e=Infinity;else{e=Math.floor(+e);if(!e)return[]}while(j=c.exec(d)){k=j.index+j[0].length;if(k>g){f.push(d.slice(g,j.index)),!b&&j.length>1&&j[0].replace(i,function(){for(var b=1;b1&&j.index=e)break}c.lastIndex===j.index&&c.lastIndex++}return g===d.length?(l||!c.test(""))&&f.push(""):f.push(d.slice(g)),f.length>e?f.slice(0,e):f}var b=/()??/.exec("")[1]===a;return"lol".split(/(o)/).length!==3?c:String.prototype.split}(),d,j=function(a,b){var c="";this.prototype=Error.prototype,this.name="MustacheError",b&&(c="("+b.line+","+b.character+"): ",b.partial&&(c="["+b.partial+"]"+c)),this.message=c+a,b&&(this.line=b.line,this.character=b.character,this.partial=b.partial)},l=/(\r?\n)|({{![\s\S]*?!}})|({{[#\^\/&>]?\s*[^!{=]\S*?\s*}})|({{{\s*\S*?\s*}}})|({{=\S*?\s*\S*?=}})/,n={"IMPLICIT-ITERATOR":function(b,c){b.pragmas["IMPLICIT-ITERATOR"]={iterator:(c||{iterator:a}).iterator||"."}}},w={"!":c,"#":A,"^":A,"/":function(a,b){throw new j('Unbalanced End Section tag "'+b+'".',a.metrics)},"&":t,"{":t,">":u,"=":z,def:t,text:s},x={"!":c,"#":A,"^":A,"/":C,"&":B,"{":B,">":B,"=":z,def:B,text:B};return{name:"mustache.js",version:"0.5.1-vcs",to_html:function(a,b,c,d){var e=Mustache.compile(a,c),f=e(b,d);if(!d)return f},compile:function(a,b){var c={};if(b)for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);var e=k(m(a,c));return function(a,b){var c=[],d=b||function(a){c.push(a)};e([a||{}],d);if(!b)return c.join("")}},Error:j}}() \ No newline at end of file