From eb3cc86a043da45a01740d7da77c2998264c250b Mon Sep 17 00:00:00 2001 From: Kabir Shah Date: Sat, 18 Mar 2017 15:36:19 -0700 Subject: [PATCH] allow $ and @ signs in templates --- dist/moon.js | 2 +- dist/moon.min.js | 2 +- src/util/util.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/moon.js b/dist/moon.js index 8892f094..e17db775 100644 --- a/dist/moon.js +++ b/dist/moon.js @@ -188,7 +188,7 @@ * @return {String} compiled template */ var compileTemplate = function (template, isString) { - var TEMPLATE_RE = /{{([A-Za-z0-9_]+)([A-Za-z0-9_.()'"+\-*/\s\[\]]+)?}}/gi; + var TEMPLATE_RE = /{{([A-Za-z0-9_$@]+)([A-Za-z0-9_.()'"+\-*/\s\[\]]+)?}}/gi; var compiled = template; template.replace(TEMPLATE_RE, function (match, key, modifiers) { if (!modifiers) { diff --git a/dist/moon.min.js b/dist/moon.min.js index d01a6beb..081f9ccf 100644 --- a/dist/moon.min.js +++ b/dist/moon.min.js @@ -5,4 +5,4 @@ * Free to use under the MIT license. * https://kingpixil.github.io/license */ -!function(e,t){"object"==typeof module&&module.exports?module.exports=t():e.Moon=t()}(this,function(){"use strict";function e(e){this.instance=e,this.cache={}}function t(t){this.$opts=t||{},this.$id=s++,this.$name=this.$opts.name||"root",this.$data=this.$opts.data||{},this.$render=this.$opts.render||w,this.$hooks=this.$opts.hooks||{},this.$methods=this.$opts.methods||{},this.$events={},this.$dom={},this.$observer=new e(this),this.$destroyed=!1,this.$initialRender=!0,this.$queued=!1,this.$opts.computed&&a(this,this.$opts.computed),this.init()}var n={},r={},o={},i={stop:"event.stopPropagation();",prevent:"event.preventDefault();",ctrl:"if(!event.ctrlKey) {return;};",shift:"if(!event.shiftKey) {return;};",alt:"if(!event.altKey) {return;};",enter:"if(event.keyCode !== 13) {return;};"},s=0,a=function(e,t){var n=function(n){e.$observer.cache[n]={dirty:!0,getter:t[n].get,cache:null};var r={get:function(){return e.$observer.getComputed(n)}};t[n].set&&(r.set=function(r){return t[n].set.call(e,r)}),Object.defineProperty(e.$data,n,r)};for(var r in t)n(r)};e.prototype.getComputed=function(e){if(this.cache[e].dirty){var t=this.cache[e].getter.call(this.instance);return this.cache[e].cache=t,t}return this.cache[e].cache},e.prototype.notify=function(){u(this.instance)};var c=function(e){t.config.silent||console.log(e)},p=function(e){console.error("[Moon] ERR: "+e)},u=function(e){e.$queued||e.$destroyed||(e.$queued=!0,setTimeout(function(){e.build(),S(e,"updated"),e.$queued=!1},0))},l=function(e){for(var t={},n=e.attributes,r=n.length;r--;)t[n[r].name]=n[r].value;return e.__moon__props__=t,t},f=function(){return{shouldRender:!0,eventListeners:{}}},h=function(e){var t=/\n/g,n=/"/g,r=/\\/g;return e.replace(r,"\\\\").replace(n,'\\"').replace(t,"\\n")},d=function(e,t,n,r){var o;n.replace(/\[(\w+)\]/g,function(e,t){n=n.replace(e,"."+t)});var i=n.split(".");for(o=0;o",e.current);return r===-1?(e.tokens.push({type:"comment",value:t.slice(e.current)}),void(e.current=n)):(e.tokens.push({type:"comment",value:t.slice(e.current,r)}),void(e.current=r+3))},T=function(e){var t=e.input,n=(t.length,"/"===t.charAt(e.current+1));e.tokens.push({type:"tagStart",close:n}),e.current+=n?2:1;var r=j(e);N(e);var o="/"===t.charAt(e.current);e.tokens.push({type:"tagEnd",close:!1}),e.current+=o?2:1,o&&(e.tokens.push({type:"tagStart",close:!0}),e.tokens.push({type:"tag",value:r}),e.tokens.push({type:"attribute",value:{}}),e.tokens.push({type:"tagEnd",close:!1}))},j=function(e){for(var t=e.input,n=t.length,r=e.current;r"!==o&&" "!==o)break;r++}for(var i=r;i"===o||" "===o)break;i++}var s=t.slice(r,i);return e.tokens.push({type:"tag",value:s}),e.current=i,s},N=function(e){for(var t=e.input,n=t.length,r=e.current,o={},i=t.charAt(r),s=t.charAt(r+1),a=function(){r++,i=t.charAt(r),s=t.charAt(r+1)};r"!==i&&("/"!==i||">"!==s);)if(" "!==i){for(var c="",p=!1;"="!==i&&r"!==i||"/"===i&&">"!==s)){p=!0;break}c+=i,a()}if(p)o[c]="";else{var u="",l=" ";for(a(),"'"===i||'"'===i?(l=i,a()):u+=i;(i!==l&&">"!==i||"/"===i&&">"!==s)&&r1&&(s=c.shift(),a=c.join("(").slice(0,-1));var p="";r.shift();for(var u=0;u",e.current);return r===-1?(e.tokens.push({type:"comment",value:t.slice(e.current)}),void(e.current=n)):(e.tokens.push({type:"comment",value:t.slice(e.current,r)}),void(e.current=r+3))},T=function(e){var t=e.input,n=(t.length,"/"===t.charAt(e.current+1));e.tokens.push({type:"tagStart",close:n}),e.current+=n?2:1;var r=j(e);N(e);var o="/"===t.charAt(e.current);e.tokens.push({type:"tagEnd",close:!1}),e.current+=o?2:1,o&&(e.tokens.push({type:"tagStart",close:!0}),e.tokens.push({type:"tag",value:r}),e.tokens.push({type:"attribute",value:{}}),e.tokens.push({type:"tagEnd",close:!1}))},j=function(e){for(var t=e.input,n=t.length,r=e.current;r"!==o&&" "!==o)break;r++}for(var i=r;i"===o||" "===o)break;i++}var s=t.slice(r,i);return e.tokens.push({type:"tag",value:s}),e.current=i,s},N=function(e){for(var t=e.input,n=t.length,r=e.current,o={},i=t.charAt(r),s=t.charAt(r+1),a=function(){r++,i=t.charAt(r),s=t.charAt(r+1)};r"!==i&&("/"!==i||">"!==s);)if(" "!==i){for(var c="",p=!1;"="!==i&&r"!==i||"/"===i&&">"!==s)){p=!0;break}c+=i,a()}if(p)o[c]="";else{var u="",l=" ";for(a(),"'"===i||'"'===i?(l=i,a()):u+=i;(i!==l&&">"!==i||"/"===i&&">"!==s)&&r1&&(s=c.shift(),a=c.join("(").slice(0,-1));var p="";r.shift();for(var u=0;u