Comparing version 0.0.27 to 0.0.28
@@ -31,2 +31,5 @@ var fs = require('fs'); | ||
// internal variables | ||
_api.numOfAddedRules = 0; | ||
// registering API methods | ||
@@ -33,0 +36,0 @@ if(fs.existsSync(__dirname + "/api")) { |
@@ -12,3 +12,3 @@ module.exports = function(API) { | ||
return false; | ||
} | ||
} | ||
} | ||
@@ -45,21 +45,23 @@ var clearingPluginsCalls = function(props) { | ||
var addRule = function(selector, props, stylesheet) { | ||
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; | ||
// check for plugin | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet)) return; | ||
// 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]; | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearingPluginsCalls(props); | ||
} else if(typeof props === "string") { | ||
checkAndExecutePlugin(null, selector, props, stylesheet); | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearingPluginsCalls(props); | ||
} | ||
var add = function(rules, stylesheet) { | ||
API.numOfAddedRules += 1; | ||
for(var selector in rules) { | ||
@@ -66,0 +68,0 @@ if(typeof rules[selector].length !== 'undefined' && typeof rules[selector] === "object") { |
@@ -19,15 +19,15 @@ var requireUncached = require('../helpers/RequireUncached.js'), | ||
} else if(ext === "css") { | ||
try { | ||
// try { | ||
var cssData = fs.readFileSync(path, {encoding: "utf8"}); | ||
var parsed = CSSParse(cssData); | ||
API.handlecss(parsed, path); | ||
} catch(err) { | ||
console.log("Error during importing of '" + path + "'", err); | ||
} | ||
// } catch(err) { | ||
// console.log("Error during importing of '" + path + "'", err); | ||
// } | ||
} else { | ||
try { | ||
// try { | ||
requireUncached(path)(API) | ||
} catch(err) { | ||
console.log("Error: I can't find '" + path + "'.", err); | ||
} | ||
// } catch(err) { | ||
// console.log("Error: I can't find '" + path + "'.", err); | ||
// } | ||
} | ||
@@ -34,0 +34,0 @@ } |
module.exports = function(api) { | ||
return function(raw) { | ||
api.add({ | ||
____raw: { value: raw } | ||
}); | ||
var o = {}; | ||
o["____raw_" + api.numOfAddedRules] = { value: raw }; | ||
api.add(o); | ||
return api; | ||
} | ||
} |
@@ -6,5 +6,9 @@ module.exports = function() { | ||
stylesheet += '@' + value.vendor + 'document'; | ||
stylesheet += ' ' + value.document | ||
for(var i=0; rule=value.rules[i]; i++) { | ||
api.handlecssrule(rule, stylesheet) | ||
stylesheet += ' ' + value.document; | ||
if(value.rules && value.rules.length) { | ||
for(var i=0; rule=value.rules[i]; i++) { | ||
api.handlecssrule(rule, stylesheet); | ||
} | ||
} else if(typeof value.styles != "undefined") { | ||
api.add(value.styles, stylesheet); | ||
} | ||
@@ -11,0 +15,0 @@ } |
@@ -1,4 +0,8 @@ | ||
var cleanCSS = require('clean-css'); | ||
var cleanCSS = require('clean-css'), | ||
newline = '\n', | ||
defaultOptions = { | ||
combineSelectors: true, | ||
minify: false | ||
}; | ||
var newline = '\n'; | ||
var toCSS = function(rules) { | ||
@@ -8,3 +12,3 @@ var css = ''; | ||
// handling raw content | ||
if(selector === "____raw") { | ||
if(selector.indexOf("____raw") === 0) { | ||
css += rules[selector].value + newline; | ||
@@ -86,2 +90,3 @@ // handling normal styles | ||
module.exports = function(rules, callback, options) { | ||
options = options || defaultOptions; | ||
var css = ''; | ||
@@ -94,3 +99,2 @@ for(var stylesheet in rules) { | ||
} else { | ||
// media queries handling | ||
css += stylesheet + " {" + newline + toCSS(r) + "}" + newline; | ||
@@ -101,6 +105,8 @@ } | ||
if(options.minify) { | ||
callback(null, cleanCSS.process(css)); | ||
css = cleanCSS.process(css); | ||
if(callback) callback(null, css); | ||
} else { | ||
callback(null, css); | ||
if(callback) callback(null, css); | ||
} | ||
return css; | ||
} |
{ | ||
"name": "absurd", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"homepage": "https://github.com/krasimir/absurd", | ||
@@ -5,0 +5,0 @@ "description": "CSS preprocessor", |
@@ -50,3 +50,3 @@ describe("Test case (charset)", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('body {\n border-radius: 2px;\n}\nbody a {\n font-size: 2em;\n}\n@charset: "BLA-BLA";\np {\n margin: 2px;\n}\n'); | ||
expect(css).toBe('body {\n border-radius: 2px;\n}\nbody a {\n font-size: 2em;\n}\n@charset: "UTF-8";\n@charset: "BLA-BLA";\np {\n margin: 2px;\n}\n'); | ||
done(); | ||
@@ -53,0 +53,0 @@ }); |
@@ -5,2 +5,20 @@ describe("Test case (Document)", function() { | ||
it("Document / js", function(done) { | ||
Absurd(__dirname + '/code.js').compile(function(err, css) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('@-moz-document url-prefix() {\n.ui-select .ui-btn select {\n opacity: .0001;\n}\n}\n'); | ||
done(); | ||
}); | ||
}); | ||
it("Document / json", function(done) { | ||
Absurd(__dirname + '/code.json').compile(function(err, css) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('@-moz-document url-prefix() {\n.ui-select .ui-btn select {\n opacity: .0001;\n}\n}\n'); | ||
done(); | ||
}); | ||
}); | ||
it("Document / css", function(done) { | ||
@@ -7,0 +25,0 @@ Absurd(__dirname + '/code.css').compile(function(err, css) { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
60441
83
1623
11