Permalink
Browse files

refactor positions example with visitor

  • Loading branch information...
1 parent ba90780 commit 35abd25a663fb529ce75ca3d776b70b64e685c2c @tj tj committed Mar 1, 2013
Showing with 7 additions and 7 deletions.
  1. +7 −7 examples/positions.js
View
@@ -6,17 +6,17 @@ function positions() {
var positions = ['absolute', 'relative', 'fixed'];
return function(style){
- style.rules.forEach(function(rule){
- rule.declarations.forEach(function(decl, i){
+ rework.visit.declarations(style, function(declarations){
+ declarations.forEach(function(decl, i){
if (!~positions.indexOf(decl.property)) return;
var args = decl.value.split(/\s+/);
var arg, n;
// remove original
- rule.declarations.splice(i, 1);
+ declarations.splice(i, 1);
// position prop
- rule.declarations.push({
+ declarations.push({
property: 'position',
value: decl.property
});
@@ -25,12 +25,12 @@ function positions() {
while (args.length) {
arg = args.shift();
n = parseFloat(args[0]) ? args.shift() : 0;
- rule.declarations.push({
+ declarations.push({
property: arg,
value: n
});
}
-
+
});
});
}
@@ -40,4 +40,4 @@ var css = rework(read('examples/positions.css', 'utf8'))
.use(positions())
.toString()
-console.log(css);
+console.log(css);

0 comments on commit 35abd25

Please sign in to comment.