Skip to content

Commit

Permalink
🚧 Write loops for checking rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Sum authored and Hugo Sum committed Aug 3, 2020
1 parent c5a0696 commit 7f23217
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PostCSS Rfs Autopilot

[PostCSS] plugin Auto markup your CSS with rfs() for RFS.
[PostCSS] A plugin that automagically mark your CSS up with `rfs()` for [RFS](https://github.com/twbs/rfs).

[PostCSS]: https://github.com/postcss/postcss

Expand All @@ -16,6 +16,12 @@
}
```

## Problem

[RFS](https://github.com/twbs/rfs) is a great unit resizing engine that helps you build responsive CSS layout, but writing `rfs()` everywhere manually is a pain in the ass.

With this plugin, you just need to declare rules you want to apply `rfs()` to, and it will do the heavy lifting for you.

## Usage

Check you project for existed PostCSS config: `postcss.config.js`
Expand Down
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ module.exports = postcss.plugin('postcss-rfs-autopilot', ({ rulesToTransform, un
// Work with options here

return (root, result) => {

// Transform CSS AST here

root.walkRules((rule) => {
options.rulesToTransform.forEach((desiredRuleToTransform) => {
//Find all rules the user want to apply RFS to
rule.walkDecls(desiredRuleToTransform, (decl) => {
//Check if rfs() has already applied to the value
if( ! /^rfs/g.test(decl)){
console.log('RFS declaration not found. Apply transformation here.')
console.log(decl);
}
})
})
})
}
})

0 comments on commit 7f23217

Please sign in to comment.