Created
January 23, 2016 05:53
-
-
Save wyze/85b61bc6560d05a43f50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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