Skip to content

Commit

Permalink
Update grunt:selector task to handle new Sizzle EXPOSE block
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jul 9, 2012
1 parent 7fae98c commit 4a90bce
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions grunt.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -156,10 +156,43 @@ module.exports = function( grunt ) {
api: file.read( files[0] ), api: file.read( files[0] ),
src: file.read( files[1] ) src: file.read( files[1] )
}, },
compiled; compiled, parts;

/**
sizzle-jquery.js -> sizzle between "EXPOSE" blocks,
replace define & window.Sizzle assignment
// EXPOSE
if ( typeof define === "function" && define.amd ) {
define(function() { return Sizzle; });
} else {
window.Sizzle = Sizzle;
}
// EXPOSE
Becomes...
Sizzle.attr = jQuery.attr;
jQuery.find = Sizzle;
jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.pseudos;
jQuery.unique = Sizzle.uniqueSort;
jQuery.text = Sizzle.getText;
jQuery.isXMLDoc = Sizzle.isXML;
jQuery.contains = Sizzle.contains;
*/

// Break into 3 pieces
parts = sizzle.src.split("// EXPOSE");
// Replace the if/else block with api
parts[1] = sizzle.api;
// Rejoin the pieces
compiled = parts.join("");



// sizzle-jquery.js -> sizzle after "EXPOSE", replace window.Sizzle
compiled = sizzle.src.replace( "window.Sizzle = Sizzle;", sizzle.api );
verbose.write("Injected sizzle-jquery.js into sizzle.js"); verbose.write("Injected sizzle-jquery.js into sizzle.js");


// Write concatenated source to file // Write concatenated source to file
Expand Down

0 comments on commit 4a90bce

Please sign in to comment.