Skip to content

Instantly share code, notes, and snippets.

@Panya
Created March 14, 2014 20:47
Show Gist options
  • Save Panya/9556507 to your computer and use it in GitHub Desktop.
Save Panya/9556507 to your computer and use it in GitHub Desktop.
diff --git a/lib/functions/index.js b/lib/functions/index.js
index fb55b71..7211a6c 100644
--- a/lib/functions/index.js
+++ b/lib/functions/index.js
@@ -1106,64 +1106,24 @@ exports.selector = function selector(sel){
return stack.length ? utils.compileSelectors(stack).join(',') : '&';
};
-function prefixNode(prefix, node) {
- switch (node.nodeName) {
- case 'function':
- case 'ident':
- return node.name;
- case 'literal':
- case 'string':
- if (prefix && !node.prefixed && !node.val.nodeName) {
- node.val = node.val.replace(/\./g, '.' + prefix);
- node.prefixed = true;
- }
- return node.val;
- case 'unit':
- default:
- return node.val;
- }
-}
-
-function prefixClassesForSelector(prefix, selector) {
- selector.segments.forEach(function (segment) {
- prefixNode(prefix.string, segment);
- });
-}
-
-function prefixClassesForBlock(prefix, block) {
- if (block.nodes && block.nodes.length) {
- block.nodes = block.nodes.map(function (node) {
- if (node.nodeName == 'group' && node.nodes.length) {
- node.nodes.forEach(function (selector) {
- if (selector.segments) {
- prefixClassesForSelector(prefix, selector);
- } else {
- prefixNode(prefix.string, selector);
- }
- });
- } else if (node.nodeName == 'block') {
- return prefixClassesForBlock(prefix, node);
- }
- return node;
- });
- }
- return block;
-}
-
/**
* Prefix css classes in a block
*
- * @param {String} [prefix]
- * @param {Block} [block]
+ * @param {String} prefix
+ * @param {Block} block
* @return {Block}
- * @api public
+ * @api private
*/
exports['-prefix-classes'] = function prefixClasses(prefix, block){
utils.assertString(prefix, 'prefix');
utils.assertType(block, 'block', 'block');
+ var _prefix = this.prefix;
- return prefixClassesForBlock(prefix, block);
+ this.prefix = prefix.string;
+ block = this.visit(block);
+ this.prefix = _prefix;
+ return block;
};
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment