Comparing version 0.1.7 to 0.1.8
@@ -1,1 +0,1 @@ | ||
"use strict";function e(e,n,i,a){var o,l;return n=n||{},3===arguments.length&&"string"==typeof arguments[2]&&(a=arguments[2],i={}),i=i||{},i.normalizeWhitespace=i.normalizeWhitespace===!1?!1:H||!1,i.xmlMode=i.xmlMode||!1,o=t(e,n.view||n,i||{},a),l=r(o.$.html()),l.isLayout=o.isLayout,l.layout=o.layout,l.partials=o.partials,l.containers=o.containers,l.mapping=n.view?n:{view:n},l.mapping=l.mapping||{},l}function t(e,t,r,n){function i(e,t){t.html(K+"getObjValue(model,"+X+e.html+X+",false,"+X+t.html()+X+",dynamicKeys)"+z)}function a(e,t){var r,n,i,a;if("[object Object]"===Object.prototype.toString.call(e.attrs))for(r in e.attrs)if("style"===r&&"[object Object]"===Object.prototype.toString.call(e.attrs[r]))for(n in e.attrs[r])t.css(n,K+"getObjValue(model,"+X+e.attrs[r][n]+X+",true,"+X+(t.css(n)||"")+X+",dynamicKeys)"+z);else if("class"===r&&"[object Object]"===Object.prototype.toString.call(e.attrs[r])){i="(function(){var classes=["+X+(t.attr("class")||"").split(" ").join(X+","+X)+X+"];";for(a in e.attrs[r])i+="classes=getClassValue(model,"+X+a+X+","+X+e.attrs[r][a]+X+",classes,dynamicKeys);";i+="return encode(classes.join("+X+" "+X+"));})()",t.attr(r,K+i+z)}else t.attr(r,K+"getObjValue(model,"+X+e.attrs[r]+X+",true,"+X+(t.attr(r)||"")+X+",dynamicKeys)"+z)}function o(e,t){var r,n,o=t.first(),s=m.html(o);if(t.length>1)for(r=1;r<t.length;r++)s+=m.html(o.next()),o.next().remove();s=s.replace(/\n(\s|\n)*\n/g,"\n"),e.html&&i(e,o),e.attrs&&a(e,o),"[object Object]"===Object.prototype.toString.call(e.inside)&&l(e.inside,o),n="<nis-render-code>"+K+"(function(refArray){"+(e["default"]!==!1&&e.showDefault!==!1?"if(refArray.length===0)return "+X+s+X+";":"")+"var out="+X+X+";for(var i=0;i"+M+"refArray.length;i++){out+=(function(model){return "+X+m.html(o).replace(/\n(\s|\n)*\n/g,"\n")+X+";})(refArray[i]);}return out;})(getObjValue(model,"+X+e.repeat+X+",false,undefined,dynamicKeys)||[])"+z+"</nis-render-code>",o.replaceWith(n)}function l(e,t){var r,n;for(r in e)"_"!==r[0]&&"$"!==r[0]&&-1===["partial","widget","container","renderbody","render-body","layout","superlayout","super-layout"].indexOf(r)&&(n=t?t.find(r):m(r),n.length>0&&(e[r].repeat?o(e[r],n):(e[r].html&&i(e[r],n),e[r].attrs&&a(e[r],n))))}var s,c,u,p,d,f,m=J.load(e,r);if(l(t),s=[],m("partial,widget").each(function(){var e=m(this),t=e.attr("template"),r=e.attr("id")||"";t&&(s.push({template:t,id:r}),e.replaceWith("<nis-render-code>"+K+"partials["+(s.length-1)+"]"+z+"</nis-render-code>"))}),c=[],m("[nis-container],[nis-container-id]").each(function(){var e,t=m(this),r=t.attr("nis-container")||t.attr("nis-container-id"),n=(t.attr("nis-container-templates")||t.attr("nis-container-widgets")||"").replace(/\s/g,"").split(",");for(e=0;e<n.length;e++)n[e]||(n.splice(e,1),e--);r&&(c.push({id:r,widgets:n}),t.empty(),t.append("<nis-render-code>"+K+"(containers["+X+r+X+"]||"+X+X+")"+z+"</nis-render-code>"),t.removeAttr("nis-container").removeAttr("nis-container-id").removeAttr("nis-container-widgets").removeAttr("nis-container-templates"),t.attr("nis-render-attribute",K+"(mode==="+X+k+X+" ? "+X+"nis-container="+G+r+G+" nis-container-widgets="+G+n+G+X+":"+X+X+")"+z))}),u=m("renderbody,render-body"),1===u.length)u.first().replaceWith("<nis-render-code>"+K+"body"+z+"</nis-render-code>");else if(u.length>1)throw new Error("Only one <renderbody> or <render-body> element is allowed");if(p=m("layout,superlayout,super-layout"),d=p.attr("template"),p.length>1)throw new Error("Only one <layout> element is allowed, and have to be root element");return p&&d&&p.replaceWith(p.html()),f=m.root().children(),f&&f.each(function(){var e=m(this),t=e.attr("nis-render-attribute")||"",r=(t?t+" ":"")+K+"(mode==="+X+k+X+" ? "+X+_+"="+G+(n||"")+G+" "+B+"="+G+X+"+widgetId+"+X+G+X+" :"+X+X+")"+z;e.attr("nis-render-attribute",r)}),m("[show-if-mode]").each(function(){var e,t=m(this),r=t.attr("show-if-mode");t.removeAttr("show-if-mode"),e=m.html(t).replace(/\n(\s|\n)*\n/g,"\n"),t.replaceWith("<nis-render-code>"+K+"(mode==="+X+r+X+" ? "+X+e+X+" :"+X+X+")"+z+"</nis-render-code>")}),{$:m,isLayout:1===u.length,layout:d,partials:s,containers:c}}function r(e){function t(t,r,n){for(var i=0;i<n.length;i++)if(e[r+i]!==n[i])return!1;return!0}var r,n="'",i={},a={},o={},l=0;for(e=e.replace(/\n(\s|\n)*\n/g,"\n").replace(D,"<").replace(T,">").replace(/<nis-render-code([^>]+)>/g,"").replace(/<nis-render-code>/g,"").replace(/<\/nis-render-code>/g,"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").replace(/\'/g,"\\'").replace(/nis-render-attribute="([^"]*)"/g,"$1").replace(U,'"'),Q&&(e=e.replace(/\n/g,"")),r=0;r<e.length;r++)t(e,r,K)?(l++,i[l]="'+",o[l]=null,a[l]=r+2):t(e,r,z)?(a[l]=null,o[l]=r+2):a[l]&&r>a[l]?i[l]+="\n"===e[r]?"\\n":e[r]:a[l]&&r<=a[l]||(o[l]&&r===o[l]?(l>1?i[l-1]+=i[l]+"+'":1===l&&(n+=i[l].replace(C,"'")+"+'"),l--):o[l]&&r<=o[l]||(n+="\n"===e[r]?"\\n":e[r]));return n+="'",eval('(function(model, mode, body, partials, containers, widgetId, dynamicKeys){partials=partials||{};containers=containers||{};widgetId=widgetId||"";return '+n+";})")}function getObjValue(e,t,r,n,i){var a,o,l,s,c,u;if((void 0===n||null===n)&&(n=""),void 0===e||null===e||"function"==typeof e)return n;if("this"===t)return r?encode(e):e;if(a=t.match(/^[j|J][s|S][o|O][n|N]\((.+)\)$/),a&&(t=a[1]),i&&(o=t.match(/\{([^\}]+)\}/g)))for(l=0;l<o.length;l++)o[l]=o[l].substring(1,o[l].length-1),t=t.replace(new RegExp(("{"+o[l]+"}").escape()),i[o[l]]||o[l]);for(s=t.split("."),c=e,u=0;u<s.length;u++){if(void 0===c||null===c||!c.hasOwnProperty||!c.hasOwnProperty(s[u]))return n;c=c[s[u]]}return"undefined"==typeof c&&(c=""),"function"==typeof c?n:a?r?encode(JSON.stringify(c)):JSON.stringify(c):r?encode(c):c}function getClassValue(e,t,r,n,i){var a,o,l,s,c,u;if(")"===t[t.length-1]&&(a=t.match(/^[p|P][r|R][e|E][f|F][i|I][x|X]\((.+)\)$/),o=t.match(/^[s|S][u|U][f|F][f|F][i|I][x|X]\((.+)\)$/)),c="",a)for(s=getObjValue(e,r,!1,"",i),s=Array.isArray(s)?s:[s],u=0;u<s.length;u++)s[u]&&(c=a[1]+s[u],-1===n.indexOf(c)&&n.push(c));else if(o)for(s=getObjValue(e,r,!1,"",i),s=Array.isArray(s)?s:[s],u=0;u<s.length;u++)s[u]&&(c=s[u]+o[1],-1===n.indexOf(c)&&n.push(c));else l=getObjValue(e,r,!1,"",i),l===!0?-1===n.indexOf(t)&&n.push(t):l===!1&&-1!==n.indexOf(t)&&n.splice(n.indexOf(t),1);return n}function encode(e){return"string"!=typeof e&&(e.toString?e=e.toString():e+=""),e.replace(/\u0026/g,"&").replace(/\u0022/g,""").replace(/\u0027/g,"'").replace(/\u003e/g,"&qt;").replace(/\u003c/g,"<")}function n(e){return e.replace(new RegExp("^"+(module.exports.viewDirId+"/").escape(),"g"),"").replace(/^widgets\//,"").replace(/\.html$/,"").replace(/\//g,"_")}function i(e,t,r){if(2===arguments.length&&(r=arguments[1],t={}),"function"!=typeof r)throw new Error("Wrong arguments");O.existsOrCreateSync(e),O.watchRecursive(e,t,o,function(e,t){if(e)r(new Error("NIS view engine: init failed").cause(e));else{for(var n in t)try{if(t[n].isFile&&t[n].ext===I){if($[n]=l(t[n].fullPath,(t[n+"."+N]||{}).fullPath,n),$[n]instanceof Error)throw $[n];t[n+"."+P]&&($[n].script=t[n+"."+P].fullPath)}}catch(e){return r(new Error('NIS view engine: init failed template "'+n+'"').cause(e))}r()}})}function a(e,t,r){t=j.resolve(t),r&&(r=j.resolve(r));try{$[e]=l(t,r,e)}catch(n){$[e]=new Error("NIS view engine: registerView failed").cause(n)}return $[e]}function o(e,t){if(e)throw e;for(var r=0;r<t.length;r++)!function(e){var r,n=t[e].file,i=t[e].event;if(n.ext===I)r=n.id;else if(n.ext===N)r=n.id.replace(new RegExp("\\."+N+"$"),"");else{if(n.ext!==P)return;r=n.id.replace(new RegExp("\\."+P+"$"),"")}if(n.isFile)if(n.ext===I)"removed"===i?delete $[r]:("created"===i||"updated"===i)&&s(n.fullPath,n.fullPath+"."+N,r,function(e,t){if(e)$[r]=e;else{var n=$[r].script?$[r].script+"":null;$[r]=t,$[r].script=n}});else if(n.ext===N)("removed"===i&&$[r]||"created"===i||"updated"===i)&&s(n.fullPath.replace(new RegExp("\\."+N+"$"),""),"remove"!==i?n.fullPath:null,r,function(e,t){if(e)$[r]=e;else{var n=$[r].script+"";$[r]=t,$[r].script=n}});else if(n.ext===P){if("removed"===i){try{delete require.cache[require.resolve(n.fullPath)]}catch(a){}$[r]&&delete $[r].script}"updated"===i?delete require.cache[require.resolve(n.fullPath)]:"created"===i&&($[r].script=n.fullPath)}}(r)}function l(t,r,i){var a,o,l={};if(r){try{l=E.readFileSync(r,{encoding:"utf8"})}catch(s){return new Error("NIS view engine compileSync: reading mapping file failed").details({template:t,cause:s})}try{l=JSON.parse(l||"{}")}catch(s){return new Error("NIS view engine compileSync: JSON.parse mapping data failed").details({template:t,cause:s})}if("[object Object]"!==Object.prototype.toString.call(l))return new Error("NIS view engine compileSync: mapping is not object").details({template:t})}try{a=E.readFileSync(t,{encoding:"utf8"})}catch(s){return new Error("NIS view engine compileSync: reading template file failed").details({template:t,cause:s})}try{return o=i.replace(new RegExp("^"+((module.exports.viewDirId||"")+"/").escape(),"g"),""),l.baseProp=l.baseProp||n(o),e(a,l,o)}catch(s){return new Error("NIS view engine compileSync: compiling template file failed").details({template:t,cause:s})}}function s(t,r,i,a){function o(r,a){O.readFile(t,{encoding:"utf8"},function(o,l){if(o)a(new Error("NIS view engine compileAsync: reading template file failed").details({template:t,cause:o}));else try{var s=i.replace(new RegExp("^"+((module.exports.viewDirId||"")+"/").escape(),"g"),"");r.baseProp=r.baseProp||n(s),a(null,e(l,r,s))}catch(o){a(new Error("NIS view engine compileAsync: compile template failed").details({template:t,cause:o}))}})}r?E.exists(r,function(e){e?O.readFile(r,{encoding:"utf8"},function(e,r){if(e)a(new Error("NIS view engine compileAsync: reading mapping file failed").cause(e));else{var n={};try{n=JSON.parse(r||"{}")}catch(e){return a(new Error("NIS view engine compileAsync: JSON.parse mapping data failed").details({template:t,cause:e}))}if("[object Object]"!==Object.prototype.toString.call(n))return a(new Error("NIS view engine compileAsync: mapping is not object").details({template:t}));o(n,a)}}):o({},a)}):o({},a)}function c(e,t){if(!t)throw new Error('View "'+e+'" not found');if(t instanceof Error)throw new Error('View "'+e+'" compilation failed').cause(t);if("function"!=typeof t)throw new Error('View "'+e+'" is not function')}function u(e,t,r,n,i,a){var o,l,s,u,f;return 5===arguments.length&&"function"==typeof arguments[4]&&(a=arguments[4],i={}),o=(e?e+"/":"")+p(t,a),o.match(A)||(o+="."+I),l=$[o],c(o,l),s=l(r,n,"",d(e,r,n,l.partials,i,a),i),l.layout&&(u=(e?e+"/":"")+p(l.layout,a),u.match(A)||(u+="."+I),f=$[u],c(u,f),s=f(r,n,s,d(e,r,n,f.partials,i,a),i)),s}function p(e,t){return t?t(e):e}function d(e,t,r,i,a,o){var l,s,u,d,f=[];if(!i||0===i.length)return[];for(l=0;l<i.length;l++)s=(e?e+"/":"")+p(i[l].template,o),s.match(A)||(s+="."+I),u=$[s],c(s,u),d={},i[l].id&&(d[u.mapping.baseProp||n(i[l].id)]=i[l].id),f.push(u(t,r,"",[],a||{},i[l].id,d));return f}function f(e,t,r,n,i,a){var o,l=m(e,t,a),s=l(r,n,"",g(e,r,n,l.partials,i,a),i||{});return l.layout&&(o=m(e,l.layout,a),s=o(r,n,s,g(e,r,n,o.partials,i,a),i||{})),s}function m(e,t,r){var n,i,a,o=p(t,r),s=(e?e+"/":"")+o;return s.match(A)||(s+="."+I),n=$[s],n?(c(s,n),n):(i=process.cwd()+"/"+s,a=i+"."+N,E.existsSync(a)||(a=null),n=$[s]=l(i,a,s),c(s,n),n)}function g(e,t,r,i,a,o){var l,s,c,u=[];if(!i||0===i.length)return[];for(l=0;l<i.length;l++)s=m(e,i[l].template,o),c={},i[l].id&&(c[s.mapping.baseProp||n(i[l].id)]=i[l].id),u.push(s(t,r,"",[],a||{},i[l].id,c));return u}function h(e,t,r,n,i){var a,o,l,s,c,u;if("string"==typeof r&&(r=r.replace(/(\r\n|\r|\n)\s*$/,"")),a=t.match(/^[j|J][s|S][o|O][n|N]\((.+)\)$/)){t=a[1];try{r=JSON.parse(r)}catch(p){r=void 0}}if(4===arguments.length&&"string"!=typeof arguments[3]&&(i=arguments[3],n=null),i&&(o=t.match(/\{([^\}]+)\}/g)))for(l=0;l<o.length;l++)o[l]=o[l].substring(1,o[l].length-1),t=t.replace(new RegExp(("{"+o[l]+"}").escape()),i[o[l]]||o[l]);if(s=t.split("."),c=e,"this"===t)"push"===n?Array.isArray(e)?e.push(r):e=[r]:e=r;else for(u=0;u<s.length;u++)u>=s.length-1?"push"===n?Array.isArray(c[s[u]])?c[s[u]].push(r):c[s[u]]=[r]:(c[s[u]]=r,"undefined"==typeof r&&delete c[s[u]]):"[object Object]"===Object.prototype.toString.call(c[s[u]])||Array.isArray(c[s[u]])||(c[s[u]]={}),c=c[s[u]];return e}function y(e,t,r,n,i,a){if(!r.html||""===r.html||0===t.length)return void a(null,n);var o=t.first().html();n=h(n,r.html,o,i),a(null,n)}function v(e,t,r,n,i,a){var o,l,s,c,u,p,d,f,m;if(!r.attrs||""===r.attrs||0===t.length)return void a(null,n);for(o in r.attrs)if("style"===o&&"[object Object]"===Object.prototype.toString.call(r.attrs[o])){l={};for(s in r.attrs[o])l=t.first().css(s),n=h(n,r.attrs[o][s],l,i)}else if("class"===o&&"[object Object]"===Object.prototype.toString.call(r.attrs[o])){l={},d=(t.first().attr("class")||"").split(" ");for(f in r.attrs[o]){if(c=null,u=null,")"===f[f.length-1]&&(c=f.match(/^[p|P][r|R][e|E][f|F][i|I][x|X]\((.+)\)$/),u=f.match(/^[s|S][u|U][f|F][f|F][i|I][x|X]\((.+)\)$/)),c){for(c=new RegExp("^"+c[1]+"(.+)"),l=[],m=0;m<d.length;m++)p=d[m].match(c),p&&l.push(p[1]);l.length<=1&&(l=l[0])}else if(u){for(u=new RegExp("(.+)"+u[1]+"$"),l=[],m=0;m<d.length;m++)p=d[m].match(u),p&&l.push(p[1]);l.length<=1&&(l=l[0])}else l=-1!==d.indexOf(f);n=h(n,r.attrs[o][f],l,i)}}else"string"==typeof r.attrs[o]&&(l=t.first().attr(o),n=h(n,r.attrs[o],l,i));a(null,n)}function w(e,t,r,n,i,a){if(!r.repeat||""===r.repeat)return void a(null,n);if(t.length<1)return n=h(n,r.repeat,[],i),void a(null,n);n=h(n,r.repeat,[],i);var o=new q(setImmediate);t.each(function(){var t=e(this);o.add(function(o){y(e,t,r,{},i,function(l,s){return l?void a(l):void v(e,t,r,s,i,function(l,s){return l?void a(l):void(r.inside?x(e,t,r.inside,s,i,function(e,t){return e?void a(e):(n=h(n,r.repeat,t,"push",i),void o())}):(n=h(n,r.repeat,s,"push",i),o()))})})})}),o.execute(function(e){a(e,n)})}function x(e,t,r,n,i,a){q.each(r,function(a,o){var l=t.find(a);new q(setImmediate).add(function(t){r[a].html&&!r[a].repeat?y(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).add(function(t){r[a].attrs&&!r[a].repeat?v(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).add(function(t){r[a].repeat?w(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).execute(o)},function(e){a(e,n)})}function b(e,t,r,n){var i,a;3===arguments.length&&(n=arguments[2],r={}),r=r||{},r.normalizeWhitespace=r.normalizeWhitespace===!1?!1:H||!1,r.xmlMode=r.xmlMode||!1,i=J.load(e||"",r),a=r.valueObj||{},t=t||{},x(i,i.root(),t,a,r.dynamicKeys,n)}function S(e,t,r){var n,i;return 2===arguments.length&&"string"!=typeof arguments[1]&&(r=arguments[1],t=""),r=r||{},r.normalizeWhitespace=r.normalizeWhitespace===!1?!1:H||!1,r.xmlMode=r.xmlMode||!1,t=t||R,n=J.load(e||"",r),i=[],n.root().find("["+t+"]").each(function(){var e,r,a=n(this),o=a.attr(t),l=a.closest("["+F+"]").attr(F)||"",s=a.attr(W)||"";o&&(e=a.prev("["+t+"]"),e&&e.attr(t)===o&&(e.attr(W)||"")===s?(r=n(this).clone(),r.find("["+t+"]").remove(),i[i.length-1].html+=n.html(r)):(r=n(this).clone(),r.find("["+t+"]").remove(),i.push({template:o,html:n.html(r),containerId:l,widgetId:s})))}),i}var O,j,E,I,A,N,P,e,$,q,R,F,W,V,J=require("cheerio"),K="##!",z="!##",M="#L!T#",D=/#L!T#/g,L="#G!T#",T=/#G!T#/g,X="~!~",C=/\~!\~/g,G="~!!~",U=/\~!!\~/g,_="nis-template-id",k="admin",B="nis-widget-id",H=!1,Q=!1;module.exports.compile=e,O=require("nis-utils").fsExt,j=require("path"),E=require("fs"),I="html",A=/\.html$/g,N="json",P="js","undefined"==typeof e&&(e=require("./compile.js").compile),module.exports.init=i,module.exports.compile=e,module.exports.compileSync=l,module.exports.compileAsync=s,module.exports.get=module.exports.getView=function(e){return $[e]},module.exports.getAll=module.exports.getViews=function(){return $},module.exports.register=a,module.exports.render=u,module.exports.renderSync=f,module.exports.viewDirId,$={},J=require("cheerio"),q=require("nis-utils").async.Series,module.exports.parse=b,module.exports.slice=S,R="nis-template-id",F="nis-container",W="nis-widget-id",H=!1,V=require("js2xmlparser"),module.exports.xml=function(e,t){return V((t||{}).rootName||"root",e,t||{})}; | ||
"use strict";function e(e,n,i,a){var o,l;return n=n||{},3===arguments.length&&"string"==typeof arguments[2]&&(a=arguments[2],i={}),i=i||{},i.normalizeWhitespace=i.normalizeWhitespace===!1?!1:H||!1,i.xmlMode=i.xmlMode||!1,o=t(e,n.view||n,i||{},a),l=r(o.$.html()),l.isLayout=o.isLayout,l.layout=o.layout,l.partials=o.partials,l.containers=o.containers,l.mapping=n.view?n:{view:n},l.mapping=l.mapping||{},l}function t(e,t,r,n){function i(e,t){t.html(K+"getObjValue(model,"+X+e.html+X+",false,"+X+t.html()+X+",dynamicKeys)"+z)}function a(e,t){var r,n,i,a;if("[object Object]"===Object.prototype.toString.call(e.attrs))for(r in e.attrs)if("style"===r&&"[object Object]"===Object.prototype.toString.call(e.attrs[r]))for(n in e.attrs[r])t.css(n,K+"getObjValue(model,"+X+e.attrs[r][n]+X+",true,"+X+(t.css(n)||"")+X+",dynamicKeys)"+z);else if("class"===r&&"[object Object]"===Object.prototype.toString.call(e.attrs[r])){i="(function(){var classes=["+X+(t.attr("class")||"").split(" ").join(X+","+X)+X+"];";for(a in e.attrs[r])i+="classes=getClassValue(model,"+X+a+X+","+X+e.attrs[r][a]+X+",classes,dynamicKeys);";i+="return encode(classes.join("+X+" "+X+"));})()",t.attr(r,K+i+z)}else t.attr(r,K+"getObjValue(model,"+X+e.attrs[r]+X+",true,"+X+(t.attr(r)||"")+X+",dynamicKeys)"+z)}function o(e,t){var r,n,o=t.first(),s=m.html(o);if(t.length>1)for(r=1;r<t.length;r++)s+=m.html(o.next()),o.next().remove();s=s.replace(/\n(\s|\n)*\n/g,"\n"),e.html&&i(e,o),e.attrs&&a(e,o),"[object Object]"===Object.prototype.toString.call(e.inside)&&l(e.inside,o),n="<nis-render-code>"+K+"(function(refArray){"+(e["default"]!==!1&&e.showDefault!==!1?"if(refArray.length===0)return "+X+s+X+";":"")+"var out="+X+X+";for(var i=0;i"+M+"refArray.length;i++){out+=(function(model){return "+X+m.html(o).replace(/\n(\s|\n)*\n/g,"\n")+X+";})(refArray[i]);}return out;})(getObjValue(model,"+X+e.repeat+X+",false,undefined,dynamicKeys)||[])"+z+"</nis-render-code>",o.replaceWith(n)}function l(e,t){var r,n;for(r in e)"_"!==r[0]&&"$"!==r[0]&&-1===["partial","widget","container","renderbody","render-body","layout","superlayout","super-layout"].indexOf(r)&&(n=t?t.find(r):m(r),n.length>0&&(e[r].repeat?o(e[r],n):(e[r].html&&i(e[r],n),e[r].attrs&&a(e[r],n))))}var s,c,u,p,d,f,m=J.load(e,r);if(l(t),s=[],m("partial,widget").each(function(){var e=m(this),t=e.attr("template"),r=e.attr("id")||"";t&&(s.push({template:t,id:r}),e.replaceWith("<nis-render-code>"+K+"partials["+(s.length-1)+"]"+z+"</nis-render-code>"))}),c=[],m("[nis-container],[nis-container-id]").each(function(){var e,t=m(this),r=t.attr("nis-container")||t.attr("nis-container-id"),n=(t.attr("nis-container-templates")||t.attr("nis-container-widgets")||"").replace(/\s/g,"").split(",");for(e=0;e<n.length;e++)n[e]||(n.splice(e,1),e--);r&&(c.push({id:r,widgets:n}),t.empty(),t.append("<nis-render-code>"+K+"(containers["+X+r+X+"]||"+X+X+")"+z+"</nis-render-code>"),t.removeAttr("nis-container").removeAttr("nis-container-id").removeAttr("nis-container-widgets").removeAttr("nis-container-templates"),t.attr("nis-render-attribute",K+"(mode==="+X+k+X+" ? "+X+"nis-container="+G+r+G+" nis-container-widgets="+G+n+G+X+":"+X+X+")"+z))}),u=m("renderbody,render-body"),1===u.length)u.first().replaceWith("<nis-render-code>"+K+"body"+z+"</nis-render-code>");else if(u.length>1)throw new Error("Only one <renderbody> or <render-body> element is allowed");if(p=m("layout,superlayout,super-layout"),d=p.attr("template"),p.length>1)throw new Error("Only one <layout> element is allowed, and have to be root element");return p&&d&&p.replaceWith(p.html()),f=m.root().children(),f&&f.each(function(){var e=m(this),t=e.attr("nis-render-attribute")||"",r=(t?t+" ":"")+K+"(mode==="+X+k+X+" ? "+X+_+"="+G+(n||"")+G+" "+B+"="+G+X+"+widgetId+"+X+G+X+" :"+X+X+")"+z;e.attr("nis-render-attribute",r)}),m("[show-if-mode]").each(function(){var e,t=m(this),r=t.attr("show-if-mode");t.removeAttr("show-if-mode"),e=m.html(t).replace(/\n(\s|\n)*\n/g,"\n"),t.replaceWith("<nis-render-code>"+K+"(mode==="+X+r+X+" ? "+X+e+X+" :"+X+X+")"+z+"</nis-render-code>")}),{$:m,isLayout:1===u.length,layout:d,partials:s,containers:c}}function r(e){function t(t,r,n){for(var i=0;i<n.length;i++)if(e[r+i]!==n[i])return!1;return!0}var r,n="'",i={},a={},o={},l=0;for(e=e.replace(/\n(\s|\n)*\n/g,"\n").replace(D,"<").replace(T,">").replace(/<nis-render-code([^>]+)>/g,"").replace(/<nis-render-code>/g,"").replace(/<\/nis-render-code>/g,"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").replace(/\'/g,"\\'").replace(/nis-render-attribute="([^"]*)"/g,"$1").replace(U,'"'),Q&&(e=e.replace(/\n/g,"")),r=0;r<e.length;r++)t(e,r,K)?(l++,i[l]="'+",o[l]=null,a[l]=r+2):t(e,r,z)?(a[l]=null,o[l]=r+2):a[l]&&r>a[l]?i[l]+="\n"===e[r]?"\\n":e[r]:a[l]&&r<=a[l]||(o[l]&&r===o[l]?(l>1?i[l-1]+=i[l]+"+'":1===l&&(n+=i[l].replace(C,"'")+"+'"),l--):o[l]&&r<=o[l]||(n+="\n"===e[r]?"\\n":e[r]));return n+="'",eval('(function(model, mode, body, partials, containers, widgetId, dynamicKeys){partials=partials||{};containers=containers||{};widgetId=widgetId||"";return '+n+";})")}function getObjValue(e,t,r,n,i){var a,o,l,s,c,u;if((void 0===n||null===n)&&(n=""),void 0===e||null===e||"function"==typeof e)return n;if("this"===t)return r?encode(e):e;if(a=t.match(/^[j|J][s|S][o|O][n|N]\((.+)\)$/),a&&(t=a[1]),i&&(o=t.match(/\{([^\}]+)\}/g)))for(l=0;l<o.length;l++)o[l]=o[l].substring(1,o[l].length-1),t=t.replace(new RegExp(("{"+o[l]+"}").escape()),i[o[l]]||o[l]);for(s=t.split("."),c=e,u=0;u<s.length;u++){if(void 0===c||null===c||!c.hasOwnProperty||!c.hasOwnProperty(s[u]))return n;c=c[s[u]]}return"undefined"==typeof c&&(c=""),"function"==typeof c?n:a?r?encode(JSON.stringify(c)):JSON.stringify(c):r?encode(c):c}function getClassValue(e,t,r,n,i){var a,o,l,s,c,u;if(")"===t[t.length-1]&&(a=t.match(/^[p|P][r|R][e|E][f|F][i|I][x|X]\((.+)\)$/),o=t.match(/^[s|S][u|U][f|F][f|F][i|I][x|X]\((.+)\)$/)),c="",a)for(s=getObjValue(e,r,!1,"",i),s=Array.isArray(s)?s:[s],u=0;u<s.length;u++)s[u]&&(c=a[1]+s[u],-1===n.indexOf(c)&&n.push(c));else if(o)for(s=getObjValue(e,r,!1,"",i),s=Array.isArray(s)?s:[s],u=0;u<s.length;u++)s[u]&&(c=s[u]+o[1],-1===n.indexOf(c)&&n.push(c));else l=getObjValue(e,r,!1,"",i),l===!0?-1===n.indexOf(t)&&n.push(t):l===!1&&-1!==n.indexOf(t)&&n.splice(n.indexOf(t),1);return n}function encode(e){return"string"!=typeof e&&(e.toString?e=e.toString():e+=""),e.replace(/\u0026/g,"&").replace(/\u0022/g,""").replace(/\u0027/g,"'").replace(/\u003e/g,"&qt;").replace(/\u003c/g,"<")}function n(e){return e.replace(new RegExp("^"+(module.exports.viewDirId+"/").escape(),"g"),"").replace(/^widgets\//,"").replace(/\.html$/,"").replace(/\//g,"_")}function i(e,t,r){if(2===arguments.length&&(r=arguments[1],t={}),"function"!=typeof r)throw new Error("Wrong arguments");O.existsOrCreateSync(e),O.watchRecursive(e,t,o,function(e,t){if(e)r(new Error("NIS view engine: init failed").cause(e));else{for(var n in t)try{if(t[n].isFile&&t[n].ext===I){if($[n]=l(t[n].fullPath,(t[n+"."+N]||{}).fullPath,n),$[n]instanceof Error)throw $[n];t[n+"."+P]&&($[n].script=t[n+"."+P].fullPath)}}catch(e){return r(new Error('NIS view engine: init failed template "'+n+'"').cause(e))}r()}})}function a(e,t,r){t=j.resolve(t),r&&(r=j.resolve(r));try{$[e]=l(t,r,e)}catch(n){$[e]=new Error("NIS view engine: registerView failed").cause(n)}return $[e]}function o(e,t){if(e)throw e;for(var r=0;r<t.length;r++)!function(e){var r,n=t[e].file,i=t[e].event;if(n.ext===I)r=n.id;else if(n.ext===N)r=n.id.replace(new RegExp("\\."+N+"$"),"");else{if(n.ext!==P)return;r=n.id.replace(new RegExp("\\."+P+"$"),"")}if(n.isFile)if(n.ext===I)"removed"===i?delete $[r]:("created"===i||"updated"===i)&&s(n.fullPath,n.fullPath+"."+N,r,function(e,t){if(e)$[r]=e;else{var n=$[r].script?$[r].script+"":null;$[r]=t,$[r].script=n}});else if(n.ext===N)("removed"===i&&$[r]||"created"===i||"updated"===i)&&s(n.fullPath.replace(new RegExp("\\."+N+"$"),""),"remove"!==i?n.fullPath:null,r,function(e,t){if(e)$[r]=e;else{var n=$[r].script+"";$[r]=t,$[r].script=n}});else if(n.ext===P){if("removed"===i){try{delete require.cache[require.resolve(n.fullPath)]}catch(a){}$[r]&&delete $[r].script}"updated"===i?delete require.cache[require.resolve(n.fullPath)]:"created"===i&&($[r].script=n.fullPath)}}(r)}function l(t,r,i){var a,o,l={};if(r){try{l=E.readFileSync(r,{encoding:"utf8"})}catch(s){return new Error("NIS view engine compileSync: reading mapping file failed").details({template:t,cause:s})}try{l=JSON.parse(l||"{}")}catch(s){return new Error("NIS view engine compileSync: JSON.parse mapping data failed").details({template:t,cause:s})}if("[object Object]"!==Object.prototype.toString.call(l))return new Error("NIS view engine compileSync: mapping is not object").details({template:t})}try{a=E.readFileSync(t,{encoding:"utf8"})}catch(s){return new Error("NIS view engine compileSync: reading template file failed").details({template:t,cause:s})}try{return o=i.replace(new RegExp("^"+((module.exports.viewDirId||"")+"/").escape(),"g"),""),l.baseProp=l.baseProp||n(o),e(a,l,o)}catch(s){return new Error("NIS view engine compileSync: compiling template file failed").details({template:t,cause:s})}}function s(t,r,i,a){function o(r,a){O.readFile(t,{encoding:"utf8"},function(o,l){if(o)a(new Error("NIS view engine compileAsync: reading template file failed").details({template:t,cause:o}));else try{var s=i.replace(new RegExp("^"+((module.exports.viewDirId||"")+"/").escape(),"g"),"");r.baseProp=r.baseProp||n(s),a(null,e(l,r,s))}catch(o){a(new Error("NIS view engine compileAsync: compile template failed").details({template:t,cause:o}))}})}r?E.exists(r,function(e){e?O.readFile(r,{encoding:"utf8"},function(e,r){if(e)a(new Error("NIS view engine compileAsync: reading mapping file failed").cause(e));else{var n={};try{n=JSON.parse(r||"{}")}catch(e){return a(new Error("NIS view engine compileAsync: JSON.parse mapping data failed").details({template:t,cause:e}))}if("[object Object]"!==Object.prototype.toString.call(n))return a(new Error("NIS view engine compileAsync: mapping is not object").details({template:t}));o(n,a)}}):o({},a)}):o({},a)}function c(e,t){if(!t)throw new Error('View "'+e+'" not found');if(t instanceof Error)throw new Error('View "'+e+'" compilation failed').cause(t);if("function"!=typeof t)throw new Error('View "'+e+'" is not function')}function u(e,t,r,n,i,a){var o,l,s,u,f;return 5===arguments.length&&"function"==typeof arguments[4]&&(a=arguments[4],i={}),o=(e?e+"/":"")+p(t,a),o.match(A)||(o+="."+I),l=$[o],c(o,l),s=l(r,n,"",d(e,r,n,l.partials,i,a),i),l.layout&&(u=(e?e+"/":"")+p(l.layout,a),u.match(A)||(u+="."+I),f=$[u],c(u,f),s=f(r,n,s,d(e,r,n,f.partials,i,a),i)),s}function p(e,t){return t?t(e):e}function d(e,t,r,i,a,o){var l,s,u,d,f=[];if(!i||0===i.length)return[];for(l=0;l<i.length;l++)s=(e?e+"/":"")+p(i[l].template,o),s.match(A)||(s+="."+I),u=$[s],c(s,u),d={},i[l].id&&(d[u.mapping.baseProp||n(i[l].id)]=i[l].id),f.push(u(t,r,"",[],a||{},i[l].id,d));return f}function f(e,t,r,n,i,a){var o,l=m(e,t,a),s=l(r,n,"",g(e,r,n,l.partials,i,a),i||{});return l.layout&&(o=m(e,l.layout,a),s=o(r,n,s,g(e,r,n,o.partials,i,a),i||{})),s}function m(e,t,r){var n,i,a,o=p(t,r),s=(e?e+"/":"")+o;return s.match(A)||(s+="."+I),n=$[s],n?(c(s,n),n):(i=process.cwd()+"/"+s,a=i+"."+N,E.existsSync(a)||(a=null),n=$[s]=l(i,a,s),c(s,n),n)}function g(e,t,r,i,a,o){var l,s,c,u=[];if(!i||0===i.length)return[];for(l=0;l<i.length;l++)s=m(e,i[l].template,o),c={},i[l].id&&(c[s.mapping.baseProp||n(i[l].id)]=i[l].id),u.push(s(t,r,"",[],a||{},i[l].id,c));return u}function h(e,t,r,n,i){var a,o,l,s,c,u;if("string"==typeof r&&(r=r.replace(/(\r\n|\r|\n)\s*$/,"")),a=t.match(/^[j|J][s|S][o|O][n|N]\((.+)\)$/)){t=a[1];try{r=JSON.parse(r)}catch(p){r=void 0}}if(4===arguments.length&&"string"!=typeof arguments[3]&&(i=arguments[3],n=null),i&&(o=t.match(/\{([^\}]+)\}/g)))for(l=0;l<o.length;l++)o[l]=o[l].substring(1,o[l].length-1),t=t.replace(new RegExp(("{"+o[l]+"}").escape()),i[o[l]]||o[l]);if(s=t.split("."),c=e,"this"===t)"push"===n?Array.isArray(e)?e.push(r):e=[r]:e=r;else for(u=0;u<s.length;u++)u>=s.length-1?"push"===n?Array.isArray(c[s[u]])?c[s[u]].push(r):c[s[u]]=[r]:(c[s[u]]=r,"undefined"==typeof r&&delete c[s[u]]):"[object Object]"===Object.prototype.toString.call(c[s[u]])||Array.isArray(c[s[u]])||(c[s[u]]={}),c=c[s[u]];return e}function y(e,t,r,n,i,a){if(!r.html||""===r.html||0===t.length)return void a(null,n);var o=t.first().html();n=h(n,r.html,o,i),a(null,n)}function v(e,t,r,n,i,a){var o,l,s,c,u,p,d,f,m;if(!r.attrs||""===r.attrs||0===t.length)return void a(null,n);for(o in r.attrs)if("style"===o&&"[object Object]"===Object.prototype.toString.call(r.attrs[o])){l={};for(s in r.attrs[o])l=t.first().css(s),n=h(n,r.attrs[o][s],l,i)}else if("class"===o&&"[object Object]"===Object.prototype.toString.call(r.attrs[o])){l={},d=(t.first().attr("class")||"").split(" ");for(f in r.attrs[o]){if(c=null,u=null,")"===f[f.length-1]&&(c=f.match(/^[p|P][r|R][e|E][f|F][i|I][x|X]\((.+)\)$/),u=f.match(/^[s|S][u|U][f|F][f|F][i|I][x|X]\((.+)\)$/)),c){for(c=new RegExp("^"+c[1]+"(.+)"),l=[],m=0;m<d.length;m++)p=d[m].match(c),p&&l.push(p[1]);l.length<=1&&(l=l[0])}else if(u){for(u=new RegExp("(.+)"+u[1]+"$"),l=[],m=0;m<d.length;m++)p=d[m].match(u),p&&l.push(p[1]);l.length<=1&&(l=l[0])}else l=-1!==d.indexOf(f);n=h(n,r.attrs[o][f],l,i)}}else"string"==typeof r.attrs[o]&&(l=t.first().attr(o),n=h(n,r.attrs[o],l,i));a(null,n)}function w(e,t,r,n,i,a){if(!r.repeat||""===r.repeat)return void a(null,n);if(t.length<1)return n=h(n,r.repeat,[],i),void a(null,n);n=h(n,r.repeat,[],i);var o=new q(setImmediate);t.each(function(){var t=e(this);o.add(function(o){y(e,t,r,{},i,function(l,s){return l?void a(l):void v(e,t,r,s,i,function(l,s){return l?void a(l):void(r.inside?x(e,t,r.inside,s,i,function(e,t){return e?void a(e):(n=h(n,r.repeat,t,"push",i),void o())}):(n=h(n,r.repeat,s,"push",i),o()))})})})}),o.execute(function(e){a(e,n)})}function x(e,t,r,n,i,a){q.each(r,function(a,o){var l=t.find(a);new q(setImmediate).add(function(t){r[a].html&&!r[a].repeat?y(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).add(function(t){r[a].attrs&&!r[a].repeat?v(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).add(function(t){r[a].repeat?w(e,l,r[a],n,i,function(e){e?t(e):t()}):t()}).execute(o)},function(e){a(e,n)})}function b(e,t,r,n){var i,a;3===arguments.length&&(n=arguments[2],r={}),r=r||{},r.normalizeWhitespace=r.normalizeWhitespace===!1?!1:H||!1,r.xmlMode=r.xmlMode||!1,i=J.load(e||"",r),a=r.valueObj||{},t=t||{},x(i,i.root(),t,a,r.dynamicKeys,n)}function S(e,t,r){var n,i;return 2===arguments.length&&"string"!=typeof arguments[1]&&(r=arguments[1],t=""),r=r||{},r.normalizeWhitespace=r.normalizeWhitespace===!1?!1:H||!1,r.xmlMode=r.xmlMode||!1,t=t||R,n=J.load(e||"",r),i=[],n.root().find("["+t+"]").each(function(){var e,r,a,o=n(this),l=o.attr(t),s=o.closest("["+F+"]").attr(F)||"",c=o.attr(W)||"";if(l)if(e=o.prev("["+t+"]"),e&&e.attr(t)===l&&(e.attr(W)||"")===c){for(r=n(this).clone(),r.find("["+t+"]").remove(),a=0;a<i.length;a++)if(i[a].template===l){i[a].html+=n.html(r);break}}else r=n(this).clone(),r.find("["+t+"]").remove(),i.push({template:l,html:n.html(r),containerId:s,widgetId:c})}),i}var O,j,E,I,A,N,P,e,$,q,R,F,W,V,J=require("cheerio"),K="##!",z="!##",M="#L!T#",D=/#L!T#/g,L="#G!T#",T=/#G!T#/g,X="~!~",C=/\~!\~/g,G="~!!~",U=/\~!!\~/g,_="nis-template-id",k="admin",B="nis-widget-id",H=!1,Q=!1;module.exports.compile=e,O=require("nis-utils").fsExt,j=require("path"),E=require("fs"),I="html",A=/\.html$/g,N="json",P="js","undefined"==typeof e&&(e=require("./compile.js").compile),module.exports.init=i,module.exports.compile=e,module.exports.compileSync=l,module.exports.compileAsync=s,module.exports.get=module.exports.getView=function(e){return $[e]},module.exports.getAll=module.exports.getViews=function(){return $},module.exports.register=a,module.exports.render=u,module.exports.renderSync=f,module.exports.viewDirId,$={},J=require("cheerio"),q=require("nis-utils").async.Series,module.exports.parse=b,module.exports.slice=S,R="nis-template-id",F="nis-container",W="nis-widget-id",H=!1,V=require("js2xmlparser"),module.exports.xml=function(e,t){return V((t||{}).rootName||"root",e,t||{})}; |
{ | ||
"name": "nis-view", | ||
"preferGlobal": false, | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"author": "NIS - Matus Szabo <hello@nowitssimple.com>", | ||
@@ -6,0 +6,0 @@ "description": "view engine", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16997