diff --git a/ICanHaz.js b/ICanHaz.js index af1bc22..7312374 100644 --- a/ICanHaz.js +++ b/ICanHaz.js @@ -1,18 +1,12 @@ /*! ICanHaz.js version 0.7 -- by @HenrikJoreteg -Licensed under the "You should follow @HenrikJoreteg on Twitter to use this" license. (Because, apparently I'm a twitter whore like that) - -Documentation at: http://github.com/HenrikJoreteg/ICanHaz.js - -Dependencies: -- jQuery - -ICanHaz comes bundled with mustache.js (MIT licensed) for convenience. Big ups to @defunkt for mustache and @janl for the js port. -https://github.com/janl/mustache.js/blob/master/LICENSE +More info at: http://github.com/HenrikJoreteg/ICanHaz.js */ (function ($) { /*! - mustache.js — Logic-less templates in JavaScript + mustache.js -- Logic-less templates in JavaScript + + by @janl (MIT Licensed, https://github.com/janl/mustache.js/blob/master/LICENSE). See http://mustache.github.com/ for more info. */ @@ -98,7 +92,7 @@ var Mustache = function() { */ render_partial: function(name, context, partials) { name = this.trim(name); - if(!partials || !partials[name]) { + if(!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } if(typeof(context[name]) != "object") { @@ -118,7 +112,7 @@ var Mustache = function() { var that = this; // CSW - Added "+?" so it finds the tighest bound, not the widest var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag + - "\\s*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag + + "\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag + "\\s*", "mg"); // for each {{#foo}}{{/foo}} section do... @@ -273,8 +267,11 @@ var Mustache = function() { create_context: function(_context) { if(this.is_object(_context)) { return _context; - } else if(this.pragmas["IMPLICIT-ITERATOR"]) { - var iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator || "."; + } else { + var iterator = "."; + if(this.pragmas["IMPLICIT-ITERATOR"]) { + iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; + } var ctx = {}; ctx[iterator] = _context; return ctx; @@ -315,7 +312,7 @@ var Mustache = function() { return({ name: "mustache.js", - version: "0.3.0-dev", + version: "0.3.0", /* Turns a template and view into HTML @@ -332,7 +329,7 @@ var Mustache = function() { } }); }();/*! - ICanHaz.js version 0.7 -- by @HenrikJoreteg + ICanHaz.js -- by @HenrikJoreteg */ /*global jQuery */ function ICanHaz() { diff --git a/ICanHaz.min.js b/ICanHaz.min.js index 24cdc9a..cde74f1 100644 --- a/ICanHaz.min.js +++ b/ICanHaz.min.js @@ -1,23 +1,17 @@ /* ICanHaz.js version 0.7 -- by @HenrikJoreteg -Licensed under the "You should follow @HenrikJoreteg on Twitter to use this" license. (Because, apparently I'm a twitter whore like that) - -Documentation at: http://github.com/HenrikJoreteg/ICanHaz.js - -Dependencies: -- jQuery - -ICanHaz comes bundled with mustache.js (MIT licensed) for convenience. Big ups to @defunkt for mustache and @janl for the js port. -https://github.com/janl/mustache.js/blob/master/LICENSE +More info at: http://github.com/HenrikJoreteg/ICanHaz.js */ (function(c){ /* - mustache.js — Logic-less templates in JavaScript + mustache.js -- Logic-less templates in JavaScript + + by @janl (MIT Licensed, https://github.com/janl/mustache.js/blob/master/LICENSE). See http://mustache.github.com/ for more info. */ -var b=function(){var d=function(){};d.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":true},context:{},render:function(h,g,f,i){if(!i){this.context=g;this.buffer=[]}if(!this.includes("",h)){if(i){return h}else{this.send(h);return}}h=this.render_pragmas(h);var e=this.render_section(h,g,f);if(i){return this.render_tags(e,g,f,i)}this.render_tags(e,g,f,i)},send:function(e){if(e!=""){this.buffer.push(e)}},render_pragmas:function(e){if(!this.includes("%",e)){return e}var g=this;var f=new RegExp(this.otag+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+this.ctag);return e.replace(f,function(j,h,i){if(!g.pragmas_implemented[h]){throw ({message:"This implementation of mustache doesn't understand the '"+h+"' pragma"})}g.pragmas[h]={};if(i){var k=i.split("=");g.pragmas[h][k[0]]=k[1]}return""})},render_partial:function(e,g,f){e=this.trim(e);if(!f||!f[e]){throw ({message:"unknown_partial '"+e+"'"})}if(typeof(g[e])!="object"){return this.render(f[e],g,f,true)}return this.render(f[e],g[e],f,true)},render_section:function(g,f,e){if(!this.includes("#",g)&&!this.includes("^",g)){return g}var i=this;var h=new RegExp(this.otag+"(\\^|\\#)\\s*(.+)\\s*"+this.ctag+"\\s*([\\s\\S]+?)"+this.otag+"\\/\\s*\\2\\s*"+this.ctag+"\\s*","mg");return g.replace(h,function(k,l,j,m){var n=i.find(j,f);if(l=="^"){if(!n||i.is_array(n)&&n.length===0){return i.render(m,f,e,true)}else{return""}}else{if(l=="#"){if(i.is_array(n)){return i.map(n,function(o){return i.render(m,i.create_context(o),e,true)}).join("")}else{if(i.is_object(n)){return i.render(m,i.create_context(n),e,true)}else{if(typeof n==="function"){return n.call(f,m,function(o){return i.render(o,f,e,true)})}else{if(n){return i.render(m,f,e,true)}else{return""}}}}}}})},render_tags:function(n,e,g,j){var h=this;var m=function(){return new RegExp(h.otag+"(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?"+h.ctag+"+","g")};var k=m();var l=function(q,i,p){switch(i){case"!":return"";case"=":h.set_delimiters(p);k=m();return"";case">":return h.render_partial(p,e,g);case"{":return h.find(p,e);default:return h.escape(h.find(p,e))}};var o=n.split("\n");for(var f=0;f\\]/g,function(f){switch(f){case"&":return"&";case"\\":return"\\\\";case'"':return'"';case"<":return"<";case">":return">";default:return f}})},create_context:function(f){if(this.is_object(f)){return f}else{if(this.pragmas["IMPLICIT-ITERATOR"]){var g=this.pragmas["IMPLICIT-ITERATOR"].iterator||".";var e={};e[g]=f;return e}}},is_object:function(e){return e&&typeof e=="object"},is_array:function(e){return Object.prototype.toString.call(e)==="[object Array]"},trim:function(e){return e.replace(/^\s*|\s*$/g,"")},map:function(j,g){if(typeof j.map=="function"){return j.map(g)}else{var h=[];var e=j.length;for(var f=0;f|\\{|%)?([^\\/#\\^]+?)\\1?"+h.ctag+"+","g")};var k=m();var l=function(q,i,p){switch(i){case"!":return"";case"=":h.set_delimiters(p);k=m();return"";case">":return h.render_partial(p,e,g);case"{":return h.find(p,e);default:return h.escape(h.find(p,e))}};var o=n.split("\n");for(var f=0;f\\]/g,function(f){switch(f){case"&":return"&";case"\\":return"\\\\";case'"':return'"';case"<":return"<";case">":return">";default:return f}})},create_context:function(f){if(this.is_object(f)){return f}else{var g=".";if(this.pragmas["IMPLICIT-ITERATOR"]){g=this.pragmas["IMPLICIT-ITERATOR"].iterator}var e={};e[g]=f;return e}},is_object:function(e){return e&&typeof e=="object"},is_array:function(e){return Object.prototype.toString.call(e)==="[object Array]"},trim:function(e){return e.replace(/^\s*|\s*$/g,"")},map:function(j,g){if(typeof j.map=="function"){return j.map(g)}else{var h=[];var e=j.length;for(var f=0;f` along with jQuery and you're off *haz*'ing stuffs. Luckily Mustache and Mustache.js are generously MIT licensed. Mr. Github founder himself Chris Wanstrath ([@defunkt](http://twitter.com/defunkt)) created mustache. Read the [mustache documentation](http://mustache.github.com) for more info. +For simplicity and ease of use, ICanHaz includes [janl's Mustache.js v0.3.0](https://github.com/janl/mustache.js/tree/0.3.0), inside a closure) that way you can just include `` along with jQuery and you're off *haz*'ing stuffs. Luckily Mustache and Mustache.js are generously MIT licensed. Mr. Github founder himself Chris Wanstrath ([@defunkt](http://twitter.com/defunkt)) created mustache. Read the [mustache documentation](http://mustache.github.com) for more info. Then it was ported to JS by [Jan Lehnardt](https://github.com/janl). ##Why would we need this? Because building html elements using javascript or jQuery is ugly: diff --git a/source/intro.js b/source/intro.js index d71965f..ef04664 100644 --- a/source/intro.js +++ b/source/intro.js @@ -1,12 +1,4 @@ /*! -ICanHaz.js version 0.7 -- by @HenrikJoreteg -Licensed under the "You should follow @HenrikJoreteg on Twitter to use this" license. (Because, apparently I'm a twitter whore like that) - -Documentation at: http://github.com/HenrikJoreteg/ICanHaz.js - -Dependencies: -- jQuery - -ICanHaz comes bundled with mustache.js (MIT licensed) for convenience. Big ups to @defunkt for mustache and @janl for the js port. -https://github.com/janl/mustache.js/blob/master/LICENSE +ICanHaz.js version @VERSION@ -- by @HenrikJoreteg +More info at: http://github.com/HenrikJoreteg/ICanHaz.js */ \ No newline at end of file diff --git a/source/main.js b/source/main.js index 7900e3f..7eed6c7 100644 --- a/source/main.js +++ b/source/main.js @@ -1,5 +1,5 @@ /*! - ICanHaz.js version @VERSION@ -- by @HenrikJoreteg + ICanHaz.js -- by @HenrikJoreteg */ /*global jQuery */ function ICanHaz() { diff --git a/source/mustache.js b/source/mustache.js index c5299b2..02e3934 100644 --- a/source/mustache.js +++ b/source/mustache.js @@ -1,5 +1,7 @@ /*! - mustache.js — Logic-less templates in JavaScript + mustache.js -- Logic-less templates in JavaScript + + by @janl (MIT Licensed, https://github.com/janl/mustache.js/blob/master/LICENSE). See http://mustache.github.com/ for more info. */ @@ -85,7 +87,7 @@ var Mustache = function() { */ render_partial: function(name, context, partials) { name = this.trim(name); - if(!partials || !partials[name]) { + if(!partials || partials[name] === undefined) { throw({message: "unknown_partial '" + name + "'"}); } if(typeof(context[name]) != "object") { @@ -105,7 +107,7 @@ var Mustache = function() { var that = this; // CSW - Added "+?" so it finds the tighest bound, not the widest var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag + - "\\s*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag + + "\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag + "\\s*", "mg"); // for each {{#foo}}{{/foo}} section do... @@ -260,8 +262,11 @@ var Mustache = function() { create_context: function(_context) { if(this.is_object(_context)) { return _context; - } else if(this.pragmas["IMPLICIT-ITERATOR"]) { - var iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator || "."; + } else { + var iterator = "."; + if(this.pragmas["IMPLICIT-ITERATOR"]) { + iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; + } var ctx = {}; ctx[iterator] = _context; return ctx; @@ -302,7 +307,7 @@ var Mustache = function() { return({ name: "mustache.js", - version: "0.3.0-dev", + version: "0.3.0", /* Turns a template and view into HTML