Browse files

Clean up some misleading API comments. Rename makeAttributeChecker to…

… makeValueChecker given we no longer need to pass in the attribute name
  • Loading branch information...
1 parent 612d568 commit bbb0c25ab5ee861012de663352e9d4c36e39de87 Harry Fuecks committed Oct 3, 2010
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/soupselect.js
View
17 lib/soupselect.js
@@ -2,7 +2,7 @@
Port of Simon Willison's Soup Select http://code.google.com/p/soupselect/
http://www.opensource.org/licenses/mit-license.php
-Right now just a working prototype...
+MIT licensed http://www.opensource.org/licenses/mit-license.php
*/
var domUtils = require("htmlparser").DomUtils;
@@ -22,10 +22,11 @@ var tagRe = /^[a-z0-9]+$/
var attrSelectRe = /^(\w+)?\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/;
/**
-Takes an operator, attribute and optional value; returns a function that
-will return True for elements that match that combination.
+Takes an operator and a value and returns a function which can be used to
+test other values against test provided value using the given operation
+Used to checking attribute values for attribute selectors
*/
-function makeAttributeChecker(operator, attr, value) {
+function makeValueChecker(operator, value) {
value = typeof(value) == 'string' ? value : '';
return operator ? {
@@ -46,6 +47,12 @@ function makeAttributeChecker(operator, attr, value) {
}
+/**
+Takes a dom tree or part of one from htmlparser and applies
+the provided selector against. The returned value is also
+a valid dom tree, so can be passed by into
+htmlparser.DomUtil.* calls
+*/
exports.select = function(dom, selector) {
var currentContext = [dom]
@@ -63,7 +70,7 @@ exports.select = function(dom, selector) {
if ( match ) {
var tag = match[1]; var attribute = match[2]; var operator = match[3]; var value = match[4];
var options = {};
- options[attribute] = makeAttributeChecker(operator, attribute, value);
+ options[attribute] = makeValueChecker(operator, value);
var found = [];
currentContext.forEach(function(context) {

0 comments on commit bbb0c25

Please sign in to comment.