Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #136 from Financial-Times/set-article-body
Browse files Browse the repository at this point in the history
Set property directly, rather than using defineProperty
  • Loading branch information
ironsidevsquincy committed Jun 2, 2015
2 parents ba6116c + 6513951 commit 4418d7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ script:
- make test
node_js:
- '0.10'
- '0.12'
- '0.12.2'
before_deploy:
- npm-prepublish --verbose
deploy:
Expand Down
33 changes: 13 additions & 20 deletions lib/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ Article.prototype.parse = function (obj) {
this.id = obj.item.id;
this.raw = obj;

if (!this.raw.item.body) return;
if (this.raw.item.body) {
var html = this.raw.item.body.body;
try {
this.body = dom.removeNonArticleLinks(dom.fixRelativeLinks(dom.removeEmptyParagraphs(html)));
} catch (e) {
this.body = '<p>Error parsing this article.</p>';
}
} else {
this.body = '';
}
};

/**
Expand All @@ -38,6 +47,9 @@ Article.prototype.paragraphs = function (to, from, options) {
return $('p').slice(to, from);
};

// TODO: move the following out of defineProperty and just set `this` directly
// https://github.com/Financial-Times/ft-api-client/pull/136

/**
* Returns a list of inbound links to other FT articles contained within the article body
*/
Expand Down Expand Up @@ -469,25 +481,6 @@ Object.defineProperty(Article.prototype, 'quotes', {
}
});

/**
* The article body as HTML.
*/
Object.defineProperty(Article.prototype, 'body', {
get: function () {

var html = this.raw.item.body.body;

try {
return dom.removeNonArticleLinks(dom.fixRelativeLinks(dom.removeEmptyParagraphs(html)));
} catch (e) {
// console.error('Error parsing article body', e);
return '<p>Error parsing this article.</p>';
}


}
});

/**
* The largest image (ie. in pixels) that is associated with the resource
*/
Expand Down

0 comments on commit 4418d7b

Please sign in to comment.