Comparing version
@@ -1,2 +0,2 @@ | ||
/* version: 0.1.8 */ | ||
/* version: 0.1.9 */ | ||
var Absurd = (function(w) { | ||
@@ -60,2 +60,5 @@ var lib = { | ||
_storage = []; | ||
_hooks = {}; | ||
_api.defaultProcessor = lib.processors.css.CSS(); | ||
return _api; | ||
} | ||
@@ -295,2 +298,80 @@ _api.import = function() { | ||
} | ||
lib.api.compileComponent = function(api) { | ||
return function(input, callback, options) { | ||
var css = "", html = "", all = []; | ||
var processCSS = function(clb) { | ||
api.flush(); | ||
for(var i=0; i<all.length, component=all[i]; i++) { | ||
if(typeof component === "function") { component = component(); } | ||
api.add(component.css ? component.css : {}); | ||
} | ||
api.compile(function(err, result) { | ||
css += result; | ||
clb(err); | ||
}, options) | ||
} | ||
var processHTML = function(clb) { | ||
var index = 0; | ||
var error = null; | ||
var processComponent = function() { | ||
if(index > input.length-1) { | ||
clb(error); | ||
return; | ||
} | ||
var c = input[index]; | ||
if(typeof c === "function") { c = c(); } | ||
api.flush().morph("html").add(c.html ? c.html : {}).compile(function(err, result) { | ||
html += result; | ||
index += 1; | ||
error = err; | ||
processComponent(); | ||
}, options); | ||
} | ||
processComponent(); | ||
} | ||
var checkForNesting = function(o) { | ||
for(var key in o) { | ||
if(key === "_include") { | ||
if(o[key] instanceof Array) { | ||
for(var i=0; i<o[key].length, c=o[key][i]; i++) { | ||
if(typeof c === "function") { c = c(); } | ||
all.push(c); | ||
checkForNesting(c); | ||
} | ||
} else { | ||
if(typeof o[key] === "function") { o[key] = o[key](); } | ||
all.push(o[key]); | ||
checkForNesting(o[key]); | ||
} | ||
} else if(typeof o[key] === "object") { | ||
checkForNesting(o[key]); | ||
} | ||
} | ||
} | ||
// Convert the passed argument to an array. | ||
if(!(input instanceof Array)) { | ||
input = [input]; | ||
} | ||
// Checking for nesting. I.e. collecting the css and html. | ||
for(var i=0; i<input.length, c=input[i]; i++) { | ||
if(typeof c === "function") { c = c(); } | ||
all.push(c); | ||
checkForNesting(c); | ||
} | ||
processCSS(function(errCSS) { | ||
processHTML(function(errHTML) { | ||
callback( | ||
errCSS || errHTML ? {error: {css: errCSS, html: errHTML }} : null, | ||
css, | ||
html | ||
) | ||
}); | ||
}); | ||
} | ||
} | ||
lib.api.compileFile = function(api) { | ||
@@ -397,5 +478,5 @@ return api.compile; | ||
var storage = function(name, value) { | ||
if(typeof value != "undefined") { | ||
if(typeof value !== "undefined") { | ||
_s[name] = value; | ||
} else if(typeof value === "undefined" && typeof name === "object") { | ||
} else if(typeof name === "object") { | ||
for(var _name in name) { | ||
@@ -757,3 +838,3 @@ if(Object.prototype.hasOwnProperty.call(name, _name)) { | ||
addToChilds(processTemplate(value)); | ||
} else if(typeof value == "object" && value.length && value.length > 0) { | ||
} else if(value instanceof Array) { | ||
var tmp = ''; | ||
@@ -768,2 +849,19 @@ for(var i=0; tpl=value[i]; i++) { | ||
break; | ||
case "_include": | ||
var tmp = ''; | ||
var add = function(o) { | ||
if(typeof o === "function") { o = o(); } | ||
if(o.css && o.html) { o = o.html; } // catching a component | ||
tmp += process('', o); | ||
} | ||
if(value instanceof Array) { | ||
for(var i=0; i<value.length, o=value[i]; i++) { | ||
add(o); | ||
} | ||
} else if(typeof value === "object"){ | ||
add(value); | ||
} | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
@@ -770,0 +868,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{}}}},b=function(b){switch(b){case"/../processors/html/HTML.js":return a.processors.html.HTML}return function(){}},d="",e=function(){return function(b){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:a.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){f={},g=[]},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in a.api)"compile"!==j&&(e[j]=a.api[j](e),e[j]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(j));for(var k in a.plugins)e.plugin(k,a.plugins[k]());return"function"==typeof b&&b(e),e}};a.api.add=function(a){var b=function(b,c,d,f){var g=a.getPlugins()[c];if("undefined"!=typeof g){var h=g(a,d);return h&&e(b,h,f),!0}return!1},c=function(b){var c=a.getPlugins();for(var d in b)"undefined"!=typeof c[d]&&(b[d]=!1);for(var d in b)":"===d.charAt(0)&&(b[d]=!1);for(var d in b)/&/g.test(d)&&(b[d]=!1)},d=function(a,c,f){for(var g in c)"object"==typeof c[g]?(":"===g.charAt(0)?e(a+g,c[g],f):/&/g.test(g)?e(g.replace(/&/g,a),c[g],f):0===g.indexOf("@media")||0===g.indexOf("@supports")?e(a,c[g],g):b(a,g,c[g],f)===!1&&e(a+" "+g,c[g],f),c[g]=!1):"function"==typeof c[g]?(c[g]=c[g](),d(a,c,f)):b(a,g,c[g],f)&&(c[g]=!1)},e=function(f,g,h){if("undefined"==typeof g.length||"object"!=typeof g){if(!b(null,f,g,h)){if("object"==typeof a.getRules(h||"mainstream")[f]){var i=a.getRules(h||"mainstream")[f];for(var j in g)i[j]=g[j]}else a.getRules(h||"mainstream")[f]=g;d(f,g,h||"mainstream"),c(g)}}else for(var k=0;prop=g[k];k++)e(f,prop,h)},f=function(b,c){a.numOfAddedRules+=1;for(var d in b)if("undefined"!=typeof b[d].length&&"object"==typeof b[d])for(var f=0;r=b[d][f];f++)e(d,r,c||"mainstream");else e(d,b[d],c||"mainstream");return a};return f};var f=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a};a.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var g={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor};d=f(g,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{fs.writeFile(b,e,function(a){c(a,e)})}catch(d){c(d)}else c(d,e);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var g=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.darken=function(){return function(a,b){return g(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var g=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.lighten=function(){return function(a,b){return g(a,b/100)}};var h={html:function(a){a.defaultProcessor=b(d+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})}};a.api.morph=function(a){return function(b){return h[b]&&(a.flush(),h[b](a)),a}},a.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},a.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}},a.api.register=function(a){return function(b,c){return a[b]=c,a}},a.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("undefined"!=typeof e||"object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},a.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},a.helpers.RequireUncached=function(a){return delete b.cache[b.resolve(a)],b(a)};var i=b("clean-css"),j="\n",k={combineSelectors:!0,minify:!1,keepCamelCase:!1},l=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+j;else{var e=d+" {"+j;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=" "+(0==b.keepCamelCase?o(f):f)+": "+g+";"+j}e+="}"+j,c+=e}return c},m=function(a){var b={};for(var c in a){var d=!1,e={};for(var f in a[c]){var g=a[c][f];g!==!1&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},n=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},o=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};a.processors.css.CSS=function(){return function(a,b,c){c=c||k;var d="";for(var e in a){var f=m(a[e]);f=c.combineSelectors?n(f):f,d+="mainstream"===e?l(f,c):e+" {"+j+l(f,c)+"}"+j}return c.minify?(d=i.process(d),b&&b(null,d)):b&&b(null,d),d}},a.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},a.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},a.processors.css.plugins.keyframes=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c)if("undefined"!=typeof c.frames){var f="@keyframes "+c.name+" {\n";f+=e({mainstream:c.frames}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof c.keyframes){for(var f="@keyframes "+c.name+" {\n",g={},h=0;rule=c.keyframes[h];h++)if("keyframe"===rule.type)for(var i=g[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value);f+=e({mainstream:g}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c){for(var f="@media "+c.media+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}},a.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},a.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},a.processors.css.plugins.supports=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c){for(var f="@supports "+c.supports+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}};var p=null,j="\n",k={},o=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b},q=function(a){var b="";for(var c in p)if(c==a)for(var d=p[c].length,e=0;d>e;e++)b+=s("",p[c][e]);return b},s=function(a,b){var c="",d="",e="",f=u(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return t(a,d,b);var g=function(a){""!=e&&(e+=j),e+=a};for(var h in b){var i=b[h];switch(h){case"_attrs":for(var k in i)d+="function"==typeof i[k]?" "+o(k)+'="'+i[k]()+'"':" "+o(k)+'="'+i[k]+'"';b[h]=!1;break;case"_":g(i),b[h]=!1;break;case"_tpl":if("string"==typeof i)g(q(i));else if("object"==typeof i&&i.length&&i.length>0){for(var l="",m=0;tpl=i[m];m++)l+=q(tpl),m<i.length-1&&(l+=j);g(l)}b[h]=!1}}for(var n in b){var i=b[n];if(i!==!1){var p=n;switch(typeof i){case"string":g(s(p,i));break;case"object":if(i.length&&i.length>0){for(var l="",m=0;v=i[m];m++)l+=s("","function"==typeof v?v():v),m<i.length-1&&(l+=j);g(s(p,l))}else g(s(p,i));break;case"function":g(s(p,i()))}}}return c+=""!=a?t(a,d,e):e},t=function(a,b,c){var d="";return d+=""!==c?"<"+o(a)+b+">"+j+c+j+"</"+o(a)+">":"<"+o(a)+b+"/>"},u=function(a){for(var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1,k=0;c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b};return a.processors.html.HTML=function(){return function(a,b,c){p=a,b=b||function(){},c=c||k;var d=q("mainstream");return b(null,d),d}},e()}(window); | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{}}}},b=function(b){switch(b){case"/../processors/html/HTML.js":return a.processors.html.HTML}return function(){}},d="",e=function(){return function(b){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:a.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){return f={},g=[],i={},e.defaultProcessor=a.processors.css.CSS(),e},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in a.api)"compile"!==j&&(e[j]=a.api[j](e),e[j]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(j));for(var k in a.plugins)e.plugin(k,a.plugins[k]());return"function"==typeof b&&b(e),e}};a.api.add=function(a){var b=function(b,c,d,f){var g=a.getPlugins()[c];if("undefined"!=typeof g){var h=g(a,d);return h&&e(b,h,f),!0}return!1},c=function(b){var c=a.getPlugins();for(var d in b)"undefined"!=typeof c[d]&&(b[d]=!1);for(var d in b)":"===d.charAt(0)&&(b[d]=!1);for(var d in b)/&/g.test(d)&&(b[d]=!1)},d=function(a,c,f){for(var g in c)"object"==typeof c[g]?(":"===g.charAt(0)?e(a+g,c[g],f):/&/g.test(g)?e(g.replace(/&/g,a),c[g],f):0===g.indexOf("@media")||0===g.indexOf("@supports")?e(a,c[g],g):b(a,g,c[g],f)===!1&&e(a+" "+g,c[g],f),c[g]=!1):"function"==typeof c[g]?(c[g]=c[g](),d(a,c,f)):b(a,g,c[g],f)&&(c[g]=!1)},e=function(f,g,h){if("undefined"==typeof g.length||"object"!=typeof g){if(!b(null,f,g,h)){if("object"==typeof a.getRules(h||"mainstream")[f]){var i=a.getRules(h||"mainstream")[f];for(var j in g)i[j]=g[j]}else a.getRules(h||"mainstream")[f]=g;d(f,g,h||"mainstream"),c(g)}}else for(var k=0;prop=g[k];k++)e(f,prop,h)},f=function(b,c){a.numOfAddedRules+=1;for(var d in b)if("undefined"!=typeof b[d].length&&"object"==typeof b[d])for(var f=0;r=b[d][f];f++)e(d,r,c||"mainstream");else e(d,b[d],c||"mainstream");return a};return f};var f=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a};a.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var g={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor};d=f(g,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{fs.writeFile(b,e,function(a){c(a,e)})}catch(d){c(d)}else c(d,e);a.flush()},d)}},a.api.compileComponent=function(a){return function(b,d,e){var f="",g="",h=[],i=function(b){a.flush();for(var c=0;c<h.length,component=h[c];c++)"function"==typeof component&&(component=component()),a.add(component.css?component.css:{});a.compile(function(a,c){f+=c,b(a)},e)},j=function(c){var d=0,f=null,h=function(){if(d>b.length-1)return c(f),void 0;var i=b[d];"function"==typeof i&&(i=i()),a.flush().morph("html").add(i.html?i.html:{}).compile(function(a,b){g+=b,d+=1,f=a,h()},e)};h()},k=function(a){for(var b in a)if("_include"===b)if(a[b]instanceof Array)for(var d=0;d<a[b].length,c=a[b][d];d++)"function"==typeof c&&(c=c()),h.push(c),k(c);else"function"==typeof a[b]&&(a[b]=a[b]()),h.push(a[b]),k(a[b]);else"object"==typeof a[b]&&k(a[b])};b instanceof Array||(b=[b]);for(var l=0;l<b.length,c=b[l];l++)"function"==typeof c&&(c=c()),h.push(c),k(c);i(function(a){j(function(b){d(a||b?{error:{css:a,html:b}}:null,f,g)})})}},a.api.compileFile=function(a){return a.compile};var g=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.darken=function(){return function(a,b){return g(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var g=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.lighten=function(){return function(a,b){return g(a,b/100)}};var h={html:function(a){a.defaultProcessor=b(d+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})}};a.api.morph=function(a){return function(b){return h[b]&&(a.flush(),h[b](a)),a}},a.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},a.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}},a.api.register=function(a){return function(b,c){return a[b]=c,a}},a.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},a.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},a.helpers.RequireUncached=function(a){return delete b.cache[b.resolve(a)],b(a)};var i=b("clean-css"),j="\n",k={combineSelectors:!0,minify:!1,keepCamelCase:!1},l=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+j;else{var e=d+" {"+j;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=" "+(0==b.keepCamelCase?p(f):f)+": "+g+";"+j}e+="}"+j,c+=e}return c},m=function(a){var b={};for(var c in a){var d=!1,e={};for(var f in a[c]){var g=a[c][f];g!==!1&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},n=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},p=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};a.processors.css.CSS=function(){return function(a,b,c){c=c||k;var d="";for(var e in a){var f=m(a[e]);f=c.combineSelectors?n(f):f,d+="mainstream"===e?l(f,c):e+" {"+j+l(f,c)+"}"+j}return c.minify?(d=i.process(d),b&&b(null,d)):b&&b(null,d),d}},a.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},a.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},a.processors.css.plugins.keyframes=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c)if("undefined"!=typeof c.frames){var f="@keyframes "+c.name+" {\n";f+=e({mainstream:c.frames}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof c.keyframes){for(var f="@keyframes "+c.name+" {\n",g={},h=0;rule=c.keyframes[h];h++)if("keyframe"===rule.type)for(var i=g[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value);f+=e({mainstream:g}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c){for(var f="@media "+c.media+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}},a.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},a.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},a.processors.css.plugins.supports=function(){return function(a,c){var e=b(d+"/../CSS.js")();if("object"==typeof c){for(var f="@supports "+c.supports+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}};var q=null,j="\n",k={},p=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b},s=function(a){var b="";for(var c in q)if(c==a)for(var d=q[c].length,e=0;d>e;e++)b+=t("",q[c][e]);return b},t=function(a,b){var c="",d="",e="",f=w(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return u(a,d,b);var g=function(a){""!=e&&(e+=j),e+=a};for(var h in b){var i=b[h];switch(h){case"_attrs":for(var k in i)d+="function"==typeof i[k]?" "+p(k)+'="'+i[k]()+'"':" "+p(k)+'="'+i[k]+'"';b[h]=!1;break;case"_":g(i),b[h]=!1;break;case"_tpl":if("string"==typeof i)g(s(i));else if(i instanceof Array){for(var l="",m=0;tpl=i[m];m++)l+=s(tpl),m<i.length-1&&(l+=j);g(l)}b[h]=!1;break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=t("",a)};if(i instanceof Array)for(var m=0;m<i.length,o=i[m];m++)n(o);else"object"==typeof i&&n(i);g(l),b[h]=!1}}for(var q in b){var i=b[q];if(i!==!1){var r=q;switch(typeof i){case"string":g(t(r,i));break;case"object":if(i.length&&i.length>0){for(var l="",m=0;v=i[m];m++)l+=t("","function"==typeof v?v():v),m<i.length-1&&(l+=j);g(t(r,l))}else g(t(r,i));break;case"function":g(t(r,i()))}}}return c+=""!=a?u(a,d,e):e},u=function(a,b,c){var d="";return d+=""!==c?"<"+p(a)+b+">"+j+c+j+"</"+p(a)+">":"<"+p(a)+b+"/>"},w=function(a){for(var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1,k=0;c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b};return a.processors.html.HTML=function(){return function(a,b,c){q=a,b=b||function(){},c=c||k;var d=s("mainstream");return b(null,d),d}},e()}(window); |
@@ -40,2 +40,5 @@ var client = function() { | ||
_storage = []; | ||
_hooks = {}; | ||
_api.defaultProcessor = lib.processors.css.CSS(); | ||
return _api; | ||
} | ||
@@ -42,0 +45,0 @@ _api.import = function() { |
@@ -765,4 +765,2 @@ describe("Adding raw data", function() { | ||
api.morph("html"); | ||
it("should compile nested tags", function(done) { | ||
@@ -773,3 +771,3 @@ var headTags = [ | ||
]; | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -795,3 +793,3 @@ head: headTags, | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -813,6 +811,4 @@ body: getList(["A", "B", "C", "D"]) | ||
api.morph("html"); | ||
it("complex html", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
_:'<!DOCTYPE html>', | ||
@@ -864,4 +860,2 @@ html: { | ||
api.morph("html"); | ||
it("complex html", function(done) { | ||
@@ -889,3 +883,3 @@ var inputField = function(name, defaultValue) { | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -931,4 +925,2 @@ head: { | ||
api.morph("html"); | ||
it("should use function", function(done) { | ||
@@ -945,3 +937,3 @@ var getTitleTag = function(value) { | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -964,6 +956,71 @@ head: getTitleTag("Absurd is awesome"), | ||
api.morph("html"); | ||
it("should use _include", function(done) { | ||
var profile = function() { | ||
return { | ||
".profile": { | ||
"span.name": "John Doe" | ||
} | ||
} | ||
} | ||
var logo = { | ||
".logo": { | ||
'img[src="#"]': {} | ||
} | ||
} | ||
var nav = { | ||
nav: [ | ||
{ 'a[href="#"]': "Home" }, | ||
{ 'a[href="#"]': "Products" }, | ||
{ 'a[href="#"]': "Contacts" } | ||
] | ||
} | ||
var header = { | ||
header: { | ||
_include: [logo, nav, profile] | ||
} | ||
} | ||
var page = { | ||
html: { | ||
body: { | ||
_include: header | ||
} | ||
} | ||
} | ||
api.morph("html").add(page).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
expect(html).toBeDefined(); | ||
expect(html).toBe('<html>\n\ | ||
<body>\n\ | ||
<header>\n\ | ||
<div class="logo">\n\ | ||
<img src="#"/>\n\ | ||
</div><nav>\n\ | ||
<a href="#">\n\ | ||
Home\n\ | ||
</a>\n\ | ||
<a href="#">\n\ | ||
Products\n\ | ||
</a>\n\ | ||
<a href="#">\n\ | ||
Contacts\n\ | ||
</a>\n\ | ||
</nav><div class="profile">\n\ | ||
<span class="name">\n\ | ||
John Doe\n\ | ||
</span>\n\ | ||
</div>\n\ | ||
</header>\n\ | ||
</body>\n\ | ||
</html>'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe("Metamorphosis (to html preprocessor)", function() { | ||
var api = require('../../../index.js')(); | ||
it("should compile an empty tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: {} | ||
@@ -979,3 +1036,3 @@ }).compile(function(err, html) { | ||
it("should compile tag with text inside", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: "page text" | ||
@@ -991,3 +1048,3 @@ }).compile(function(err, html) { | ||
it("should compile tag with attributes", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -1005,3 +1062,3 @@ _attrs: { class: "black" } | ||
it("should compile tag with attributes and text inside", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -1020,3 +1077,3 @@ _attrs: { class: "black" }, | ||
it("should compile tag with attributes, text inside and nested tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -1036,3 +1093,3 @@ _attrs: { class: "black" }, | ||
it("should compile raw content", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
_: '<html></html>' | ||
@@ -1048,3 +1105,3 @@ }).compile(function(err, html) { | ||
it("should compile nested tags", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -1065,3 +1122,3 @@ head: { | ||
it("should compile raw content + nested tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -1096,7 +1153,5 @@ p: { | ||
api.morph("html"); | ||
it("should use templates", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
title: "AbsurdJS preprocessor" | ||
@@ -1161,4 +1216,2 @@ }, "title"); | ||
api.morph("html"); | ||
it("should use classes", function(done) { | ||
@@ -1170,3 +1223,3 @@ var tags = { | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1185,3 +1238,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1200,3 +1253,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1215,3 +1268,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1230,3 +1283,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1245,3 +1298,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1261,3 +1314,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -1277,2 +1330,222 @@ expect(html).toBeDefined(); | ||
}); | ||
describe("Componenting", function() { | ||
var api = require('../../index.js')(); | ||
it("should define component and compile it", function(done) { | ||
var component = { | ||
css: { | ||
"#widget": { | ||
width: "200px", | ||
padding: "30px 10px", | ||
background: "#aaa", | ||
a: { | ||
fontSize: "20px", | ||
textDecoration: "none" | ||
} | ||
} | ||
}, | ||
html: { | ||
"div[id=\"widget\"]": { | ||
p: { | ||
"a[href=\"http://bla.com\"]": "share" | ||
} | ||
} | ||
} | ||
}; | ||
api.compileComponent(component, function(err, css, html) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(html).toBeDefined(); | ||
expect(css).toBe('#widget {\n\ | ||
width: 200px;\n\ | ||
padding: 30px 10px;\n\ | ||
background: #aaa;\n\ | ||
}\n\ | ||
#widget a {\n\ | ||
font-size: 20px;\n\ | ||
text-decoration: none;\n\ | ||
}\n') | ||
expect(html).toBe('<div id="widget">\n\ | ||
<p>\n\ | ||
<a href="http://bla.com">\n\ | ||
share\n\ | ||
</a>\n\ | ||
</p>\n\ | ||
</div>') | ||
done(); | ||
}); | ||
}); | ||
it("should use a function instead of object", function(done) { | ||
var component = function() { | ||
return { | ||
css: { | ||
".login-link": { color: "red"} | ||
}, | ||
html: { | ||
'a.login-link': "Please login" | ||
} | ||
} | ||
} | ||
api.compileComponent(component, function(err, css, html) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(html).toBeDefined(); | ||
expect(css).toBe(".login-link {\n color: red;\n}\n"); | ||
expect(html).toBe('<a class="login-link">\nPlease login\n</a>'); | ||
done(); | ||
}) | ||
}); | ||
it("should compile several components", function(done) { | ||
var componentA = function() { | ||
return { | ||
css: { | ||
".login-link": { color: "red", fontSize: "16px" } | ||
}, | ||
html: { | ||
'a.login-link': "Please login" | ||
} | ||
} | ||
} | ||
var componentB = function() { | ||
return { | ||
css: { | ||
".logout-link": { color: "red", fontSize: "11px" } | ||
}, | ||
html: { | ||
'a.logout-link': "Logout" | ||
} | ||
} | ||
} | ||
api.compileComponent([componentA, componentB], function(err, css, html) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(html).toBeDefined(); | ||
expect(css).toBe(".login-link, .logout-link {\n\ | ||
color: red;\n\ | ||
}\n\ | ||
.login-link {\n\ | ||
font-size: 16px;\n\ | ||
}\n\ | ||
.logout-link {\n\ | ||
font-size: 11px;\n\ | ||
}\n"); | ||
expect(html).toBe('<a class="login-link">\n\ | ||
Please login\n\ | ||
</a><a class="logout-link">\n\ | ||
Logout\n\ | ||
</a>'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
describe("Nested components", function() { | ||
var api = require('../../index.js')(); | ||
it("should use a nested components", function(done) { | ||
var head = function() { | ||
return { | ||
css: { | ||
body: { | ||
width: "100%", | ||
height: "100%", | ||
margin: "10px", | ||
padding: "0px" | ||
} | ||
}, | ||
html: { | ||
head: { | ||
title: "That's my page" | ||
} | ||
} | ||
}; | ||
} | ||
var title = { | ||
css: { | ||
".title": { | ||
fontSize: "24px" | ||
} | ||
}, | ||
html: { | ||
"h1.title": "Hello world" | ||
} | ||
} | ||
var body = function() { | ||
return { | ||
css: { | ||
h1: { fontWeight: "normal" }, | ||
p: { fontSize: "24px", lineHeight: "28px" } | ||
}, | ||
html: { | ||
body: { | ||
_include: title, | ||
p: "Text of the <b>page</b>." | ||
} | ||
} | ||
} | ||
} | ||
var page = function() { | ||
return { | ||
css: { | ||
body: { | ||
margin: "0px", | ||
section: { | ||
marginTop: "20px" | ||
} | ||
} | ||
}, | ||
html: { | ||
_: "<!DOCTYPE html>", | ||
html: { | ||
_include: [head, body] | ||
} | ||
} | ||
} | ||
} | ||
api.compileComponent(page, function(err, css, html) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(html).toBeDefined(); | ||
expect(css).toBe("body {\n\ | ||
margin: 10px;\n\ | ||
width: 100%;\n\ | ||
height: 100%;\n\ | ||
padding: 0px;\n\ | ||
}\n\ | ||
body section {\n\ | ||
margin-top: 20px;\n\ | ||
}\n\ | ||
h1 {\n\ | ||
font-weight: normal;\n\ | ||
}\n\ | ||
p, .title {\n\ | ||
font-size: 24px;\n\ | ||
}\n\ | ||
p {\n\ | ||
line-height: 28px;\n\ | ||
}\n"); | ||
expect(html).toBe('<!DOCTYPE html>\n\ | ||
<html>\n\ | ||
<head>\n\ | ||
<title>\n\ | ||
That\'s my page\n\ | ||
</title>\n\ | ||
</head><body>\n\ | ||
<h1 class="title">\n\ | ||
Hello world\n\ | ||
</h1>\n\ | ||
<p>\n\ | ||
Text of the <b>page</b>.\n\ | ||
</p>\n\ | ||
</body>\n\ | ||
</html>'); | ||
done(); | ||
}) | ||
}); | ||
}); |
@@ -158,2 +158,80 @@ lib.api.add = function(API) { | ||
} | ||
lib.api.compileComponent = function(api) { | ||
return function(input, callback, options) { | ||
var css = "", html = "", all = []; | ||
var processCSS = function(clb) { | ||
api.flush(); | ||
for(var i=0; i<all.length, component=all[i]; i++) { | ||
if(typeof component === "function") { component = component(); } | ||
api.add(component.css ? component.css : {}); | ||
} | ||
api.compile(function(err, result) { | ||
css += result; | ||
clb(err); | ||
}, options) | ||
} | ||
var processHTML = function(clb) { | ||
var index = 0; | ||
var error = null; | ||
var processComponent = function() { | ||
if(index > input.length-1) { | ||
clb(error); | ||
return; | ||
} | ||
var c = input[index]; | ||
if(typeof c === "function") { c = c(); } | ||
api.flush().morph("html").add(c.html ? c.html : {}).compile(function(err, result) { | ||
html += result; | ||
index += 1; | ||
error = err; | ||
processComponent(); | ||
}, options); | ||
} | ||
processComponent(); | ||
} | ||
var checkForNesting = function(o) { | ||
for(var key in o) { | ||
if(key === "_include") { | ||
if(o[key] instanceof Array) { | ||
for(var i=0; i<o[key].length, c=o[key][i]; i++) { | ||
if(typeof c === "function") { c = c(); } | ||
all.push(c); | ||
checkForNesting(c); | ||
} | ||
} else { | ||
if(typeof o[key] === "function") { o[key] = o[key](); } | ||
all.push(o[key]); | ||
checkForNesting(o[key]); | ||
} | ||
} else if(typeof o[key] === "object") { | ||
checkForNesting(o[key]); | ||
} | ||
} | ||
} | ||
// Convert the passed argument to an array. | ||
if(!(input instanceof Array)) { | ||
input = [input]; | ||
} | ||
// Checking for nesting. I.e. collecting the css and html. | ||
for(var i=0; i<input.length, c=input[i]; i++) { | ||
if(typeof c === "function") { c = c(); } | ||
all.push(c); | ||
checkForNesting(c); | ||
} | ||
processCSS(function(errCSS) { | ||
processHTML(function(errHTML) { | ||
callback( | ||
errCSS || errHTML ? {error: {css: errCSS, html: errHTML }} : null, | ||
css, | ||
html | ||
) | ||
}); | ||
}); | ||
} | ||
} | ||
lib.api.compileFile = function(api) { | ||
@@ -260,5 +338,5 @@ return api.compile; | ||
var storage = function(name, value) { | ||
if(typeof value != "undefined") { | ||
if(typeof value !== "undefined") { | ||
_s[name] = value; | ||
} else if(typeof value === "undefined" && typeof name === "object") { | ||
} else if(typeof name === "object") { | ||
for(var _name in name) { | ||
@@ -620,3 +698,3 @@ if(Object.prototype.hasOwnProperty.call(name, _name)) { | ||
addToChilds(processTemplate(value)); | ||
} else if(typeof value == "object" && value.length && value.length > 0) { | ||
} else if(value instanceof Array) { | ||
var tmp = ''; | ||
@@ -631,2 +709,19 @@ for(var i=0; tpl=value[i]; i++) { | ||
break; | ||
case "_include": | ||
var tmp = ''; | ||
var add = function(o) { | ||
if(typeof o === "function") { o = o(); } | ||
if(o.css && o.html) { o = o.html; } // catching a component | ||
tmp += process('', o); | ||
} | ||
if(value instanceof Array) { | ||
for(var i=0; i<value.length, o=value[i]; i++) { | ||
add(o); | ||
} | ||
} else if(typeof value === "object"){ | ||
add(value); | ||
} | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
@@ -633,0 +728,0 @@ } |
@@ -33,2 +33,3 @@ var path = require("path"); | ||
'tests/metamorphosis/**/*.js', | ||
'tests/componenting/**/*.js', | ||
'!tests/common/api.import.spec.js', | ||
@@ -69,2 +70,12 @@ '!tests/common/compile-and-save.spec.js', | ||
} | ||
}, | ||
lineending: { | ||
dist: { | ||
options: { | ||
eol: 'crlf' | ||
}, | ||
files: { | ||
'./index.js': ['./index.js'] | ||
} | ||
} | ||
} | ||
@@ -76,6 +87,7 @@ }); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-lineending'); | ||
grunt.loadTasks('tasks'); | ||
grunt.registerTask('default', ['concat', 'client-side', 'uglify', 'watch']); | ||
grunt.registerTask('default', ['concat', 'client-side', 'uglify', 'lineending', 'watch']); | ||
} |
@@ -27,2 +27,2 @@ #!/usr/bin/env node | ||
// cli | ||
cli(argv, absurd); | ||
cli(argv, absurd); |
@@ -30,3 +30,5 @@ var fs = require('fs'); | ||
_rules = {}; | ||
_storage = []; | ||
_storage = {}; | ||
_hooks = {}; | ||
_api.defaultProcessor = require(__dirname + "/processors/css/CSS.js")(); | ||
return api; | ||
@@ -33,0 +35,0 @@ } |
module.exports = function(API) { | ||
var _s = API.getStorage(); | ||
var storage = function(name, value) { | ||
if(typeof value != "undefined") { | ||
if(typeof value !== "undefined") { | ||
_s[name] = value; | ||
} else if(typeof value === "undefined" && typeof name === "object") { | ||
} else if(typeof name === "object") { | ||
for(var _name in name) { | ||
@@ -8,0 +8,0 @@ if(Object.prototype.hasOwnProperty.call(name, _name)) { |
@@ -73,3 +73,3 @@ | ||
addToChilds(processTemplate(value)); | ||
} else if(typeof value == "object" && value.length && value.length > 0) { | ||
} else if(value instanceof Array) { | ||
var tmp = ''; | ||
@@ -84,2 +84,19 @@ for(var i=0; tpl=value[i]; i++) { | ||
break; | ||
case "_include": | ||
var tmp = ''; | ||
var add = function(o) { | ||
if(typeof o === "function") { o = o(); } | ||
if(o.css && o.html) { o = o.html; } // catching a component | ||
tmp += process('', o); | ||
} | ||
if(value instanceof Array) { | ||
for(var i=0; i<value.length, o=value[i]; i++) { | ||
add(o); | ||
} | ||
} else if(typeof value === "object"){ | ||
add(value); | ||
} | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
@@ -86,0 +103,0 @@ } |
{ | ||
"name": "absurd", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"homepage": "http://krasimir.github.io/absurd", | ||
@@ -28,2 +28,3 @@ "description": "CSS preprocessor", | ||
"grunt-contrib-uglify": "0.2.4", | ||
"grunt-lineending": "0.2.1", | ||
"jasmine-node": "~1.11.0" | ||
@@ -30,0 +31,0 @@ }, |
@@ -5,4 +5,2 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should compile nested tags", function(done) { | ||
@@ -13,3 +11,3 @@ var headTags = [ | ||
]; | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -35,3 +33,3 @@ head: headTags, | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -38,0 +36,0 @@ body: getList(["A", "B", "C", "D"]) |
@@ -5,6 +5,4 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("complex html", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
_:'<!DOCTYPE html>', | ||
@@ -11,0 +9,0 @@ html: { |
@@ -5,4 +5,2 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("complex html", function(done) { | ||
@@ -30,3 +28,3 @@ var inputField = function(name, defaultValue) { | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -33,0 +31,0 @@ head: { |
@@ -5,4 +5,2 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should use function", function(done) { | ||
@@ -19,3 +17,3 @@ var getTitleTag = function(value) { | ||
} | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -22,0 +20,0 @@ head: getTitleTag("Absurd is awesome"), |
@@ -18,6 +18,4 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should use the import method", function(done) { | ||
api.import(__dirname + "/../../data/html.json").compile(function(err, html) { | ||
api.morph("html").import(__dirname + "/../../data/html.json").compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -31,3 +29,3 @@ expect(html).toBeDefined(); | ||
it("should use the import method", function(done) { | ||
api.import(__dirname + "/../../data/html.yml").compile(function(err, html) { | ||
api.morph("html").import(__dirname + "/../../data/html.yml").compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -34,0 +32,0 @@ expect(html).toBeDefined(); |
@@ -5,6 +5,4 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should compile an empty tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: {} | ||
@@ -20,3 +18,3 @@ }).compile(function(err, html) { | ||
it("should compile tag with text inside", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: "page text" | ||
@@ -32,3 +30,3 @@ }).compile(function(err, html) { | ||
it("should compile tag with attributes", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -46,3 +44,3 @@ _attrs: { class: "black" } | ||
it("should compile tag with attributes and text inside", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -61,3 +59,3 @@ _attrs: { class: "black" }, | ||
it("should compile tag with attributes, text inside and nested tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -77,3 +75,3 @@ _attrs: { class: "black" }, | ||
it("should compile raw content", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
_: '<html></html>' | ||
@@ -89,3 +87,3 @@ }).compile(function(err, html) { | ||
it("should compile nested tags", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
html: { | ||
@@ -106,3 +104,3 @@ head: { | ||
it("should compile raw content + nested tag", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
body: { | ||
@@ -109,0 +107,0 @@ p: { |
@@ -5,7 +5,5 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should use templates", function(done) { | ||
api.add({ | ||
api.morph("html").add({ | ||
title: "AbsurdJS preprocessor" | ||
@@ -12,0 +10,0 @@ }, "title"); |
@@ -5,4 +5,2 @@ describe("Metamorphosis (to html preprocessor)", function() { | ||
api.morph("html"); | ||
it("should use classes", function(done) { | ||
@@ -14,3 +12,3 @@ var tags = { | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -29,3 +27,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -44,3 +42,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -59,3 +57,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -74,3 +72,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -89,3 +87,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -105,3 +103,3 @@ expect(html).toBeDefined(); | ||
} | ||
api.add(tags).compile(function(err, html) { | ||
api.morph("html").add(tags).compile(function(err, html) { | ||
expect(err).toBe(null); | ||
@@ -108,0 +106,0 @@ expect(html).toBeDefined(); |
300456
7.09%142
2.9%9617
9.35%6
20%29
3.57%