Created
April 22, 2014 04:12
-
-
Save kirjs/11165115 to your computer and use it in GitHub Desktop.
graspWrapper
This file contains 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
/** | |
* Simple wrapper to add chainable syntax to grasp.js | |
* | |
* Retuns an object that could be used this way: | |
* | |
* grasp( code ).squery('if.test').search() | |
* grasp( code ).squery('if.test').replace('!({{}})'); | |
* | |
*/ | |
function graspWrapper(grasp) { | |
var Query = function(type, query, code) { | |
this.type = type; | |
this.code = code; | |
this.query = query; | |
} | |
Query.prototype = { | |
search: function() { | |
return grasp.search(this.type, this.query, this.code); | |
}, | |
replace: function(replaceWith) { | |
return grasp.replace(this.type, this.query, replaceWith, this.code); | |
} | |
} | |
var Grasp = function(code) { | |
this.code = code; | |
} | |
Grasp.prototype = { | |
squery: function(query) { | |
return new Query('squery', query, this.code); | |
}, | |
equery: function(query) { | |
return new Query('equery', query, this.code); | |
} | |
}; | |
var result = function(code) { | |
return new Grasp(code); | |
}; | |
result.VERSION = grasp.VERSION; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment