Permalink
Browse files

Update Readme, added examples

  • Loading branch information...
1 parent 4d96be5 commit 1ee17122b82335703c2404e4109bf61e1bfa67b6 @silentrob committed Jul 25, 2010
Showing with 118 additions and 67 deletions.
  1. +56 −2 README.md
  2. +62 −0 examples.js
  3. +0 −65 test.js
View
@@ -1,9 +1,63 @@
Apricot
===
-Apricot is a HTML / DOM parser, scraper for Nodejs. It is inspired by rubys hpricot. It is designed to fetch, iterate, and augment html or html fragments.
+Apricot is a HTML / DOM parser, scraper for Nodejs.
+It is inspired by [rubys hpricot](http://github.com/whymirror/hpricot) and designed to fetch, iterate, and augment html or html fragments.
-LICENSE
+Apricot requires [JSDom](http://github.com/tmpvar/jsdom)
+
+ npm install jsdom
+
+Getting Started
+---
+ Apricot.parse("<p id='test'>An HTML Fragment</p>", function(doc) {
+ // Do something awesome here..
+ });
+
+ // OR Open a remote website, or local file
+
+ Apricot.open("http://my_awesome_website.com", function(doc) {
+ // Do something awesome here..
+ });
+
+
+Packed with Awesomeness (API)
+---
+
+Parse and Open both return a Apricot Object, a HTML DOM, created by JSDOM, with all the power of the [Sizzle Selector Engine](http://wiki.github.com/jeresig/sizzle/), and [XUI Framework](http://github.com/silentrob/xui) for Augmentation.
+
+ Apricot.parse("<p id='test'>An HTML Fragment</p>", function(doc) {
+ doc.find("selector"); // Populates internal collection, See Sizzle selector syntax (rules)
+ doc.each(callback); // Itterates over the collection, applying a callback to each match (element)
+ doc.remove(); // Removes all elements in the internal collection (See XUI Syntax)
+
+ doc.inner("fragment"); // See XUI Syntax
+ doc.outer("fragment"); // See XUI Syntax
+ doc.top("fragment"); // See XUI Syntax
+ doc.bottom("fragment"); // See XUI Syntax
+ doc.before("fragment"); // See XUI Syntax
+ doc.after("fragment"); // See XUI Syntax
+ doc.hasClass("class"); // See XUI Syntax
+ doc.addClass("class"); // See XUI Syntax
+ doc.removeClass("class"); // See XUI Syntax
+
+ doc.toHTML; // Returns the HTML
+ doc.innerHTML; // Returns the innerHTML of the body.
+ doc.toDOM; // Returns the DOM representation
+
+ // Most methods are chainable, so this works
+ doc.find("selector").addClass('foo').after(", just because");
+
+ });
+
+
+TODO
+---
+* Cleanup Code, hide privates, etc.
+* Tests
+* Add Package
+
+LICENSE (MIT)
---
_Copyright (c) 2010 Rob Ellis_
View
@@ -0,0 +1,62 @@
+Apricot = require('./lib/apricot').Apricot;
+
+// Use Case one
+console.log("UC 1");
+
+
+Apricot.parse("<p id='test'>A simple <b>test</b> string. <b>Nothing to worry about</b></p>", function(doc) {
+ doc.find('b');
+ doc.remove();
+ console.log(doc.toHTML);
+});
+
+Apricot.parse("That's my <b id='test'>spoon</b> Tyler.", function(doc) {
+ doc.find('b').inner("food");
+ console.log(doc.toHTML);
+
+});
+
+Apricot.open("test.html", function(doc){
+ doc.find('p');
+ // el is the html Element found by find.
+ doc.each(function(el){
+ console.log(el.innerHTML);
+ })
+
+});
+
+Apricot.open("test.html", function(doc){
+ doc.find('span').removeClass('hot');
+ doc.find('li').addClass('list_item').addClass('main_list');
+ console.log(doc.toHTML);
+
+});
+
+// Another Example of looping
+Apricot.open('http://www.joyent.com/', function(doc){
+ console.log("Looping 2");
+ doc.find('a');
+
+ var links = [];
+
+ doc.each(function(el){
+ links.push(el.href);
+ })
+
+ console.log((links.unique()).join('\n\r'));
+
+});
+
+
+Array.prototype.unique = function () {
+ var r = new Array();
+ o:for(var i = 0, n = this.length; i < n; i++) {
+ for(var x = 0, y = r.length; x < y; x++) {
+ if(r[x]==this[i]) {
+ continue o;
+ }
+ }
+ r[r.length] = this[i];
+ }
+ return r;
+}
View
65 test.js
@@ -1,65 +0,0 @@
-Apricot = require('./lib/apricot').Apricot;
-sys = require('sys');
-
-// Use Case one
-// console.log("UC 1");
-//
-
-// Apricot.parse("<p id='test'>A simple <b>test</b> string. <b>Nothing to worry about</b></p>", function(doc) {
-// doc.find('b');
-// doc.remove();
-// console.log(doc.toHTML);
-// });
-
-// Apricot.parse("That's my <b id='test'>spoon</b> Tyler.", function(doc) {
-// doc.find('b').inner("food");
-// console.log(doc.toHTML);
-//
-// });
-
-// Apricot.open("test.html", function(doc){
-// doc.find('p');
-// // el is the html Element found by find.
-// doc.each(function(el){
-// console.log(el.innerHTML);
-// })
-//
-// });
-
-Apricot.open("test.html", function(doc){
- doc.find('span').removeClass('hot');
- doc.find('li').addClass('list_item').addClass('main_list');
- console.log(doc.toHTML);
-
-});
-
-
-
-// Another Example of looping
-// Apricot.open('http://www.joyent.com/', function(doc){
-// console.log("Looping 2");
-// doc.find('a');
-//
-// var links = [];
-//
-// doc.each(function(el){
-// links.push(el.href);
-// })
-//
-// console.log((links.unique()).join('\n\r'));
-//
-// });
-//
-//
-// Array.prototype.unique = function () {
-// var r = new Array();
-// o:for(var i = 0, n = this.length; i < n; i++) {
-// for(var x = 0, y = r.length; x < y; x++) {
-// if(r[x]==this[i]) {
-// continue o;
-// }
-// }
-// r[r.length] = this[i];
-// }
-// return r;
-// }

0 comments on commit 1ee1712

Please sign in to comment.