Skip to content

Instantly share code, notes, and snippets.

@eightdotthree
Created July 10, 2015 22:23
Show Gist options
  • Save eightdotthree/c157b95e2738c0bff8c7 to your computer and use it in GitHub Desktop.
Save eightdotthree/c157b95e2738c0bff8c7 to your computer and use it in GitHub Desktop.
Usemin file for extracting attributes from CSS files. Used to maintain the data-skrollr-stylesheet attribute.
module.exports = function(grunt, options){
var yeoman = options.yeoman;
return {
options: {
dirs: [yeoman.dist],
blockReplacements: {
css: function(block) {
/**
* Find the first of the raw blocks that matches as a link, then extract the string to the left
* and the right of the href and put the new dest path in the middle of them, the keeping any
* attributes. Note: the attributes applied to the first link tag will be used, so if differnt
* attributes are required for different files, they need to be in their own block */
var result = '';
for(var i=0; i<block.raw.length; i++) {
if(block.raw[i].match(/\s*<link[^\>]+href=['"][^"']+["']/gm)) {
result = block.raw[i].replace(/\s*(<link[^\>]+href=['"])[^"']+(["'])/gm, '$1' + block.dest + '$2');
break;
}
}
return result;
}
}
},
html: [yeoman.dist + '/{,*/}*.html'],
css: [yeoman.dist + '/css/{,*/}*.css']
}
};
@eightdotthree
Copy link
Author

Found on Stack Overflow or GitHub in a comment but I lost the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment