cheerio
Advanced tools
Comparing version 0.12.1 to 0.12.2
0.12.2 / 2013-09-04 | ||
================== | ||
* Correct implementation of `$.fn.text` (@jugglinmike) | ||
* Refactor Cheerio array creation (@jugglinmike) | ||
* Extend manipulation methods to accept Arrays (@jugglinmike) | ||
* support .attr(attributeName, function(index, attr)) (@xiaohwan) | ||
0.12.1 / 2013-07-30 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -27,2 +27,7 @@ var _ = require('underscore'), | ||
if (typeof name === 'object' || value !== undefined) { | ||
if (_.isFunction(value)) { | ||
return this.each(function(i, el) { | ||
setAttr(el, name, value.call(this, i, el.attribs[name])); | ||
}); | ||
} | ||
return this.each(function(i, el) { | ||
@@ -29,0 +34,0 @@ el.attribs = setAttr(el, name, value); |
@@ -14,5 +14,11 @@ var _ = require('underscore'), | ||
var makeCheerioArray = function(elems) { | ||
return _.reduce(elems, function(dom, elem) { | ||
return dom.concat(elem.cheerio ? elem.toArray() : evaluate(elem)); | ||
}, []); | ||
return _.chain(elems).map(function(elem) { | ||
if (elem.cheerio) { | ||
return elem.toArray(); | ||
} else if (!_.isArray(elem)) { | ||
return evaluate(elem); | ||
} else { | ||
return elem; | ||
} | ||
}).flatten().value(); | ||
}; | ||
@@ -113,3 +119,3 @@ | ||
var replaceWith = exports.replaceWith = function(content) { | ||
content = content.cheerio ? content.toArray() : evaluate(content); | ||
content = makeCheerioArray([content]); | ||
@@ -162,4 +168,4 @@ this.each(function(i, el) { | ||
var text = exports.text = function(str) { | ||
// If `str` blank or an object | ||
if (!str || typeof str === 'object') { | ||
// If `str` is undefined, act as a "getter" | ||
if (str === undefined) { | ||
return $.text(this); | ||
@@ -166,0 +172,0 @@ } else if (_.isFunction(str)) { |
@@ -6,3 +6,3 @@ { | ||
"keywords": ["htmlparser", "jquery", "selector", "scraper"], | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -602,28 +602,36 @@ # cheerio [![Build Status](https://secure.travis-ci.org/MatthewMueller/cheerio.png?branch=master)](http://travis-ci.org/MatthewMueller/cheerio) | ||
project : cheerio | ||
repo age : 1 year, 7 months ago | ||
commits : 474 | ||
active : 141 days | ||
files : 27 | ||
repo age : 1 year, 10 months | ||
active : 169 days | ||
commits : 513 | ||
files : 28 | ||
authors : | ||
286 Matt Mueller 60.3% | ||
80 Matthew Mueller 16.9% | ||
42 David Chambers 8.9% | ||
15 Siddharth Mahendraker 3.2% | ||
7 Adam Bretz 1.5% | ||
7 ironchefpython 1.5% | ||
6 Mike Pennisi 1.3% | ||
5 Jos Shepherd 1.1% | ||
5 Ryan Schmukler 1.1% | ||
5 Ben Sheldon 1.1% | ||
3 jeremy.dentel 0.6% | ||
292 Matt Mueller 56.9% | ||
86 Matthew Mueller 16.8% | ||
44 David Chambers 8.6% | ||
15 Siddharth Mahendraker 2.9% | ||
13 Mike Pennisi 2.5% | ||
11 Adam Bretz 2.1% | ||
7 ironchefpython 1.4% | ||
5 Ryan Schmukler 1.0% | ||
5 Ben Sheldon 1.0% | ||
5 Jos Shepherd 1.0% | ||
4 Maciej Adwent 0.8% | ||
3 jeremy.dentel@brandingbrand.com 0.6% | ||
2 Felix Böhm 0.4% | ||
2 Ali Farhadi 0.4% | ||
2 Chris Khoo 0.4% | ||
2 Wayne Larsen 0.4% | ||
2 alexbardas 0.4% | ||
2 Rob Ashton 0.4% | ||
2 Wayne Larsen 0.4% | ||
1 mattym 0.2% | ||
1 nevermind 0.2% | ||
1 Felix Böhm 0.2% | ||
1 Jeremy Hubble 0.2% | ||
1 Manuel Alabor 0.2% | ||
1 Matt Liegey 0.2% | ||
1 Ben Atkin 0.2% | ||
1 Chris O'Hara 0.2% | ||
1 Felix Böhm 0.2% | ||
1 Rob "Hurricane" Ashton 0.2% | ||
1 Simon Boudrias 0.2% | ||
1 Sindre Sorhus 0.2% | ||
1 mattym 0.2% | ||
1 Chris O'Hara 0.2% | ||
``` | ||
@@ -630,0 +638,0 @@ |
@@ -53,2 +53,13 @@ var expect = require('expect.js'); | ||
it('(key, function) : should call the function and update the attribute with the return value', function() { | ||
var $fruits = $(fruits); | ||
$fruits.attr('id', function(index, value) { | ||
expect(index).to.equal(0); | ||
expect(value).to.equal('fruits'); | ||
return 'ninja'; | ||
}); | ||
var attrs = $fruits.attr(); | ||
expect(attrs.id).to.equal('ninja'); | ||
}); | ||
it('(key, value) : should correctly encode then decode unsafe values', function() { | ||
@@ -55,0 +66,0 @@ var $apple = $('.apple', fruits); |
@@ -35,2 +35,11 @@ var expect = require('expect.js'), | ||
it('(Array) : should append all elements in the array', function() { | ||
var $fruits = $(fruits); | ||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>') | ||
.toArray(); | ||
$fruits.append(more); | ||
expect($fruits.children(3).hasClass('plum')).to.be.ok(); | ||
expect($fruits.children(4).hasClass('grape')).to.be.ok(); | ||
}); | ||
it('(fn) : should add returned element as last child'); | ||
@@ -68,2 +77,11 @@ | ||
it('(Array) : should add all elements in the array as inital children', function() { | ||
var $fruits = $(fruits); | ||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>') | ||
.toArray(); | ||
$fruits.prepend(more); | ||
expect($fruits.children(0).hasClass('plum')).to.be.ok(); | ||
expect($fruits.children(1).hasClass('grape')).to.be.ok(); | ||
}); | ||
it('(html, $(...), html) : should add multiple elements as first children', function() { | ||
@@ -95,2 +113,11 @@ var $fruits = $(fruits); | ||
it('(Array) : should add all elements in the array as next sibling', function() { | ||
var $fruits = $(fruits); | ||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>') | ||
.toArray(); | ||
$('.apple', $fruits).after(more); | ||
expect($fruits.children(1).hasClass('plum')).to.be.ok(); | ||
expect($fruits.children(2).hasClass('grape')).to.be.ok(); | ||
}); | ||
it('($(...)) : should add element as next sibling', function() { | ||
@@ -136,2 +163,11 @@ var $fruits = $(fruits); | ||
it('(Array) : should add all elements in the array as previous sibling', function() { | ||
var $fruits = $(fruits); | ||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>') | ||
.toArray(); | ||
$('.apple', $fruits).before(more); | ||
expect($fruits.children(0).hasClass('plum')).to.be.ok(); | ||
expect($fruits.children(1).hasClass('grape')).to.be.ok(); | ||
}); | ||
it('($(...), html) : should add multiple elements as previous siblings', function() { | ||
@@ -176,2 +212,12 @@ var $fruits = $(fruits); | ||
it('(Array) : should replace one <li> tag with the elements in the array', function() { | ||
var $fruits = $(fruits); | ||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>') | ||
.toArray(); | ||
$('.pear', $fruits).replaceWith(more); | ||
expect($fruits.children(2).hasClass('plum')).to.be.ok(); | ||
expect($fruits.children(3).hasClass('grape')).to.be.ok(); | ||
}); | ||
it('(elem) : should replace the selected element with given element', function() { | ||
@@ -305,2 +351,21 @@ var $src = $('<ul></ul>'); | ||
it('( undefined ) : should act as an accessor', function() { | ||
var $div = $('<div>test</div>'); | ||
expect($div.text(undefined)).to.be.a('string'); | ||
expect($div.text()).to.be('test'); | ||
}); | ||
it('( "" ) : should convert to string', function() { | ||
var $div = $('<div>test</div>'); | ||
expect($div.text('').text()).to.equal(''); | ||
}); | ||
it('( null ) : should convert to string', function() { | ||
expect($('<div>').text(null).text()).to.equal('null'); | ||
}); | ||
it('( 0 ) : should convert to string', function() { | ||
expect($('<div>').text(0).text()).to.equal('0'); | ||
}); | ||
it('(str) should encode then decode unsafe characters', function() { | ||
@@ -307,0 +372,0 @@ var $apple = $('.apple', fruits); |
121070
2492
675