Comparing version 0.2.0 to 0.2.1
@@ -15,4 +15,4 @@ var fs = require('fs'); | ||
} | ||
for(var i=0; i<iterations; i++) { | ||
result += results[i]; | ||
for(var j=0; j<iterations; j++) { | ||
result += results[j]; | ||
} | ||
@@ -19,0 +19,0 @@ console.log("Result: ", result / iterations, " (iterations: " + iterations + ")"); |
var api = require("../../index.js")(); | ||
api.plugin("hoverEffect", function(api, color) { | ||
return { | ||
":hover": { | ||
color: color, | ||
background: api.lighten(color, 60) | ||
} | ||
} | ||
}) | ||
module.exports = function() { | ||
@@ -10,3 +18,4 @@ api.add({ | ||
span: { | ||
fontSize: "20px" | ||
fontSize: "20px", | ||
hoverEffect: '#999' | ||
} | ||
@@ -20,3 +29,4 @@ } | ||
header: { | ||
marginTop: "20px" | ||
marginTop: "20px", | ||
hoverEffect: '#999' | ||
} | ||
@@ -23,0 +33,0 @@ }).compile(function(err, css) { |
@@ -95,10 +95,11 @@ /* version: 0.2.0 */ | ||
var __dirname = ""; | ||
var Observer = function() { | ||
var Observer = function(eventBus) { | ||
var listeners = []; | ||
return { | ||
on: function(eventName, callback) { | ||
listeners: listeners, | ||
on: function(eventName, callback, scope) { | ||
if(!listeners[eventName]) { | ||
listeners[eventName] = []; | ||
} | ||
listeners[eventName].push(callback); | ||
listeners[eventName].push({callback: callback, scope: scope}); | ||
return this; | ||
@@ -111,3 +112,3 @@ }, | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
if(listeners[eventName][i] !== handler) { | ||
if(listeners[eventName][i].callback !== handler) { | ||
newArr.push(listeners[eventName][i]); | ||
@@ -119,7 +120,12 @@ } | ||
}, | ||
dispatch: function(eventName, data) { | ||
dispatch: function(eventName, data, scope) { | ||
if(data && typeof data === 'object' && !(data instanceof Array)) { | ||
data.target = this; | ||
} else { | ||
data = { target: this }; | ||
} | ||
if(listeners[eventName]) { | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
var callback = listeners[eventName][i]; | ||
callback(data); | ||
var callback = listeners[eventName][i].callback; | ||
callback.apply(scope || listeners[eventName][i].scope || {}, [data]); | ||
} | ||
@@ -130,2 +136,3 @@ } | ||
} | ||
if(eventBus) eventBus.dispatch(eventName, data); | ||
return this; | ||
@@ -282,2 +289,3 @@ } | ||
var component = { | ||
name: name, | ||
populate: function(options) { | ||
@@ -297,2 +305,5 @@ queue([ | ||
}, | ||
el: function() { | ||
return HTMLElement; | ||
}, | ||
set: function(key, value) { | ||
@@ -304,2 +315,5 @@ storage[key] = value; | ||
return storage[key]; | ||
}, | ||
wire: function(event) { | ||
absurd.components.events.on(event, this[event] || function() {}, this); | ||
} | ||
@@ -309,7 +323,28 @@ } | ||
} | ||
var component = function(api) { | ||
return function(name, cls) { | ||
if(typeof cls == 'undefined') { | ||
return api.components.get(name); | ||
} else { | ||
return api.components.register(name, cls); | ||
} | ||
} | ||
} | ||
var components = function(absurd) { | ||
var api = {}, comps = {}, extend = lib.helpers.Extend; | ||
var extend = lib.helpers.Extend, | ||
api = {}, | ||
comps = {}, | ||
instances = []; | ||
api.events = extend({}, Observer()); | ||
api.register = function(name, cls) { | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
return comps[name] = function() { | ||
var c = extend({}, Observer(api.events), Component(name, absurd), cls); | ||
instances.push(c); | ||
if(typeof c.constructor === 'function') { | ||
c.constructor.apply(c, Array.prototype.slice.call(arguments, 0)); | ||
} | ||
return c; | ||
}; | ||
} | ||
@@ -331,7 +366,10 @@ api.get = function(name) { | ||
comps = {}; | ||
instances = []; | ||
return api; | ||
} | ||
api.broadcast = function(event) { | ||
for(var name in comps) { | ||
comps[name].dispatch(event); | ||
api.broadcast = function(event, data) { | ||
for(var i=0; i<instances.length, instance=instances[i]; i++) { | ||
if(typeof instance[event] === 'function') { | ||
instance[event](data); | ||
} | ||
} | ||
@@ -414,2 +452,3 @@ return api; | ||
_api.components = components(_api); | ||
_api.component = component(_api); | ||
@@ -884,10 +923,6 @@ /******************************************* Copied directly from /lib/API.js */ | ||
for(var i=0; c=prop.charAt(i); i++) { | ||
if(options && options.keepCamelCase === true) { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} else { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} | ||
} | ||
@@ -1005,3 +1040,7 @@ } | ||
} | ||
entity += ' ' + transformUppercase(prop, options) + ': ' + value + ';' + newline; | ||
if(options && options.keepCamelCase === true) { | ||
entity += ' ' + prop + ': ' + value + ';' + newline; | ||
} else { | ||
entity += ' ' + transformUppercase(prop) + ': ' + value + ';' + newline; | ||
} | ||
} | ||
@@ -1015,22 +1054,2 @@ entity += '}' + newline; | ||
// dealing with false values | ||
var filterRules = function(rules) { | ||
var arr = {}; | ||
for(var selector in rules) { | ||
var areThereAnyProps = false; | ||
var props = {}; | ||
for(var prop in rules[selector]) { | ||
var value = rules[selector][prop]; | ||
if(value !== false && typeof value != 'object') { | ||
areThereAnyProps = true; | ||
props[prop] = value; | ||
} | ||
} | ||
if(areThereAnyProps) { | ||
arr[selector] = props; | ||
} | ||
} | ||
return arr; | ||
} | ||
// combining selectors | ||
@@ -1080,3 +1099,3 @@ var combineSelectors = function(rules) { | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
var r = rules[stylesheet]; | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
@@ -1236,3 +1255,3 @@ if(stylesheet === "mainstream") { | ||
beautifyHTML = require('js-beautify').html, | ||
transformUppercase = require("../../helpers/TransformUppercase"), | ||
tu = require("../../helpers/TransformUppercase"), | ||
passedOptions = {}; | ||
@@ -1252,2 +1271,9 @@ | ||
} | ||
var prepareProperty = function(prop, options) { | ||
if(options && options.keepCamelCase === true) { | ||
return prop; | ||
} else { | ||
return tu(prop, options); | ||
} | ||
} | ||
var process = function(tagName, obj) { | ||
@@ -1280,12 +1306,10 @@ // console.log("------------------------\n", tagName, ">", obj); | ||
if(typeof value[attrName] === "function") { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
} else { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
} | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
case "_": | ||
addToChilds(value); | ||
obj[directiveName] = false; | ||
break; | ||
@@ -1303,3 +1327,2 @@ case "_tpl": | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
@@ -1321,27 +1344,21 @@ case "_include": | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(value !== false) { | ||
var name = prop; | ||
switch(typeof value) { | ||
case "string": addToChilds(process(name, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
default: | ||
switch(typeof value) { | ||
case "string": addToChilds(process(directiveName, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
} | ||
addToChilds(process(directiveName, tmp)); | ||
} else { | ||
addToChilds(process(directiveName, value)); | ||
} | ||
addToChilds(process(name, tmp)); | ||
} else { | ||
addToChilds(process(name, value)); | ||
} | ||
break; | ||
case "function": addToChilds(process(name, value())); break; | ||
} | ||
break; | ||
case "function": addToChilds(process(directiveName, value())); break; | ||
} | ||
break; | ||
} | ||
@@ -1365,5 +1382,5 @@ } | ||
if(childs !== '') { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + transformUppercase(tagName, passedOptions) + '>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + prepareProperty(tagName, passedOptions) + '>'; | ||
} else { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '/>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '/>'; | ||
} | ||
@@ -1403,3 +1420,10 @@ return html; | ||
for(var i=0; c=prop[i]; i++) { | ||
if(/(#|\.|\[|\])/gi.test(prop) === false) { | ||
return { | ||
tag: prop, | ||
attrs: '' | ||
}; | ||
} | ||
for(var i=0; i<prop.length, c=prop[i]; i++) { | ||
if(c === "[" && !readingAttributes) { | ||
@@ -1406,0 +1430,0 @@ readingAttributes = true; |
@@ -1,1 +0,1 @@ | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}},ki:{}},b=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},d=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},e=function(a){var b=document.createElement("div");return b.innerHTML=a,b.childNodes[0]},f=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},g=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType?f.test(b.nodeValue)&&(a.removeChild(b),e--,d--):1==b.nodeType&&g(b);return a},h=function(b){return b.indexOf("css/CSS.js")>0?a.processors.css.CSS:b.indexOf("html/HTML.js")>0?a.processors.html.HTML:b.indexOf("component/Component.js")>0?a.processors.component.Component:"js-beautify"==b?{html:function(a){return a}}:"./helpers/PropAnalyzer"==b?a.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==b?a.helpers.TransformUppercase:"./helpers/TemplateEngine"==b?a.processors.html.helpers.TemplateEngine:"../helpers/Extend"==b?a.helpers.Extend:"../helpers/Clone"==b?a.helpers.Clone:function(){}},i="",j=function(){var a=[];return{on:function(b,c){return a[b]||(a[b]=[]),a[b].push(c),this},off:function(b,c){return a[b]?(c||(a[b]=[]),this):this},dispatch:function(b,c){if(a[b])for(var d=0;d<a[b].length;d++){var e=a[b][d];e(c)}return this[b]&&"function"==typeof this[b]&&this[b](c),this}}},k=function(c,h){var i=!1,j=!1,k=!1,l=a.helpers.Extend,m={},n=!1,o={events:{}},p=function(a){this.css?h.flush().add(this.css).compile(function(b,e){if(i)i.raw!==e&&(i.raw=e,i.element.innerHTML=e);else{var f=document.createElement("style");f.setAttribute("id",c+"-css"),f.setAttribute("type","text/css"),f.innerHTML=e,(d("head")||d("body"))[0].appendChild(f),i={raw:e,element:f}}a()}):a()},q=function(a){if(this.html)if("string"==typeof this.html){if(k===!1){var b=d(this.html);b.length>0&&(k=b[0]),j={"":k.outerHTML.replace(/</g,"<").replace(/>/g,">")}}a()}else"object"==typeof this.html?(j=l({},this.html),k===!1?h.flush().morph("html").add(j).compile(function(b,c){k=e(c),a()},this):a()):a();else a()},r=function(a){j?h.flush().morph("html").add(j).compile(function(b,c){!function d(b,c){if("undefined"!=typeof b&&"undefined"!=typeof c&&!b.isEqualNode(c)){if(b.nodeName!==c.nodeName)return b.parentNode&&b.parentNode.replaceChild(c,b),a(),void 0;if(b.nodeValue!==c.nodeValue&&(b.nodeValue=c.nodeValue),b.attributes){for(var e,f,g=b.attributes,h=c.attributes,i={},j=0;j<g.length,e=g[j];j++){for(var k=0;k<h.length,f=h[k];k++)e.name===f.name&&(b.setAttribute(e.name,f.value),i[e.name]=!0);i[e.name]||b.removeAttribute(e.name)}for(var j=0;j<h.length,f=h[j];j++)i[f.name]||b.setAttribute(f.name,f.value)}if(b.childNodes.length>=c.childNodes.length)for(var j=0;j<b.childNodes.length;j++)c.childNodes[j]||c.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j]);else for(var j=0;j<c.childNodes.length;j++)b.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j])}}(g(k),g(e(c))),a()},this):a()},s=function(a){!n&&k&&this.get("parent")&&(n=!0,this.get("parent").appendChild(k)),a()},t=function(a){if(k){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!o.events[c[0]]||o.events[c[0]].indexOf(a)<0)&&(o.events[c[0]]||(o.events[c[0]]=[]),o.events[c[0]].push(a),f(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};k.hasAttribute("data-absurd-event")&&c(k);for(var d=k.querySelectorAll?k.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()},u={populate:function(a){b([p,q,r,s,t,function(){var b={css:i,html:{element:k}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this)},set:function(a,b){return m[a]=b,this},get:function(a){return m[a]}};return u},l=function(b){var c={},d={},e=a.helpers.Extend;return c.register=function(a,c){return d[a]=e({},j(),k(a,b),c)},c.get=function(a){if(d[a])return d[a];throw new Error("There is no component with name '"+a+"'.")},c.remove=function(a){return d[a]?(delete d[a],!0):!1},c.list=function(){var a=[];for(var b in d)a.push(b);return a},c.flush=function(){return d={},c},c.broadcast=function(a){for(var b in d)d[b].dispatch(a);return c},c},m=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.components=l(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};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=(h("../helpers/Extend"),h("../helpers/Clone"),[]),c=function(b,c,e,f,g){var h=a.getPlugins()[c];if("undefined"!=typeof h){var i=h(a,e);return i&&d(b,i,f,g),!0}return!1},d=function(a,e,f,g){if(f=f||"mainstream",/, ?/g.test(a))for(var h=a.replace(/, /g,",").split(","),i=0;i<h.length,p=h[i];i++)d(p,e,f,g);else if("undefined"==typeof e.length||"object"!=typeof e){if(!c(null,a,e,f,g)){var j={},k=a,l={},m={};for(var n in e){var o=typeof e[n];"object"!==o&&"function"!==o?c(a,n,e[n],f,g)===!1&&(k="undefined"!=typeof g?g+" "+a:a,j[n]=e[n]):"object"===o?l[n]=e[n]:"function"===o&&(m[n]=e[n])}b.push({selector:k,props:j,stylesheet:f});for(var n in l)":"===n.charAt(0)?d(a+n,l[n],f,g):/&/g.test(n)?d(n.replace(/&/g,a),l[n],f,g):0===n.indexOf("@media")||0===n.indexOf("@supports")?d(a,l[n],n,g):0===a.indexOf("@media")||0===n.indexOf("@supports")?d(n,l[n],a,g):c(a,n,l[n],f,g)===!1&&d(n,l[n],f,(g?g+" ":"")+a);for(var n in m){var q={};q[n]=m[n](),d(a,q,f,g)}}}else for(var i=0;i<e.length,n=e[i];i++)d(a,n,f,g)},e=function(c,e){b=[],a.numOfAddedRules+=1;for(var f in c)d(f,c[f],e||"mainstream");for(var g=0;g<b.length;g++){var e=b[g].stylesheet,f=b[g].selector,h=b[g].props,i=a.getRules(e);if("object"==typeof i[f]){var j=i[f];for(var k in h)"object"!=typeof h[k]&&(j[k]=h[k])}else i[f]=h}return a};return e};var n=h("../helpers/Extend");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 f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=n(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{s.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var q=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 q(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var q=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 q(a,b/100)}};var r={html:function(a){a.defaultProcessor=h(i+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=h(i+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};a.api.morph=function(a){return function(b){return r[b]&&(a.flush(),r[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}};{var s=h("fs");h("path")}a.api.rawImport=function(a){var b=function(b){var c=s.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return 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.Clone=function J(a){function b(a,b,c){var d,e,f={};for(d in b)e=b[d],d in a&&(a[d]===e||d in f&&f[d]===e)||(a[d]=c?c(e):e);return a}if(!a||"object"!=typeof a||"[object Function]"===Object.prototype.toString.call(a))return a;if(a.nodeType&&"cloneNode"in a)return a.cloneNode(!0);if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return new RegExp(a);var c,d,e;if(a instanceof Array)for(c=[],d=0,e=a.length;e>d;++d)d in a&&c.push(J(a[d]));else c=a.constructor?new a.constructor:{};return b(c,a,J)},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.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b},a.helpers.RequireUncached=function(a){return delete h.cache[h.resolve(a)],h(a)},a.helpers.TransformUppercase=function(a,b){for(var d="",e=0;c=a.charAt(e);e++)d+=b&&b.keepCamelCase===!0?c:c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return d};var t=function(a,b,d){var e="",f="",g=[],j=d.api;cssPreprocessor=h(i+"/../css/CSS.js")(),htmlPreprocessor=h(i+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<g.length,component=g[b];b++)"function"==typeof component&&(component=component()),j.add(component.css?component.css:{});cssPreprocessor(j.getRules(),function(b,c){e+=c,a(b)},d)},l=function(b){var c=0,e=null,g=function(){if(c>a.length-1)return b(e),void 0;var h=a[c];"function"==typeof h&&(h=h()),j.morph("html").add(h.html?h.html:{}),htmlPreprocessor(j.getRules(),function(a,b){f+=b,c+=1,e=a,g()},d)};g()},m=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()),g.push(c),m(c);else"function"==typeof a[b]&&(a[b]=a[b]()),g.push(a[b]),m(a[b]);else"object"==typeof a[b]&&m(a[b])},n=0;n<a.length,c=a[n];n++)"function"==typeof c&&(c=c()),g.push(c),m(c);j.flush(),k(function(a){j.morph("html"),l(function(c){b(a||c?{error:{css:a,html:c}}:null,e,f)})})};a.processors.component.Component=function(){var a=function(a,b,c){t(a.mainstream,b,c)};return a.type="component",a};var u="\n",w={combineSelectors:!0,minify:!1,keepCamelCase:!1},x=h("../../helpers/TransformUppercase"),y=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+u;else{var e=d+" {"+u;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=" "+x(f,b)+": "+g+";"+u}e+="}"+u,c+=e}return c},z=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&&"object"!=typeof g&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},A=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},B=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")};a.processors.css.CSS=function(){var a=function(a,b,c){c=c||w;var d="";for(var e in a){var f=z(a[e]);f=c.combineSelectors?A(f):f,d+="mainstream"===e?y(f,c):e+" {"+u+y(f,c)+"}"+u}return c.minify?(d=B(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},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,b){var c=h(i+"/../CSS.js")();if("object"==typeof b)if("undefined"!=typeof b.frames){var d="@keyframes "+b.name+" {\n";d+=c({mainstream:b.frames}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var d="@keyframes "+b.name+" {\n",e={},f=0;rule=b.keyframes[f];f++)if("keyframe"===rule.type)for(var g=e[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value);d+=c({mainstream:e}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@media "+b.media+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}},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,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@supports "+b.supports+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}};var C=null,u="\n",w={},D=h("js-beautify").html,x=h("../../helpers/TransformUppercase"),E={},F=function(a){var b="";for(var c in C)if(c==a)for(var d=C[c].length,e=0;d>e;e++)b+=G("",C[c][e]);return b},G=function(a,b){var c="",d="",e="",f=h("./helpers/PropAnalyzer")(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return H(a,d,b);var g=function(a){""!=e&&(e+=u),e+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)d+="function"==typeof j[k]?" "+x(k,E)+'="'+j[k]()+'"':" "+x(k,E)+'="'+j[k]+'"';b[i]=!1;break;case"_":g(j),b[i]=!1;break;case"_tpl":if("string"==typeof j)g(F(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=F(tpl),m<j.length-1&&(l+=u);g(l)}b[i]=!1;break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=G("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);g(l),b[i]=!1}}for(var p in b){var j=b[p];if(j!==!1){var q=p;switch(typeof j){case"string":g(G(q,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=G("","function"==typeof v?v():v),m<j.length-1&&(l+=u);g(G(q,l))}else g(G(q,j));break;case"function":g(G(q,j()))}}}return c+=""!=a?H(a,d,e):e},H=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+x(a,E)+b+">"+u+c+u+"</"+x(a,E)+">":"<"+x(a,E)+b+"/>")},I=function(a){return a=h("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),E),E.minify?a:D(a,{indent_size:E.indentSize||4})};return a.processors.html.HTML=function(){var a=function(a,b,c){C=a,b=b||function(){},c=E=c||w;var d=I(F("mainstream"));return b(null,d),d};return a.type="html",a},a.processors.html.helpers.PropAnalyzer=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},a.processors.html.helpers.TemplateEngine=function(a,b){for(var c=/<%(.+?)%>/g,d=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,e="var r=[];\n",f=0,g=function(a,b){return e+=b?a.match(d)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",g};match=c.exec(a);)g(a.slice(f,match.index))(match[1],!0),f=match.index+match[0].length;return g(a.substr(f,a.length-f)),e+='return r.join("");',new Function(e.replace(/[\r\t\n]/g,"")).apply(b)},m()}(window); | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}},ki:{}},b=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},d=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},e=function(a){var b=document.createElement("div");return b.innerHTML=a,b.childNodes[0]},f=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},g=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType?f.test(b.nodeValue)&&(a.removeChild(b),e--,d--):1==b.nodeType&&g(b);return a},h=function(b){return b.indexOf("css/CSS.js")>0?a.processors.css.CSS:b.indexOf("html/HTML.js")>0?a.processors.html.HTML:b.indexOf("component/Component.js")>0?a.processors.component.Component:"js-beautify"==b?{html:function(a){return a}}:"./helpers/PropAnalyzer"==b?a.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==b?a.helpers.TransformUppercase:"./helpers/TemplateEngine"==b?a.processors.html.helpers.TemplateEngine:"../helpers/Extend"==b?a.helpers.Extend:"../helpers/Clone"==b?a.helpers.Clone:function(){}},i="",j=function(a){var b=[];return{listeners:b,on:function(a,c,d){return b[a]||(b[a]=[]),b[a].push({callback:c,scope:d}),this},off:function(a,c){return b[a]?(c||(b[a]=[]),this):this},dispatch:function(c,d,e){if(!d||"object"!=typeof d||d instanceof Array?d={target:this}:d.target=this,b[c])for(var f=0;f<b[c].length;f++){var g=b[c][f].callback;g.apply(e||b[c][f].scope||{},[d])}return this[c]&&"function"==typeof this[c]&&this[c](d),a&&a.dispatch(c,d),this}}},k=function(c,h){var i=!1,j=!1,k=!1,l=a.helpers.Extend,m={},n=!1,o={events:{}},p=function(a){this.css?h.flush().add(this.css).compile(function(b,e){if(i)i.raw!==e&&(i.raw=e,i.element.innerHTML=e);else{var f=document.createElement("style");f.setAttribute("id",c+"-css"),f.setAttribute("type","text/css"),f.innerHTML=e,(d("head")||d("body"))[0].appendChild(f),i={raw:e,element:f}}a()}):a()},q=function(a){if(this.html)if("string"==typeof this.html){if(k===!1){var b=d(this.html);b.length>0&&(k=b[0]),j={"":k.outerHTML.replace(/</g,"<").replace(/>/g,">")}}a()}else"object"==typeof this.html?(j=l({},this.html),k===!1?h.flush().morph("html").add(j).compile(function(b,c){k=e(c),a()},this):a()):a();else a()},r=function(a){j?h.flush().morph("html").add(j).compile(function(b,c){!function d(b,c){if("undefined"!=typeof b&&"undefined"!=typeof c&&!b.isEqualNode(c)){if(b.nodeName!==c.nodeName)return b.parentNode&&b.parentNode.replaceChild(c,b),a(),void 0;if(b.nodeValue!==c.nodeValue&&(b.nodeValue=c.nodeValue),b.attributes){for(var e,f,g=b.attributes,h=c.attributes,i={},j=0;j<g.length,e=g[j];j++){for(var k=0;k<h.length,f=h[k];k++)e.name===f.name&&(b.setAttribute(e.name,f.value),i[e.name]=!0);i[e.name]||b.removeAttribute(e.name)}for(var j=0;j<h.length,f=h[j];j++)i[f.name]||b.setAttribute(f.name,f.value)}if(b.childNodes.length>=c.childNodes.length)for(var j=0;j<b.childNodes.length;j++)c.childNodes[j]||c.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j]);else for(var j=0;j<c.childNodes.length;j++)b.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j])}}(g(k),g(e(c))),a()},this):a()},s=function(a){!n&&k&&this.get("parent")&&(n=!0,this.get("parent").appendChild(k)),a()},t=function(a){if(k){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!o.events[c[0]]||o.events[c[0]].indexOf(a)<0)&&(o.events[c[0]]||(o.events[c[0]]=[]),o.events[c[0]].push(a),f(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};k.hasAttribute("data-absurd-event")&&c(k);for(var d=k.querySelectorAll?k.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()},u={name:c,populate:function(a){b([p,q,r,s,t,function(){var b={css:i,html:{element:k}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this)},el:function(){return k},set:function(a,b){return m[a]=b,this},get:function(a){return m[a]},wire:function(a){h.components.events.on(a,this[a]||function(){},this)}};return u},l=function(a){return function(b,c){return"undefined"==typeof c?a.components.get(b):a.components.register(b,c)}},m=function(b){var c=a.helpers.Extend,d={},e={},f=[];return d.events=c({},j()),d.register=function(a,g){return e[a]=function(){var e=c({},j(d.events),k(a,b),g);return f.push(e),"function"==typeof e.constructor&&e.constructor.apply(e,Array.prototype.slice.call(arguments,0)),e}},d.get=function(a){if(e[a])return e[a];throw new Error("There is no component with name '"+a+"'.")},d.remove=function(a){return e[a]?(delete e[a],!0):!1},d.list=function(){var a=[];for(var b in e)a.push(b);return a},d.flush=function(){return e={},f=[],d},d.broadcast=function(a,b){for(var c=0;c<f.length,instance=f[c];c++)"function"==typeof instance[a]&&instance[a](b);return d},d},n=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.components=m(e),e.component=l(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};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=(h("../helpers/Extend"),h("../helpers/Clone"),[]),c=function(b,c,e,f,g){var h=a.getPlugins()[c];if("undefined"!=typeof h){var i=h(a,e);return i&&d(b,i,f,g),!0}return!1},d=function(a,e,f,g){if(f=f||"mainstream",/, ?/g.test(a))for(var h=a.replace(/, /g,",").split(","),i=0;i<h.length,p=h[i];i++)d(p,e,f,g);else if("undefined"==typeof e.length||"object"!=typeof e){if(!c(null,a,e,f,g)){var j={},k=a,l={},m={};for(var n in e){var o=typeof e[n];"object"!==o&&"function"!==o?c(a,n,e[n],f,g)===!1&&(k="undefined"!=typeof g?g+" "+a:a,j[n]=e[n]):"object"===o?l[n]=e[n]:"function"===o&&(m[n]=e[n])}b.push({selector:k,props:j,stylesheet:f});for(var n in l)":"===n.charAt(0)?d(a+n,l[n],f,g):/&/g.test(n)?d(n.replace(/&/g,a),l[n],f,g):0===n.indexOf("@media")||0===n.indexOf("@supports")?d(a,l[n],n,g):0===a.indexOf("@media")||0===n.indexOf("@supports")?d(n,l[n],a,g):c(a,n,l[n],f,g)===!1&&d(n,l[n],f,(g?g+" ":"")+a);for(var n in m){var q={};q[n]=m[n](),d(a,q,f,g)}}}else for(var i=0;i<e.length,n=e[i];i++)d(a,n,f,g)},e=function(c,e){b=[],a.numOfAddedRules+=1;for(var f in c)d(f,c[f],e||"mainstream");for(var g=0;g<b.length;g++){var e=b[g].stylesheet,f=b[g].selector,h=b[g].props,i=a.getRules(e);if("object"==typeof i[f]){var j=i[f];for(var k in h)"object"!=typeof h[k]&&(j[k]=h[k])}else i[f]=h}return a};return e};var q=h("../helpers/Extend");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 f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=q(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{t.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var r=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 r(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var r=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 r(a,b/100)}};var s={html:function(a){a.defaultProcessor=h(i+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=h(i+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};a.api.morph=function(a){return function(b){return s[b]&&(a.flush(),s[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}};{var t=h("fs");h("path")}a.api.rawImport=function(a){var b=function(b){var c=t.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return 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.Clone=function L(a){function b(a,b,c){var d,e,f={};for(d in b)e=b[d],d in a&&(a[d]===e||d in f&&f[d]===e)||(a[d]=c?c(e):e);return a}if(!a||"object"!=typeof a||"[object Function]"===Object.prototype.toString.call(a))return a;if(a.nodeType&&"cloneNode"in a)return a.cloneNode(!0);if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return new RegExp(a);var c,d,e;if(a instanceof Array)for(c=[],d=0,e=a.length;e>d;++d)d in a&&c.push(L(a[d]));else c=a.constructor?new a.constructor:{};return b(c,a,L)},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.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b},a.helpers.RequireUncached=function(a){return delete h.cache[h.resolve(a)],h(a)},a.helpers.TransformUppercase=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};var u=function(a,b,d){var e="",f="",g=[],j=d.api;cssPreprocessor=h(i+"/../css/CSS.js")(),htmlPreprocessor=h(i+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<g.length,l=g[b];b++)"function"==typeof l&&(l=l()),j.add(l.css?l.css:{});cssPreprocessor(j.getRules(),function(b,c){e+=c,a(b)},d)},m=function(b){var c=0,e=null,g=function(){if(c>a.length-1)return b(e),void 0;var h=a[c];"function"==typeof h&&(h=h()),j.morph("html").add(h.html?h.html:{}),htmlPreprocessor(j.getRules(),function(a,b){f+=b,c+=1,e=a,g()},d)};g()},n=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()),g.push(c),n(c);else"function"==typeof a[b]&&(a[b]=a[b]()),g.push(a[b]),n(a[b]);else"object"==typeof a[b]&&n(a[b])},o=0;o<a.length,c=a[o];o++)"function"==typeof c&&(c=c()),g.push(c),n(c);j.flush(),k(function(a){j.morph("html"),m(function(c){b(a||c?{error:{css:a,html:c}}:null,e,f)})})};a.processors.component.Component=function(){var a=function(a,b,c){u(a.mainstream,b,c)};return a.type="component",a};var w="\n",x={combineSelectors:!0,minify:!1,keepCamelCase:!1},y=h("../../helpers/TransformUppercase"),z=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+w;else{var e=d+" {"+w;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=b&&b.keepCamelCase===!0?" "+f+": "+g+";"+w:" "+y(f)+": "+g+";"+w}e+="}"+w,c+=e}return c},A=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},B=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")};a.processors.css.CSS=function(){var a=function(a,b,c){c=c||x;var d="";for(var e in a){var f=a[e];f=c.combineSelectors?A(f):f,d+="mainstream"===e?z(f,c):e+" {"+w+z(f,c)+"}"+w}return c.minify?(d=B(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},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,b){var c=h(i+"/../CSS.js")();if("object"==typeof b)if("undefined"!=typeof b.frames){var d="@keyframes "+b.name+" {\n";d+=c({mainstream:b.frames}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var d="@keyframes "+b.name+" {\n",e={},f=0;rule=b.keyframes[f];f++)if("keyframe"===rule.type)for(var g=e[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value);d+=c({mainstream:e}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@media "+b.media+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}},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,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@supports "+b.supports+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}};var C=null,w="\n",x={},D=h("js-beautify").html,E=h("../../helpers/TransformUppercase"),F={},G=function(a){var b="";for(var c in C)if(c==a)for(var d=C[c].length,e=0;d>e;e++)b+=I("",C[c][e]);return b},H=function(a,b){return b&&b.keepCamelCase===!0?a:E(a,b)},I=function(a,b){var c="",d="",e="",f=h("./helpers/PropAnalyzer")(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return J(a,d,b);var g=function(a){""!=e&&(e+=w),e+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)d+="function"==typeof j[k]?" "+H(k,F)+'="'+j[k]()+'"':" "+H(k,F)+'="'+j[k]+'"';break;case"_":g(j);break;case"_tpl":if("string"==typeof j)g(G(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=G(tpl),m<j.length-1&&(l+=w);g(l)}break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=I("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);g(l);break;default:switch(typeof j){case"string":g(I(i,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=I("","function"==typeof v?v():v),m<j.length-1&&(l+=w);g(I(i,l))}else g(I(i,j));break;case"function":g(I(i,j()))}}}return c+=""!=a?J(a,d,e):e},J=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+H(a,F)+b+">"+w+c+w+"</"+H(a,F)+">":"<"+H(a,F)+b+"/>")},K=function(a){return a=h("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),F),F.minify?a:D(a,{indent_size:F.indentSize||4})};return a.processors.html.HTML=function(){var a=function(a,b,c){C=a,b=b||function(){},c=F=c||x;var d=K(G("mainstream"));return b(null,d),d};return a.type="html",a},a.processors.html.helpers.PropAnalyzer=function(a){var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1;if(/(#|\.|\[|\])/gi.test(a)===!1)return{tag:a,attrs:""};for(var k=0;k<a.length,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},a.processors.html.helpers.TemplateEngine=function(a,b){for(var c=/<%(.+?)%>/g,d=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,e="var r=[];\n",f=0,g=function(a,b){return e+=b?a.match(d)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",g};match=c.exec(a);)g(a.slice(f,match.index))(match[1],!0),f=match.index+match[0].length;return g(a.substr(f,a.length-f)),e+='return r.join("");',new Function(e.replace(/[\r\t\n]/g,"")).apply(b)},n()}(window); |
@@ -1,9 +0,10 @@ | ||
var Observer = function() { | ||
var Observer = function(eventBus) { | ||
var listeners = []; | ||
return { | ||
on: function(eventName, callback) { | ||
listeners: listeners, | ||
on: function(eventName, callback, scope) { | ||
if(!listeners[eventName]) { | ||
listeners[eventName] = []; | ||
} | ||
listeners[eventName].push(callback); | ||
listeners[eventName].push({callback: callback, scope: scope}); | ||
return this; | ||
@@ -16,3 +17,3 @@ }, | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
if(listeners[eventName][i] !== handler) { | ||
if(listeners[eventName][i].callback !== handler) { | ||
newArr.push(listeners[eventName][i]); | ||
@@ -24,7 +25,12 @@ } | ||
}, | ||
dispatch: function(eventName, data) { | ||
dispatch: function(eventName, data, scope) { | ||
if(data && typeof data === 'object' && !(data instanceof Array)) { | ||
data.target = this; | ||
} else { | ||
data = { target: this }; | ||
} | ||
if(listeners[eventName]) { | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
var callback = listeners[eventName][i]; | ||
callback(data); | ||
var callback = listeners[eventName][i].callback; | ||
callback.apply(scope || listeners[eventName][i].scope || {}, [data]); | ||
} | ||
@@ -35,2 +41,3 @@ } | ||
} | ||
if(eventBus) eventBus.dispatch(eventName, data); | ||
return this; | ||
@@ -37,0 +44,0 @@ } |
@@ -148,2 +148,3 @@ var Component = function(name, absurd) { | ||
var component = { | ||
name: name, | ||
populate: function(options) { | ||
@@ -163,2 +164,5 @@ queue([ | ||
}, | ||
el: function() { | ||
return HTMLElement; | ||
}, | ||
set: function(key, value) { | ||
@@ -170,2 +174,5 @@ storage[key] = value; | ||
return storage[key]; | ||
}, | ||
wire: function(event) { | ||
absurd.components.events.on(event, this[event] || function() {}, this); | ||
} | ||
@@ -172,0 +179,0 @@ } |
@@ -0,6 +1,27 @@ | ||
var component = function(api) { | ||
return function(name, cls) { | ||
if(typeof cls == 'undefined') { | ||
return api.components.get(name); | ||
} else { | ||
return api.components.register(name, cls); | ||
} | ||
} | ||
} | ||
var components = function(absurd) { | ||
var api = {}, comps = {}, extend = lib.helpers.Extend; | ||
var extend = lib.helpers.Extend, | ||
api = {}, | ||
comps = {}, | ||
instances = []; | ||
api.events = extend({}, Observer()); | ||
api.register = function(name, cls) { | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
return comps[name] = function() { | ||
var c = extend({}, Observer(api.events), Component(name, absurd), cls); | ||
instances.push(c); | ||
if(typeof c.constructor === 'function') { | ||
c.constructor.apply(c, Array.prototype.slice.call(arguments, 0)); | ||
} | ||
return c; | ||
}; | ||
} | ||
@@ -22,7 +43,10 @@ api.get = function(name) { | ||
comps = {}; | ||
instances = []; | ||
return api; | ||
} | ||
api.broadcast = function(event) { | ||
for(var name in comps) { | ||
comps[name].dispatch(event); | ||
api.broadcast = function(event, data) { | ||
for(var i=0; i<instances.length, instance=instances[i]; i++) { | ||
if(typeof instance[event] === 'function') { | ||
instance[event](data); | ||
} | ||
} | ||
@@ -29,0 +53,0 @@ return api; |
@@ -72,2 +72,3 @@ var client = function() { | ||
_api.components = components(_api); | ||
_api.component = component(_api); | ||
@@ -74,0 +75,0 @@ /******************************************* Copied directly from /lib/API.js */ |
@@ -5,2 +5,3 @@ describe("Testing components", function() { | ||
expect(absurd.components).toBeDefined(); | ||
expect(absurd.component).toBeDefined(); | ||
done(); | ||
@@ -10,7 +11,8 @@ }); | ||
it("should register a component and the answer is 42", function(done) { | ||
var widget = absurd.components.register("widget", { | ||
var widget = absurd.component("widget", { | ||
customMethod: function() { | ||
return "custom method"; | ||
} | ||
}).on("custom-event", function(data) { | ||
})(); | ||
widget.on("custom-event", function(data) { | ||
expect(data.prop).toBe(42); | ||
@@ -20,3 +22,3 @@ done(); | ||
expect(widget.customMethod()).toBe("custom method"); | ||
absurd.components.get("widget").dispatch("custom-event", {prop: 42}); | ||
widget.dispatch("custom-event", {prop: 42}); | ||
}); | ||
@@ -33,13 +35,15 @@ | ||
it("should register two components and broadcast a message", function(done) { | ||
var c =0, count = function() { | ||
c += 1; | ||
if(c == 2) done(); | ||
} | ||
absurd.components.flush(); | ||
absurd.components.register("c1", { omg: function() { count(); } }); | ||
absurd.components.register("c2", { omg: function() { count(); } }); | ||
absurd.components.broadcast("omg"); | ||
it("should create a component and call its constructor", function(done) { | ||
var Component = absurd.component("ComponentCreation", { | ||
constructor: function(a, b, c) { | ||
expect(this.name).toBe("ComponentCreation"); | ||
expect(a).toBe(10); | ||
expect(b).toBe(20); | ||
expect(c).toBe(30); | ||
done(); | ||
} | ||
}) | ||
Component(10, 20, 30); | ||
}); | ||
}); |
@@ -17,3 +17,3 @@ describe("Testing components (CSS compilation)", function() { | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
@@ -42,5 +42,5 @@ | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
}); |
@@ -13,3 +13,3 @@ describe("Testing components (HTML compilation)", function() { | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
@@ -32,3 +32,3 @@ | ||
} | ||
}).set("parent", document.querySelector("body")).populate(); | ||
})().set("parent", document.querySelector("body")).populate(); | ||
}); | ||
@@ -53,3 +53,3 @@ | ||
] | ||
}).on("populated", function(data) { | ||
})().on("populated", function(data) { | ||
expect(data.html.element.outerHTML).toBe('<ul class="class-B"><li><a href="http://google.com">Google</a></li><li><a href="http://yahoo.com">Yahoo</a></li></ul>'); | ||
@@ -89,3 +89,3 @@ done(); | ||
} | ||
}).set("parent", document.querySelector("body")).populate(); | ||
})().set("parent", document.querySelector("body")).populate(); | ||
}); | ||
@@ -123,3 +123,3 @@ | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
@@ -153,3 +153,3 @@ | ||
} | ||
}).populate() | ||
})().populate() | ||
}); | ||
@@ -171,3 +171,3 @@ | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
@@ -193,5 +193,35 @@ | ||
} | ||
}).populate(); | ||
})().populate(); | ||
}); | ||
it("should remove dom elements", function(done) { | ||
absurd.components.register("RemoveDomElements", { | ||
links: [ | ||
{ label: "A" }, | ||
{ label: "B" }, | ||
{ label: "C" } | ||
], | ||
html: { | ||
nav: [ | ||
'<% for(var i=0; i<this.links.length; i++) { %>', | ||
'<a href="#"><% this.links[i].label %></a>', | ||
'<% } %>' | ||
] | ||
}, | ||
populated: function(data) { | ||
if(!this.tested) { | ||
this.tested = true; | ||
this.links = [ | ||
{ label: "A" }, | ||
{ label: "C" } | ||
] | ||
this.populate(); | ||
} else { | ||
expect(this.el().outerHTML).toBe('<nav><a href="#">A</a><a href="#">C</a></nav>'); | ||
done(); | ||
} | ||
} | ||
})().populate(); | ||
}); | ||
}); |
@@ -31,5 +31,5 @@ describe("Testing components in complex scenarios", function() { | ||
} | ||
}).set("parent", document.querySelector("body")).populate(); | ||
})().set("parent", document.querySelector("body")).populate(); | ||
}); | ||
}); |
@@ -34,5 +34,33 @@ describe("Testing components events", function() { | ||
} | ||
}).set("parent", document.querySelector("body")).populate(); | ||
})().set("parent", document.querySelector("body")).populate(); | ||
}); | ||
it("should register two components and broadcast a message", function(done) { | ||
var c =0, count = function() { | ||
c += 1; | ||
if(c == 2) done(); | ||
} | ||
absurd.components.flush(); | ||
absurd.components.register("c1", { omg: function() { count(); } })(); | ||
absurd.components.register("c2", { omg: function() { count(); } })(); | ||
absurd.components.broadcast("omg"); | ||
}); | ||
it("should send a message from one component to another", function(done) { | ||
var a = absurd.component("ComponentA", { | ||
go: function() { | ||
this.dispatch("update", {value: 42}) | ||
} | ||
})(); | ||
var b = absurd.component("ComponentB", { | ||
update: function(data) { | ||
expect(data.value).toBe(42); | ||
expect(this.name).toBe("ComponentB"); | ||
done(); | ||
} | ||
})(); | ||
b.wire("update"); | ||
a.go(); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
describe("Testing nesting of components", function() { | ||
describe("Testing components (nesting)", function() { | ||
@@ -3,0 +3,0 @@ var absurd = Absurd(); |
@@ -420,10 +420,6 @@ lib.api.add = function(API) { | ||
for(var i=0; c=prop.charAt(i); i++) { | ||
if(options && options.keepCamelCase === true) { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} else { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} | ||
} | ||
@@ -541,3 +537,7 @@ } | ||
} | ||
entity += ' ' + transformUppercase(prop, options) + ': ' + value + ';' + newline; | ||
if(options && options.keepCamelCase === true) { | ||
entity += ' ' + prop + ': ' + value + ';' + newline; | ||
} else { | ||
entity += ' ' + transformUppercase(prop) + ': ' + value + ';' + newline; | ||
} | ||
} | ||
@@ -551,22 +551,2 @@ entity += '}' + newline; | ||
// dealing with false values | ||
var filterRules = function(rules) { | ||
var arr = {}; | ||
for(var selector in rules) { | ||
var areThereAnyProps = false; | ||
var props = {}; | ||
for(var prop in rules[selector]) { | ||
var value = rules[selector][prop]; | ||
if(value !== false && typeof value != 'object') { | ||
areThereAnyProps = true; | ||
props[prop] = value; | ||
} | ||
} | ||
if(areThereAnyProps) { | ||
arr[selector] = props; | ||
} | ||
} | ||
return arr; | ||
} | ||
// combining selectors | ||
@@ -616,3 +596,3 @@ var combineSelectors = function(rules) { | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
var r = rules[stylesheet]; | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
@@ -772,3 +752,3 @@ if(stylesheet === "mainstream") { | ||
beautifyHTML = require('js-beautify').html, | ||
transformUppercase = require("../../helpers/TransformUppercase"), | ||
tu = require("../../helpers/TransformUppercase"), | ||
passedOptions = {}; | ||
@@ -788,2 +768,9 @@ | ||
} | ||
var prepareProperty = function(prop, options) { | ||
if(options && options.keepCamelCase === true) { | ||
return prop; | ||
} else { | ||
return tu(prop, options); | ||
} | ||
} | ||
var process = function(tagName, obj) { | ||
@@ -816,12 +803,10 @@ // console.log("------------------------\n", tagName, ">", obj); | ||
if(typeof value[attrName] === "function") { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
} else { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
} | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
case "_": | ||
addToChilds(value); | ||
obj[directiveName] = false; | ||
break; | ||
@@ -839,3 +824,2 @@ case "_tpl": | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
@@ -857,27 +841,21 @@ case "_include": | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(value !== false) { | ||
var name = prop; | ||
switch(typeof value) { | ||
case "string": addToChilds(process(name, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
default: | ||
switch(typeof value) { | ||
case "string": addToChilds(process(directiveName, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
} | ||
addToChilds(process(directiveName, tmp)); | ||
} else { | ||
addToChilds(process(directiveName, value)); | ||
} | ||
addToChilds(process(name, tmp)); | ||
} else { | ||
addToChilds(process(name, value)); | ||
} | ||
break; | ||
case "function": addToChilds(process(name, value())); break; | ||
} | ||
break; | ||
case "function": addToChilds(process(directiveName, value())); break; | ||
} | ||
break; | ||
} | ||
@@ -901,5 +879,5 @@ } | ||
if(childs !== '') { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + transformUppercase(tagName, passedOptions) + '>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + prepareProperty(tagName, passedOptions) + '>'; | ||
} else { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '/>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '/>'; | ||
} | ||
@@ -939,3 +917,10 @@ return html; | ||
for(var i=0; c=prop[i]; i++) { | ||
if(/(#|\.|\[|\])/gi.test(prop) === false) { | ||
return { | ||
tag: prop, | ||
attrs: '' | ||
}; | ||
} | ||
for(var i=0; i<prop.length, c=prop[i]; i++) { | ||
if(c === "[" && !readingAttributes) { | ||
@@ -942,0 +927,0 @@ readingAttributes = true; |
module.exports = function(prop, options) { | ||
var transformed = ""; | ||
for(var i=0; c=prop.charAt(i); i++) { | ||
if(options && options.keepCamelCase === true) { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} else { | ||
if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { | ||
transformed += "-" + c.toLowerCase(); | ||
} else { | ||
transformed += c; | ||
} | ||
} | ||
@@ -13,0 +9,0 @@ } |
@@ -23,3 +23,7 @@ var newline = '\n', | ||
} | ||
entity += ' ' + transformUppercase(prop, options) + ': ' + value + ';' + newline; | ||
if(options && options.keepCamelCase === true) { | ||
entity += ' ' + prop + ': ' + value + ';' + newline; | ||
} else { | ||
entity += ' ' + transformUppercase(prop) + ': ' + value + ';' + newline; | ||
} | ||
} | ||
@@ -33,22 +37,2 @@ entity += '}' + newline; | ||
// dealing with false values | ||
var filterRules = function(rules) { | ||
var arr = {}; | ||
for(var selector in rules) { | ||
var areThereAnyProps = false; | ||
var props = {}; | ||
for(var prop in rules[selector]) { | ||
var value = rules[selector][prop]; | ||
if(value !== false && typeof value != 'object') { | ||
areThereAnyProps = true; | ||
props[prop] = value; | ||
} | ||
} | ||
if(areThereAnyProps) { | ||
arr[selector] = props; | ||
} | ||
} | ||
return arr; | ||
} | ||
// combining selectors | ||
@@ -98,3 +82,3 @@ var combineSelectors = function(rules) { | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
var r = rules[stylesheet]; | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
@@ -101,0 +85,0 @@ if(stylesheet === "mainstream") { |
@@ -12,3 +12,10 @@ module.exports = function(prop) { | ||
for(var i=0; c=prop[i]; i++) { | ||
if(/(#|\.|\[|\])/gi.test(prop) === false) { | ||
return { | ||
tag: prop, | ||
attrs: '' | ||
}; | ||
} | ||
for(var i=0; i<prop.length, c=prop[i]; i++) { | ||
if(c === "[" && !readingAttributes) { | ||
@@ -15,0 +22,0 @@ readingAttributes = true; |
@@ -6,3 +6,3 @@ var data = null, | ||
beautifyHTML = require('js-beautify').html, | ||
transformUppercase = require("../../helpers/TransformUppercase"), | ||
tu = require("../../helpers/TransformUppercase"), | ||
passedOptions = {}; | ||
@@ -22,2 +22,9 @@ | ||
} | ||
var prepareProperty = function(prop, options) { | ||
if(options && options.keepCamelCase === true) { | ||
return prop; | ||
} else { | ||
return tu(prop, options); | ||
} | ||
} | ||
var process = function(tagName, obj) { | ||
@@ -50,12 +57,10 @@ // console.log("------------------------\n", tagName, ">", obj); | ||
if(typeof value[attrName] === "function") { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; | ||
} else { | ||
attrs += " " + transformUppercase(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName] + "\""; | ||
} | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
case "_": | ||
addToChilds(value); | ||
obj[directiveName] = false; | ||
break; | ||
@@ -73,3 +78,2 @@ case "_tpl": | ||
} | ||
obj[directiveName] = false; | ||
break; | ||
@@ -91,27 +95,21 @@ case "_include": | ||
addToChilds(tmp); | ||
obj[directiveName] = false; | ||
break; | ||
} | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(value !== false) { | ||
var name = prop; | ||
switch(typeof value) { | ||
case "string": addToChilds(process(name, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
default: | ||
switch(typeof value) { | ||
case "string": addToChilds(process(directiveName, value)); break; | ||
case "object": | ||
if(value.length && value.length > 0) { | ||
var tmp = ''; | ||
for(var i=0; v=value[i]; i++) { | ||
tmp += process('', typeof v == "function" ? v() : v); | ||
if(i < value.length-1) tmp += newline; | ||
} | ||
addToChilds(process(directiveName, tmp)); | ||
} else { | ||
addToChilds(process(directiveName, value)); | ||
} | ||
addToChilds(process(name, tmp)); | ||
} else { | ||
addToChilds(process(name, value)); | ||
} | ||
break; | ||
case "function": addToChilds(process(name, value())); break; | ||
} | ||
break; | ||
case "function": addToChilds(process(directiveName, value())); break; | ||
} | ||
break; | ||
} | ||
@@ -135,5 +133,5 @@ } | ||
if(childs !== '') { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + transformUppercase(tagName, passedOptions) + '>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '>' + newline + childs + newline + '</' + prepareProperty(tagName, passedOptions) + '>'; | ||
} else { | ||
html += '<' + transformUppercase(tagName, passedOptions) + attrs + '/>'; | ||
html += '<' + prepareProperty(tagName, passedOptions) + attrs + '/>'; | ||
} | ||
@@ -140,0 +138,0 @@ return html; |
{ | ||
"name": "absurd", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"homepage": "http://krasimir.github.io/absurd", | ||
@@ -29,3 +29,5 @@ "description": "CSS/HTML preprocessor. Check out krasimirtsonev.com/blog/article/AbsurdJS-fundamentals", | ||
"grunt-lineending": "0.2.1", | ||
"jasmine-node": "~1.11.0" | ||
"jasmine-node": "~1.11.0", | ||
"npm-stats": "*", | ||
"JSONStream": "*" | ||
}, | ||
@@ -32,0 +34,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
388935
178
11919
8