Comparing version 0.0.26 to 0.0.27
@@ -45,3 +45,3 @@ var fs = require('fs'); | ||
var file = plugins[i]; | ||
_api.plugin(file.replace(".js", ""), require(__dirname + "/plugins/" + file)); | ||
_api.plugin(file.replace(".js", ""), require(__dirname + "/plugins/" + file)()); | ||
} | ||
@@ -48,0 +48,0 @@ } |
module.exports = function(API) { | ||
var checkForPlugin = function(selector, prop, value, stylesheet) { | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet) { | ||
var plugin = API.getPlugins()[prop]; | ||
if(typeof plugin !== 'undefined') { | ||
addRule(selector, plugin(API, value), stylesheet); | ||
var pluginResponse = plugin(API, value); | ||
if(pluginResponse) { | ||
addRule(selector, pluginResponse, stylesheet); | ||
} | ||
return true; | ||
@@ -29,3 +32,3 @@ } else { | ||
// check for plugins | ||
} else if(checkForPlugin(selector, prop, props[prop], stylesheet) === false) { | ||
} else if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet) === false) { | ||
addRule(selector + " " + prop, props[prop], stylesheet); | ||
@@ -35,3 +38,3 @@ } | ||
} else { | ||
if(checkForPlugin(selector, prop, props[prop], stylesheet)) { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet)) { | ||
props[prop] = false; | ||
@@ -43,24 +46,28 @@ } | ||
var addRule = function(selector, props, stylesheet) { | ||
// if the selector is already there | ||
if(typeof API.getRules(stylesheet || "mainstream")[selector] == 'object') { | ||
var current = API.getRules(stylesheet || "mainstream")[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
current[propNew] = props[propNew]; | ||
if(typeof props === "object") { | ||
// if the selector is already there | ||
if(typeof API.getRules(stylesheet || "mainstream")[selector] == 'object') { | ||
var current = API.getRules(stylesheet || "mainstream")[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
current[propNew] = props[propNew]; | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearingPluginsCalls(props); | ||
} else if(typeof props === "string") { | ||
checkAndExecutePlugin(null, selector, props, stylesheet); | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearingPluginsCalls(props); | ||
} | ||
var add = function(rules) { | ||
var add = function(rules, stylesheet) { | ||
for(var selector in rules) { | ||
if(typeof rules[selector].length !== 'undefined') { | ||
if(typeof rules[selector].length !== 'undefined' && typeof rules[selector] === "object") { | ||
for(var i=0; r=rules[selector][i]; i++) { | ||
addRule(selector, r, "mainstream"); | ||
addRule(selector, r, stylesheet || "mainstream"); | ||
} | ||
} else { | ||
addRule(selector, rules[selector], "mainstream"); | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
} | ||
@@ -67,0 +74,0 @@ } |
@@ -7,23 +7,3 @@ var requireUncached = require('../helpers/RequireUncached.js'), | ||
module.exports = function(API) { | ||
var HandleCSS = { | ||
rule: function(rule) { | ||
var absurdObj = {}, absurdProps = {}; | ||
if(rule.declarations && rule.declarations.length > 0) { | ||
for(var i=0; decl=rule.declarations[i]; i++) { | ||
if(decl.type === "declaration") { | ||
absurdProps[decl.property] = decl.value; | ||
} | ||
} | ||
if(rule.selectors && rule.selectors.length > 0) { | ||
for(var i=0; selector=rule.selectors[i]; i++) { | ||
absurdObj[selector] = absurdProps; | ||
} | ||
} | ||
API.add(absurdObj); | ||
} | ||
}, | ||
import: function(rule, cssPath) { | ||
API.import(path.dirname(cssPath) + "/" + rule.import.replace(/"/g, '')); | ||
} | ||
} | ||
var importFile = function(path) { | ||
@@ -43,9 +23,3 @@ var ext = path.split('.').pop().toLowerCase(); | ||
var parsed = CSSParse(cssData); | ||
if(parsed && parsed.type === 'stylesheet' && parsed.stylesheet && parsed.stylesheet.rules) { | ||
var rules = parsed.stylesheet.rules; | ||
for(var i=0; rule=rules[i]; i++) { | ||
// console.log(rule); | ||
if(HandleCSS[rule.type]) HandleCSS[rule.type](rule, path); | ||
} | ||
} | ||
API.handlecss(parsed, path); | ||
} catch(err) { | ||
@@ -52,0 +26,0 @@ console.log("Error during importing of '" + path + "'", err); |
{ | ||
"name": "absurd", | ||
"version": "0.0.26", | ||
"version": "0.0.27", | ||
"homepage": "https://github.com/krasimir/absurd", | ||
@@ -5,0 +5,0 @@ "description": "CSS preprocessor", |
@@ -40,4 +40,4 @@ # absurd.js | ||
compile([callback], [settings]) | ||
compileFile([outputFile], [callback], [settings]) | ||
.compile([callback], [settings]) | ||
.compileFile([outputFile], [callback], [settings]) | ||
@@ -58,3 +58,3 @@ *settings* parameter is optional. Valid options: | ||
// do something with the css | ||
},); | ||
}); | ||
@@ -61,0 +61,0 @@ Or you may get the API separately. |
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
51958
63
1342