1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * Article Component
 */

// Setup options
var xml2js = require('xml2js'),
	componentData = null,
	http = require('http'),
	parser = new xml2js.Parser();

exports.render = function(_data, _callback) {
	// TODO thes values should not be hardcoded
	var options = {
	  host: 'localhost',
	  path: '/Git/AuTi/AuTi/Feeds/article.rss',
	  method: 'GET'
	};

	/**
	 * Render / parse data feed
	 * @param {Object} _newData
	 */
	function parseArticle(_newData) {
		parser.addListener('end', function (result) {
			componentData = result;
			_callback(result);
		});

		parser.parseString(_newData);		
	};
	
	if(componentData) {
		_callback(componentData);
	} else {
		// Get the article content
		var req = http.request(options, function(res) {
			res.setEncoding('utf8');

			res.on('data', function(chunk) {
				parseArticle(chunk);
			});
		});

		req.write('data\n');
		req.end();		
	}
};