diff --git a/lib/RssBraider.js b/lib/RssBraider.js index 7a519d0..2e656a6 100644 --- a/lib/RssBraider.js +++ b/lib/RssBraider.js @@ -75,7 +75,7 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback) file_path = source.file_path || null, source_articles = []; - logger.debug("Requesting source:" + source.name + " at " + url + " for feed:" + feed_name); + // logger.debug("Requesting source:" + source.name + " at " + url + " for feed:" + feed_name); // todo: Check if source.file is set and set up a fs stream read var feedparser = new FeedParser(); if (url) { @@ -218,7 +218,7 @@ RssBraider.prototype.runPlugins = function (item, itemOptions, source, feed_name for (var i = 0; i < plugins_list.length; i++) { var plugin_name = plugins_list[i]; if (self.plugins[plugin_name]) { - logger.info("DEBUG runPlugins running " + plugin_name + " for item " + item.guid + " in feed: " + feed.meta.title); + // logger.info("DEBUG runPlugins running " + plugin_name + " for item " + item.guid + " in feed: " + feed.meta.title); itemOptions = self.plugins[plugin_name](item, itemOptions, source); } else { logger.error("A plugin named '" + plugin_name + "' hasn't been registered"); @@ -227,10 +227,10 @@ RssBraider.prototype.runPlugins = function (item, itemOptions, source, feed_name // If itemOptions comes back null, skip this item // as one of the plugins decided to toss it if (itemOptions === null) { - logger.info("Plugin rejected item", plugin_name, item.guid, feed.meta.title); + // logger.info("Plugin rejected item", plugin_name, item.guid, feed.meta.title); break; } else { - logger.info("Plugin completed", plugin_name, item.guid, feed.meta.title); + // logger.info("Plugin completed", plugin_name, item.guid, feed.meta.title); } } return itemOptions; diff --git a/lib/example_plugins/filter_all_articles.js b/lib/example_plugins/filter_all_articles.js new file mode 100644 index 0000000..914f9a6 --- /dev/null +++ b/lib/example_plugins/filter_all_articles.js @@ -0,0 +1,9 @@ +module.exports = function (item, itemOptions, source) { + if (!item || !itemOptions) { + return; + } + + // This plugin removes all items by returning null instead of the processed + // itemOptions + return null; +}; \ No newline at end of file diff --git a/lib/example_plugins/plugin_template.js b/lib/example_plugins/plugin_template.js new file mode 100644 index 0000000..daef882 --- /dev/null +++ b/lib/example_plugins/plugin_template.js @@ -0,0 +1,10 @@ +module.exports = function (item, itemOptions, source) { + if (!item || !itemOptions) { + return; + } + + // This plugin does no processing + // It's just a template + + return itemOptions; +}; \ No newline at end of file diff --git a/lib/example_plugins/strip_elements_from_powerpress.js b/lib/example_plugins/strip_elements_from_powerpress.js index 6f826fe..73b8932 100644 --- a/lib/example_plugins/strip_elements_from_powerpress.js +++ b/lib/example_plugins/strip_elements_from_powerpress.js @@ -83,5 +83,4 @@ module.exports = function (item, itemOptions, source) { }); } return itemOptions; - }; \ No newline at end of file diff --git a/package.json b/package.json index 9f50bfa..40905db 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "rss": "git://github.com/rv-kip/node-rss.git#8d1420" }, "devDependencies": { - "tape": "^4.0.0", - "mockdate": "^1.0.3" + "mockdate": "^1.0.3", + "tape": "^4.0.0" } } diff --git a/test/expected_output/emptyFeed.xml b/test/expected_output/emptyFeed.xml new file mode 100644 index 0000000..169bd60 --- /dev/null +++ b/test/expected_output/emptyFeed.xml @@ -0,0 +1,10 @@ + + + + <![CDATA[A Feed with no elements]]> + + http://github.com/dylang/node-rss + rss-braider + Wed, 31 Dec 2014 00:00:01 GMT + + \ No newline at end of file diff --git a/test/feeds/no_elements.js b/test/feeds/no_elements.js new file mode 100644 index 0000000..f066f40 --- /dev/null +++ b/test/feeds/no_elements.js @@ -0,0 +1,18 @@ +var feed = { + "feed_name" : "no_elements", + "plugins" : ['filter_all_articles'], // No articles make it through + "meta" : { + "title" : "A Feed with no elements", + "description" : "This feed will have no elements as a result of the filter_all_articles plugin. Used for unit tests.", + "url" : "http://rss.nytimes.com/services/xml/rss/nyt/Technology.xml", + }, + "sources" : [ + { + "name" : "nyt_tech", + "feed_url" : "http://rss.nytimes.com/services/xml/rss/nyt/Technology.xml", + "count" : 5, + "fullname" : "NYT Technology" + } + ] +}; +exports.feed = feed; \ No newline at end of file diff --git a/test/feeds/sample_feed.js b/test/feeds/sample_feed.js index e9d5e08..8d9d495 100644 --- a/test/feeds/sample_feed.js +++ b/test/feeds/sample_feed.js @@ -16,11 +16,10 @@ var feed = { }, "sources" : [ { - "name" : "sample_feed", + "name" : "sample_source", "count" : 1, "file_path" : __dirname + "/../input_files/sample_feed.xml", - }, - + } ] }; exports.feed = feed; \ No newline at end of file diff --git a/test/index.js b/test/index.js index 8094985..7a8f081 100644 --- a/test/index.js +++ b/test/index.js @@ -111,4 +111,25 @@ test('sort by date asc', function(t) { }); }); +test('filter all articles out using plugin', function(t) { + t.plan(1); + var feeds = {}; + feeds.sample_feed = require("./feeds/no_elements").feed; + var braider_options = { + feeds : feeds, + indent : " ", + date_sort_order : "asc", + plugins_directories : [__dirname + '/../lib/example_plugins/'] + }; + var rss_braider = RssBraider.createClient(braider_options); + + rss_braider.processFeed('sample_feed', 'rss', function(err, data){ + if (err) { + return t.fail(err); + } + console.log(data); + t.equal(data, expectedOutput.emptyFeed); + }); +}); +