Permalink
Browse files

Reorganise into package structure

  • Loading branch information...
1 parent fa22a62 commit d9107142bfe638bc0751fc3401829ef4ee0ba680 Harry Fuecks committed Oct 1, 2010
Showing with 35 additions and 21 deletions.
  1. +6 −0 .gitmodules
  2. +1 −0 deps/htmlparser
  3. +1 −0 deps/nodeunit
  4. +1 −21 { → lib}/soupselect.js
  5. +26 −0 tests/soupselect.js
View
@@ -0,0 +1,6 @@
+[submodule "deps/nodeunit"]
+ path = deps/nodeunit
+ url = git://github.com/caolan/nodeunit.git
+[submodule "deps/htmlparser"]
+ path = deps/htmlparser
+ url = http://github.com/tautologistics/node-htmlparser.git
Submodule htmlparser added at 8e538e
Submodule nodeunit added at 42e2e9
@@ -50,7 +50,7 @@ function makeAttributeChecker(operator, attr, value) {
}[operator];
}
-function select(dom, selector) {
+exports.select = function(dom, selector) {
var currentContext = [dom]
var tokens = selector.split(/\s+/);
@@ -133,23 +133,3 @@ function select(dom, selector) {
return currentContext;
}
-
-var html = "<a class='y'>text a</a><b id='x'>text b</b><c class='y'>text c</c><d id='z' class='w'><e>text e</e></d><g>bogus</g><g class='g h i'>hhh</g><g class='h'>foo</g>";
-
-var handler = new htmlparser.DefaultHandler(function(err, dom) {
- if (err) {
- sys.debug("Error: " + err);
- } else {
- sys.puts("a : " + sys.inspect(select(dom, 'a')));
- sys.puts("g : " + sys.inspect(select(dom, 'g')));
- sys.puts("g.h : " + sys.inspect(select(dom, 'g.h')));
- sys.puts("g[class=h] : " + sys.inspect(select(dom, 'g[class=h]'))); // ISSUES
- sys.puts("g[class~=h] : " + sys.inspect(select(dom, 'g[class~=h]'))); // ISSUES
- sys.puts("#x : " + sys.inspect(select(dom, '#x')));
- sys.puts("* : " + sys.inspect(select(dom, '*')));
- sys.puts("g* : " + sys.inspect(select(dom, 'g *')));
- }
-});
-
-var parser = new htmlparser.Parser(handler);
-parser.parseComplete(html);
View
@@ -0,0 +1,26 @@
+var soupselect = require('soupselect'),
+ nodeunit = require('nodeunit'),
+ htmlparser = require("htmlparser")
+ sys = require('sys');
+
+var select = soupselect.select;
+
+var html = "<a class='y'>text a</a><b id='x'>text b</b><c class='y'>text c</c><d id='z' class='w'><e>text e</e></d><g>bogus</g><g class='g h i'>hhh</g><g class='h'>foo</g>";
+
+var handler = new htmlparser.DefaultHandler(function(err, dom) {
+ if (err) {
+ sys.debug("Error: " + err);
+ } else {
+ sys.puts("a : " + sys.inspect(select(dom, 'a')));
+ sys.puts("g : " + sys.inspect(select(dom, 'g')));
+ sys.puts("g.h : " + sys.inspect(select(dom, 'g.h')));
+ sys.puts("g[class=h] : " + sys.inspect(select(dom, 'g[class=h]'))); // ISSUES
+ sys.puts("g[class~=h] : " + sys.inspect(select(dom, 'g[class~=h]'))); // ISSUES
+ sys.puts("#x : " + sys.inspect(select(dom, '#x')));
+ sys.puts("* : " + sys.inspect(select(dom, '*')));
+ sys.puts("g* : " + sys.inspect(select(dom, 'g *')));
+ }
+});
+
+var parser = new htmlparser.Parser(handler);
+parser.parseComplete(html);

0 comments on commit d910714

Please sign in to comment.