Permalink
Browse files

FIX: Remove the argument "next" from the method signature "operator" …

…pass in argument in scrapinode.use(path,content,operator).

the next argument was a function, it was looking like a callback and it was not a callback but was more like a passthrough operator, this could have lead to problems and uncomprehension.
This feature is now replaced, now if you want to passthrough and so reach another "operator" method, you should return "null" and not call the argument "next" which is now unavailable.
  • Loading branch information...
1 parent 1a7aeeb commit 59e5e3ef797c455659add4ebbd613d07f92cce0a @lbdremy committed Jan 25, 2013
Showing with 21 additions and 35 deletions.
  1. +5 −5 lib/defaults/index.js
  2. +13 −4 lib/router.js
  3. +3 −26 lib/scraper.js
View
@@ -31,7 +31,7 @@ module.exports = exports = [
}
];
-function scrapDescription(window,next){
+function scrapDescription(window){
var $ = window.$;
var url = window.url;
var descriptions = [];
@@ -95,13 +95,13 @@ var validExtension = (function(){
*
*/
-function scrapImage(window,next){
+function scrapImage(window){
var $ = window.$;
var url = window.url;
var thumbs = [];
var thumbsRejected = [];
- var title = scrapTitle(window,next);
+ var title = scrapTitle(window);
var addToThumbs = function(image,beginning){
var src = $(image).attr('src');
if(src && validExtension(src) ){
@@ -167,7 +167,7 @@ function scrapImage(window,next){
*
*/
-function scrapTitle(window,next){
+function scrapTitle(window){
var $ = window.$;
var url = window.url;
@@ -203,7 +203,7 @@ function scrapTitle(window,next){
*
*/
-function scrapVideo(window,next){
+function scrapVideo(window){
var $ = window.$;
var url = window.url;
var thumbs = [];
View
@@ -50,16 +50,25 @@ Router.prototype.dispatch = function(url,content,from){
for(var i = from; i < this.routes.length;i++){
var route = this.routes[i];
if(route.match(url,content)){
- return {
+ var result = {
to : i + 1,
operation : route.operation
};
+ return result;
}
}
- return {
+ var self = this;
+ var defaultResult = {
to : this.routes.length,
- operation : function(window,next){
- next(new ScrapinodeError('No operations found for url: ' + url + ' and content: ' + content));
+ operation : function(window){
+ var message = 'Dead end, no content found and no more route.';
+ var infos = {
+ url : url,
+ content : content,
+ routes : self.routes
+ };
+ throw new ScrapinodeError(message + 'Informations: ' + JSON.stringify(infos));
}
};
+ return defaultResult;
}
View
@@ -30,31 +30,8 @@ function Scraper(url,window,router){
Scraper.prototype.get = function(content,from) {
var self = this;
from = from || 0;
- var completed = true;
var result = this.router.dispatch(this.url,content,from);
- var trouvaille = result.operation(this.window,
- function next(err){
- if(err) throw err;
- completed = false;
- }
- );
- if(!completed) return self.get(content,result.to);
+ var trouvaille = result.operation(this.window);
+ if(trouvaille === null) return self.get(content,result.to);
return trouvaille;
-};
-
-/**
-Scraper.prototype.getAsync = function(content,from,callback){
- var self = this;
- if(typeof(from) === 'function'){
- callback = from;
- from = 0;
- }
- var result = this.router.dispatch(this.url,content,from);
- result.operation(this.window,
- function next(err){
- if(err) return callback(err);
- self.getAsync(content,result.to,callback);
- }
- );
-}
-**/
+};

0 comments on commit 59e5e3e

Please sign in to comment.