Skip to content

Instantly share code, notes, and snippets.

@wyze
Created January 23, 2016 05:53
Show Gist options
  • Save wyze/85b61bc6560d05a43f50 to your computer and use it in GitHub Desktop.
Save wyze/85b61bc6560d05a43f50 to your computer and use it in GitHub Desktop.
import declarer from '../utils/declarer'
const antGutter = decl => {
declarer({
body: {
background: 'tomato'
},
'.one:after': {
content: `'1'`
},
'.two:after': {
content: `'2'`
},
'.three:after': {
content: `'3'`
}
}, decl)
decl.remove()
}
export default antGutter
import { pascalToDash } from './string-conversion'
const declarer = (declarations, decl) => {
Object.keys(declarations).reverse().forEach(selector => {
// If the selector is the same as the one the declaration was discovered in...
if (decl.parent.selector === selector) {
for (let declaration of Object.keys(declarations[selector])) {
decl.parent.append({
prop: pascalToDash(declaration),
value: declarations[selector][declaration]
})
}
} else {
// Thanks to https://github.com/jeffjewiss for this code.
const ruleset = decl.parent.cloneAfter({ selector })
ruleset.walkDecls(decl => decl.remove())
for (let declaration of Object.keys(declarations[selector])) {
decl.clone({
prop: pascalToDash(declaration),
value: declarations[selector][declaration]
}).moveTo(ruleset)
}
}
})
}
export default declarer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment