Skip to content

Commit

Permalink
build out documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed May 31, 2015
1 parent 7709e08 commit 2603c0b
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 300 deletions.
362 changes: 87 additions & 275 deletions Readme.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions examples/array-of-arrays.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul class="tags">
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
<ul class="tags">
<li>d</li>
<li>e</li>
</ul>
8 changes: 8 additions & 0 deletions examples/array-of-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var read = require('fs').readFileSync;
var html = read(__dirname + '/array-of-arrays.html');
var Xray = require('..');
var x = Xray()

x(html, '.tags', [['li']])(function(err, arr) {
console.log(arr);
});
5 changes: 5 additions & 0 deletions examples/arrays.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
<a href="http://google.com">Google</a>
<a href="http://facebook.com">Facebook</a>
<a href="http://twitter.com">Twitter</a>
</body>
8 changes: 8 additions & 0 deletions examples/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var read = require('fs').readFileSync;
var html = read(__dirname + '/arrays.html');
var Xray = require('..');
var x = Xray()

x(html, ['a'])(function(err, arr) {
console.log(arr);
})
17 changes: 17 additions & 0 deletions examples/collection-of-collections.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="items">
<div class="item">
<h2>first item</h2>
<ul class="tags">
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</div>
<div class="item">
<h2>second item</h2>
<ul class="tags">
<li>d</li>
<li>e</li>
</ul>
</div>
</div>
11 changes: 11 additions & 0 deletions examples/collection-of-collections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var read = require('fs').readFileSync;
var html = read(__dirname + '/collection-of-collections.html');
var Xray = require('..');
var x = Xray()

x(html, '.item', [{
title: 'h2',
tags: x('.tags', ['li'])
}])(function(err, arr) {
console.log(arr);
});
7 changes: 7 additions & 0 deletions examples/collections.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h2 class="title">first item</h2>
<img src="item.png">
<ul class="tags">
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
12 changes: 12 additions & 0 deletions examples/collections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var read = require('fs').readFileSync
var html = read(__dirname + '/collections.html')
var Xray = require('..')
var x = Xray()

x(html, {
title: '.title',
image: 'img@src',
tags: ['li']
})(function(err, obj) {
console.log(obj);
})
21 changes: 0 additions & 21 deletions examples/github-stars.js

This file was deleted.

1 change: 1 addition & 0 deletions examples/selector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>header two</h2>
8 changes: 8 additions & 0 deletions examples/selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var read = require('fs').readFileSync
var html = read(__dirname + '/selector.html')
var Xray = require('..')
var x = Xray()

x(html, 'h2')(function(err, title) {
console.log(title);
})
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var error = require('debug')('x-ray:error');
* Crawler methods
*/

var methods = [ 'concurrency', 'throttle', 'timeout', 'driver', 'delay' ];
var methods = [ 'concurrency', 'throttle', 'timeout', 'driver', 'delay', 'limit'];

/**
* Export
Expand Down
2 changes: 1 addition & 1 deletion lib/is-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = isHTML;
*/

function isHTML(str) {
str = (str || '').trim();
str = (str || '').toString().trim();
return '<' == str[0]
&& '>' == str[str.length - 1];
}
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var Xray = require('./');
var x = Xray();

x('http://google.com', {
main: 'title',
image: x('https://images.google.com', 'title')
})(function(err, obj) {
console.log(obj); // => { main: 'Google', image: 'Google Images' }
})
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ describe('Xray()', function() {
var $ = cheerio.load(html);
var x = Xray();

x('.item', [{
x($, '.item', [{
title: 'h2',
tags: x('.tags', ['li'])
}])($, function(err, arr) {
}])(function(err, arr) {
if (err) return done(err);
assert.deepEqual([
{ title: 'first item', tags: [ 'a', 'b', 'c' ] },
Expand Down

0 comments on commit 2603c0b

Please sign in to comment.