New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nis-view

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nis-view - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

lib/view.js

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

@@ -6,0 +6,0 @@ "description": "view engine",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc