My greatest programming joys over the past few months have been whenever I get the opportunity to programmatically manipulate the code itself. Ever since transforming a number of projects containing 100s of modules from AMD to Common.js, it’s been stewing in my mind.
ReworkCSS, though, is a bit different than a typical CSS preprocessor. It’s a tool for sending CSS through a pipeline and doing anything you can imagine with it. Transform and extend the language, track internal usage metrics of properties and selectors, or add custom linting. It’s not an opinionated css-like language that outputs CSS. It’s a preprocessors foundation. And it’s fast.
For these reasons rework is my tool of choice when working in the CSS domain. You have the full power of your programming abilities and ideas at your disposal.
Rework parses a string of CSS and returns to you an abstract syntax tree (AST). An AST is a tree structure that represents the source file. Simplistically, you can think of an AST for any language as a defined object containing child array and objects.
Iterating over arrays and objects and manipulating them is more or less what we do as developers. To get started manipulating one of these trees it is important to understand it and know what to look for in your filter and reducing functions.
It is in this spirit that I forked @fkling42’s wonderful Esprima AST Explorer tool to use ReworkCSS. The forked project is available here: http://iamdustan.com/reworkcss_ast_explorer/ and on github: https://github.com/iamdustan/reworkcss_ast_explorer.
In the left pane you can write any valid CSS and in the right pane you can explore the abstract syntax tree that rework provides you. Please note that there are a few bugs yet to work out. Namely, the original project has cross- pane contextual highlighting.
Open up the CSS AST Explorer in your browser while writing a custom transformer to extend and level up your projects front end code.
Some ideas for rework plugins to get you started:
My hope is that tools like these help you think about software development and UI development in differently.
For more inspiration:
These words brought to you by Dustan Kasten. A friendly, bearded, husband, father, and user interface engineer living in Charlotte, NC. Considers himself quite partial to React.js these days. Find @iamdustan on Twitter