postcss-mixins
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -0,5 +1,9 @@ | ||
## 3.0.1 | ||
* Fix default arguments in nested mixins. | ||
* Fix `@mixin-content` for declarations content. | ||
## 3.0 | ||
* Add nested mixins support. | ||
* Use `postcss-js` to conver object to CSS in JS mixins. | ||
* Case insentive mixin file search. | ||
* Use `postcss-js` to convert objects into CSS in JS mixins. | ||
* Case insensitive mixin file search. | ||
@@ -6,0 +10,0 @@ ## 2.1.1 |
46
index.js
@@ -8,3 +8,14 @@ var jsToCss = require('postcss-js/parser'); | ||
var insertObject = function (rule, obj, processMixins) { | ||
function insideDefine(rule) { | ||
var parent = rule.parent; | ||
if ( !parent ) { | ||
return false; | ||
} else if ( parent.name === 'define-mixin' ) { | ||
return true; | ||
} else { | ||
return insideDefine(parent); | ||
} | ||
} | ||
function insertObject(rule, obj, processMixins) { | ||
var root = jsToCss(obj); | ||
@@ -16,5 +27,5 @@ root.each(function (node) { | ||
rule.parent.insertBefore(rule, root); | ||
}; | ||
} | ||
var insertMixin = function (result, mixins, rule, processMixins, opts) { | ||
function insertMixin(result, mixins, rule, processMixins, opts) { | ||
var name = rule.params.split(/\s/, 1)[0]; | ||
@@ -48,8 +59,7 @@ var params = rule.params.slice(name.length).trim(); | ||
var clones = []; | ||
var proxy = postcss.root(); | ||
for ( i = 0; i < mixin.nodes.length; i++ ) { | ||
clones.push( mixin.nodes[i].clone() ); | ||
proxy.append( mixin.nodes[i].clone() ); | ||
} | ||
var proxy = postcss.rule({ nodes: clones }); | ||
if ( meta.args.length ) { | ||
@@ -59,4 +69,4 @@ vars({ only: values })(proxy); | ||
if ( meta.content ) { | ||
proxy.walkAtRules('mixin-content', function (place) { | ||
place.replaceWith(rule.nodes); | ||
proxy.walkAtRules('mixin-content', function (content) { | ||
content.replaceWith(rule.nodes); | ||
}); | ||
@@ -66,3 +76,3 @@ } | ||
rule.parent.insertBefore(rule, clones); | ||
rule.parent.insertBefore(rule, proxy); | ||
@@ -81,5 +91,5 @@ } else if ( typeof mixin === 'object' ) { | ||
if ( rule.parent ) rule.remove(); | ||
}; | ||
} | ||
var defineMixin = function (result, mixins, rule) { | ||
function defineMixin(result, mixins, rule) { | ||
var name = rule.params.split(/\s/, 1)[0]; | ||
@@ -117,3 +127,3 @@ var other = rule.params.slice(name.length).trim(); | ||
rule.remove(); | ||
}; | ||
} | ||
@@ -140,7 +150,9 @@ module.exports = postcss.plugin('postcss-mixins', function (opts) { | ||
var processMixins = function (root) { | ||
root.walkAtRules(function (atrule) { | ||
if ( atrule.name === 'mixin' ) { | ||
insertMixin(result, mixins, atrule, processMixins, opts); | ||
} else if ( atrule.name === 'define-mixin' ) { | ||
defineMixin(result, mixins, atrule); | ||
root.walkAtRules(function (i) { | ||
if ( i.name === 'mixin' ) { | ||
if ( !insideDefine(i) ) { | ||
insertMixin(result, mixins, i, processMixins, opts); | ||
} | ||
} else if ( i.name === 'define-mixin' ) { | ||
defineMixin(result, mixins, i); | ||
} | ||
@@ -147,0 +159,0 @@ }); |
{ | ||
"name": "postcss-mixins", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "PostCSS plugin for mixins", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
19278
161