Skip to content

Instantly share code, notes, and snippets.

@msweeney
Last active December 18, 2015 10:39
Show Gist options
  • Save msweeney/5770059 to your computer and use it in GitHub Desktop.
Save msweeney/5770059 to your computer and use it in GitHub Desktop.
module.exports = function(str) {
return function(style) {
style.rules = style.rules.map(function(rule) {
if (rule.declarations) {
rule.declarations.forEach(function(decl, i) {
var token;
if (decl.comment) {
token = decl.comment.trim();
if (token.charAt(0) === '$') {
rule.declarations[i+1].value = token;
}
}
});
}
return rule;
});
}
};
pure-button {
/* $buttonBackgroundColor */
background-color: #E6E6E6;
/* $buttonBorderHex */
border: 1px solid #999; /*IE 6/7/8*/
/* $buttonBorderRGBA */
border: none rgba(0, 0, 0, 0); /*IE9 + everything else*/
/* $buttonBorderRadius */
border-radius: 2px;
/* $buttonColorHex */
color: #444; /* rgba not supported (IE 8) */
/* $buttonColorRGBA */
color: rgba(0, 0, 0, 0.80); /* rgba supported */
/* $buttonColorHex */
*color: #444; /* IE 6 & 7 */
/* $buttonPadding */
padding: 0.5em 1.5em 0.5em;
}
var rework = require('..'),
addVars = require('addVars.js'),
read = require('fs').readFileSync;
var css = rework(read('button-skin.css', 'utf8'))
.use(addVars())
.toString()
console.log(css);
/* yields:
(note comments removed for brevity)
.pure-button {
background-color: $buttonBackgroundColor;
border: $buttonBorderHex;
border: $buttonBorderRGBA;
border-radius: $buttonBorderRadius;
color: $buttonColorHex;
color: $buttonColorRGBA;
*color: $buttonColorHex;
padding: $buttonPadding;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment