Comparing version 0.0.38 to 0.0.39
@@ -1,2 +0,2 @@ | ||
/* version: 0.0.37 */ | ||
/* version: 0.0.39 */ | ||
var Absurd = (function(w) { | ||
@@ -10,3 +10,3 @@ var lib = { | ||
var require = function() { | ||
return function() {} | ||
}; | ||
@@ -34,3 +34,3 @@ var client = function() { | ||
minify: false, | ||
processor: lib.processors.CSS | ||
processor: lib.processors.CSS() | ||
}; | ||
@@ -79,3 +79,5 @@ | ||
for(var method in lib.api) { | ||
_api[method] = lib.api[method](_api); | ||
if(method !== "compile") { | ||
_api[method] = lib.api[method](_api); | ||
} | ||
} | ||
@@ -231,2 +233,41 @@ | ||
} | ||
var extend = function(destination, source) { | ||
for (var key in source) { | ||
if (hasOwnProperty.call(source, key)) { | ||
destination[key] = source[key]; | ||
} | ||
} | ||
return destination; | ||
}; | ||
lib.api.compile = function(api) { | ||
return function(callback, options) { | ||
var _defaultOptions = { | ||
combineSelectors: true, | ||
minify: false, | ||
processor: require("../processors/CSS.js")() | ||
}; | ||
options = extend(_defaultOptions, options || {}); | ||
options.processor( | ||
api.getRules(), | ||
callback || function() {}, | ||
options | ||
); | ||
} | ||
} | ||
lib.api.compileFile = function(api) { | ||
return function(file, compileFileCallback, options) { | ||
api.compile(function(err, css) { | ||
try { | ||
fs.writeFile(file, css, function (err) { | ||
compileFileCallback(err, css); | ||
}); | ||
} catch(err) { | ||
compileFileCallback(err); | ||
} | ||
}, options); | ||
} | ||
} | ||
lib.api.plugin = function(api) { | ||
@@ -297,3 +338,3 @@ var plugin = function(name, func) { | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -329,3 +370,3 @@ // js or json | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -381,3 +422,3 @@ var content = '@media ' + value.media + " {\n"; | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -489,24 +530,26 @@ var content = '@supports ' + value.supports + " {\n"; | ||
lib.processors.CSS = function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
lib.processors.CSS = function() { | ||
return function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
}; | ||
return client(); | ||
})(window); |
@@ -1,1 +0,1 @@ | ||
var Absurd=function(){function a(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}var b={api:{},helpers:{},plugins:{},processors:{}},d=function(){},e=function(){return function(a){var c=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},d={},e={},f={},g={},h={combineSelectors:!0,minify:!1,processor:b.processors.CSS};d.getRules=function(a){return"undefined"==typeof a?e:("undefined"==typeof e[a]&&(e[a]=[]),e[a])},d.getPlugins=function(){return g},d.getStorage=function(){return f},d.flush=function(){e={},f=[]},d.numOfAddedRules=0,d.compile=function(a,b){b=c(h,b||{}),b.processor(d.getRules(),a||function(){},{combineSelectors:!0})},d.getPath=function(){return{}};for(var i in b.api)d[i]=b.api[i](d);for(var j in b.plugins)d.plugin(j,b.plugins[j]());return"function"==typeof a&&a(d),d}};b.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)},d=function(a,c,d){for(var f in c)"object"==typeof c[f]?(":"===f.charAt(0)?e(a+f,c[f],d):0===f.indexOf("@media")||0===f.indexOf("@supports")?e(a,c[f],f):b(a,f,c[f],d)===!1&&e(a+" "+f,c[f],d),c[f]=!1):b(a,f,c[f],d)&&(c[f]=!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},b.api.colors=function(b){var c=b.darken=function(b,c){return a(b,-(c/100))},d=b.lighten=function(b,c){return a(b,c/100)};return{darken:c,lighten:d}},b.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},b.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}},b.api.storage=function(a){var b=a.getStorage(),c=function(c,d){if("undefined"==typeof d){if(b[c])return b[c];throw new Error("There is no data in the storage associated with '"+c+"'")}return b[c]=d,a};return c},b.helpers.RequireUncached=function(a){return delete d.cache[d.resolve(a)],d(a)},b.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+'";'))}},b.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)}}},b.plugins.keyframes=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS");if("object"==typeof b)if("undefined"!=typeof b.frames){var e="@keyframes "+b.name+" {\n";e+=c({mainstream:b.frames}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var e="@keyframes "+b.name+" {\n",f={},g=0;rule=b.keyframes[g];g++)if("keyframe"===rule.type)for(var h=f[rule.values]={},i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value);e+=c({mainstream:f}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}}},b.plugins.media=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS");if("object"==typeof b){for(var e="@media "+b.media+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}},b.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+'";'))}},b.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)}}},b.plugins.supports=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS");if("object"==typeof b){for(var e="@supports "+b.supports+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}};var f=d("clean-css"),g="\n",h={combineSelectors:!0,minify:!1},i=function(a){var b="";for(var c in a)if(0===c.indexOf("____raw"))b+=a[c][c]+g;else{var d=c+" {"+g;for(var e in a[c])a[c][e],d+=" "+l(e)+": "+a[c][e]+";"+g;d+="}"+g,b+=d}return b},j=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},k=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},l=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};return b.processors.CSS=function(a,b,c){c=c||h;var d="";for(var e in a){var l=j(a[e]);l=c.combineSelectors?k(l):l,d+="mainstream"===e?i(l):e+" {"+g+i(l)+"}"+g}return c.minify?(d=f.process(d),b&&b(null,d)):b&&b(null,d),d},e()}(window); | ||
var Absurd=function(){function a(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}var b={api:{},helpers:{},plugins:{},processors:{}},d=function(){return function(){}},e=function(){return function(a){var c=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},d={},e={},f={},g={},h={combineSelectors:!0,minify:!1,processor:b.processors.CSS()};d.getRules=function(a){return"undefined"==typeof a?e:("undefined"==typeof e[a]&&(e[a]=[]),e[a])},d.getPlugins=function(){return g},d.getStorage=function(){return f},d.flush=function(){e={},f=[]},d.numOfAddedRules=0,d.compile=function(a,b){b=c(h,b||{}),b.processor(d.getRules(),a||function(){},{combineSelectors:!0})},d.getPath=function(){return{}};for(var i in b.api)"compile"!==i&&(d[i]=b.api[i](d));for(var j in b.plugins)d.plugin(j,b.plugins[j]());return"function"==typeof a&&a(d),d}};b.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)},d=function(a,c,d){for(var f in c)"object"==typeof c[f]?(":"===f.charAt(0)?e(a+f,c[f],d):0===f.indexOf("@media")||0===f.indexOf("@supports")?e(a,c[f],f):b(a,f,c[f],d)===!1&&e(a+" "+f,c[f],d),c[f]=!1):b(a,f,c[f],d)&&(c[f]=!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},b.api.colors=function(b){var c=b.darken=function(b,c){return a(b,-(c/100))},d=b.lighten=function(b,c){return a(b,c/100)};return{darken:c,lighten:d}};var f=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a};b.api.compile=function(a){return function(b,c){var e={combineSelectors:!0,minify:!1,processor:d("../processors/CSS.js")()};c=f(e,c||{}),c.processor(a.getRules(),b||function(){},c)}},b.api.compileFile=function(a){return function(b,c,d){a.compile(function(a,d){try{fs.writeFile(b,d,function(a){c(a,d)})}catch(a){c(a)}},d)}},b.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},b.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}},b.api.storage=function(a){var b=a.getStorage(),c=function(c,d){if("undefined"==typeof d){if(b[c])return b[c];throw new Error("There is no data in the storage associated with '"+c+"'")}return b[c]=d,a};return c},b.helpers.RequireUncached=function(a){return delete d.cache[d.resolve(a)],d(a)},b.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+'";'))}},b.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)}}},b.plugins.keyframes=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b)if("undefined"!=typeof b.frames){var e="@keyframes "+b.name+" {\n";e+=c({mainstream:b.frames}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var e="@keyframes "+b.name+" {\n",f={},g=0;rule=b.keyframes[g];g++)if("keyframe"===rule.type)for(var h=f[rule.values]={},i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value);e+=c({mainstream:f}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}}},b.plugins.media=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b){for(var e="@media "+b.media+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}},b.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+'";'))}},b.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)}}},b.plugins.supports=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b){for(var e="@supports "+b.supports+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}};var g=d("clean-css"),h="\n",i={combineSelectors:!0,minify:!1},j=function(a){var b="";for(var c in a)if(0===c.indexOf("____raw"))b+=a[c][c]+h;else{var d=c+" {"+h;for(var e in a[c])a[c][e],d+=" "+m(e)+": "+a[c][e]+";"+h;d+="}"+h,b+=d}return b},k=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},l=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},m=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};return b.processors.CSS=function(){return function(a,b,c){c=c||i;var d="";for(var e in a){var f=k(a[e]);f=c.combineSelectors?l(f):f,d+="mainstream"===e?j(f):e+" {"+h+j(f)+"}"+h}return c.minify?(d=g.process(d),b&&b(null,d)):b&&b(null,d),d}},e()}(window); |
var require = function() { | ||
return function() {} | ||
}; |
@@ -22,3 +22,3 @@ var client = function() { | ||
minify: false, | ||
processor: lib.processors.CSS | ||
processor: lib.processors.CSS() | ||
}; | ||
@@ -67,3 +67,5 @@ | ||
for(var method in lib.api) { | ||
_api[method] = lib.api[method](_api); | ||
if(method !== "compile") { | ||
_api[method] = lib.api[method](_api); | ||
} | ||
} | ||
@@ -70,0 +72,0 @@ |
@@ -135,2 +135,41 @@ lib.api.add = function(API) { | ||
} | ||
var extend = function(destination, source) { | ||
for (var key in source) { | ||
if (hasOwnProperty.call(source, key)) { | ||
destination[key] = source[key]; | ||
} | ||
} | ||
return destination; | ||
}; | ||
lib.api.compile = function(api) { | ||
return function(callback, options) { | ||
var _defaultOptions = { | ||
combineSelectors: true, | ||
minify: false, | ||
processor: require("../processors/CSS.js")() | ||
}; | ||
options = extend(_defaultOptions, options || {}); | ||
options.processor( | ||
api.getRules(), | ||
callback || function() {}, | ||
options | ||
); | ||
} | ||
} | ||
lib.api.compileFile = function(api) { | ||
return function(file, compileFileCallback, options) { | ||
api.compile(function(err, css) { | ||
try { | ||
fs.writeFile(file, css, function (err) { | ||
compileFileCallback(err, css); | ||
}); | ||
} catch(err) { | ||
compileFileCallback(err); | ||
} | ||
}, options); | ||
} | ||
} | ||
lib.api.plugin = function(api) { | ||
@@ -201,3 +240,3 @@ var plugin = function(name, func) { | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -233,3 +272,3 @@ // js or json | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -285,3 +324,3 @@ var content = '@media ' + value.media + " {\n"; | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -393,22 +432,24 @@ var content = '@supports ' + value.supports + " {\n"; | ||
lib.processors.CSS = function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
lib.processors.CSS = function() { | ||
return function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} |
56
index.js
@@ -8,53 +8,13 @@ #!/usr/bin/env node | ||
hasOwnProperty = Object.prototype.hasOwnProperty, | ||
API = null, | ||
api = null, | ||
absurd = null, | ||
module.exports = absurd = function(func) { | ||
API = require("./lib/API.js")(); | ||
var _defaultOptions = { | ||
combineSelectors: true, | ||
minify: false, | ||
processor: require("./lib/processors/CSS.js") | ||
}; | ||
var extend = function(destination, source) { | ||
for (var key in source) { | ||
if (hasOwnProperty.call(source, key)) { | ||
destination[key] = source[key]; | ||
} | ||
} | ||
return destination; | ||
}; | ||
// --------------------------------------------------- compile | ||
var compile = API.compile = function(callback, options) { | ||
options = extend(_defaultOptions, options || {}); | ||
if(typeof func == "function") { | ||
func(API); | ||
} else if(typeof func == "string") { | ||
API.import(func); | ||
} | ||
options.processor( | ||
API.getRules(), | ||
callback || function() {}, | ||
options | ||
); | ||
} | ||
// --------------------------------------------------- compile to file | ||
var compileFile = API.compileFile = function(file, compileFileCallback, options) { | ||
compile(function(err, css) { | ||
try { | ||
fs.writeFile(file, css, function (err) { | ||
compileFileCallback(err, css); | ||
}); | ||
} catch(err) { | ||
compileFileCallback(err); | ||
} | ||
}, options); | ||
} | ||
return API; | ||
api = require("./lib/API.js")(); | ||
if(typeof func == "function") { | ||
func(api); | ||
} else if(typeof func == "string") { | ||
api.import(func); | ||
} | ||
return api; | ||
} | ||
@@ -61,0 +21,0 @@ |
@@ -26,3 +26,3 @@ var requireUncached = require('../helpers/RequireUncached.js'), | ||
} | ||
} else { | ||
} else if(ext === "js") { | ||
try { | ||
@@ -29,0 +29,0 @@ requireUncached(path)(API) |
module.exports = function() { | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -5,0 +5,0 @@ // js or json |
module.exports = function() { | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -5,0 +5,0 @@ var content = '@media ' + value.media + " {\n"; |
module.exports = function() { | ||
return function(api, value) { | ||
var processor = require(__dirname + "/../processors/CSS"); | ||
var processor = require(__dirname + "/../processors/CSS")(); | ||
if(typeof value === "object") { | ||
@@ -5,0 +5,0 @@ var content = '@supports ' + value.supports + " {\n"; |
@@ -88,22 +88,24 @@ var cleanCSS = require('clean-css'), | ||
module.exports = function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
module.exports = function() { | ||
return function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
for(var stylesheet in rules) { | ||
var r = filterRules(rules[stylesheet]); | ||
r = options.combineSelectors ? combineSelectors(r) : r; | ||
if(stylesheet === "mainstream") { | ||
css += toCSS(r); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
} | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} | ||
// Minification | ||
if(options.minify) { | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} |
{ | ||
"name": "absurd", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"homepage": "https://github.com/krasimir/absurd", | ||
@@ -5,0 +5,0 @@ "description": "CSS preprocessor", |
@@ -12,3 +12,3 @@ describe("Absurd acting in code:", function() { | ||
it("should initialize absurd", function(done) { | ||
absurd = Absurd("./../data/css/index.js"); | ||
absurd = Absurd(__dirname + "/../data/css/index.js"); | ||
expect(typeof absurd).toBe("object"); | ||
@@ -15,0 +15,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207506
108
6244