diff --git a/annotation.mustache b/annotation.mustache index a165d68..f8e189c 100644 --- a/annotation.mustache +++ b/annotation.mustache @@ -7,9 +7,9 @@ {{#hasKey this "_image"}} {{#each this}} {{#hasKey this "href"}} - {{text}} + {{text}} {{else}} - {{text}} + {{text}} {{/hasKey}} {{/each}} {{/hasKey}} diff --git a/index.js b/index.js index 7fc8fee..d8fd805 100644 --- a/index.js +++ b/index.js @@ -10,12 +10,12 @@ function AnnotationPoller (opts) { this.pkg = opts.pkg // what package should we load annotations for? this.endpoint = '/api/v1/annotations/' + this.pkg this.annotations = {} - this.template = Handlebars.templates['annotation.mustache'] + this.template = global.Handlebars.templates['annotation.mustache'] this.addonSelector = '#npm-addon-box' } AnnotationPoller.prototype._installExtensions = function () { - Handlebars.registerHelper('hasKey', function (obj, key, options) { + global.Handlebars.registerHelper('hasKey', function (obj, key, options) { if (typeof obj === 'object' && obj[key]) { return options.fn(this) } else { @@ -23,7 +23,7 @@ AnnotationPoller.prototype._installExtensions = function () { } }) - Handlebars.registerHelper('isArray', function (obj, options) { + global.Handlebars.registerHelper('isArray', function (obj, options) { if ($.isArray(obj)) { return options.fn(this) } else { @@ -123,7 +123,7 @@ AnnotationPoller.prototype._applyReplacements = function (obj) { if (!$.isArray(row.image)) { row.image = [row.image] } - row.image.forEach(function(img) { + row.image.forEach(function (img) { if (img.url) img.url = _this._escape(img.url) if (img.href) img.href = _this._escape(img.href) }) diff --git a/package.json b/package.json index 3c860dd..ab702e3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "build": "handlebars annotation.mustache -f annotation.js", - "pretest": "npm run build", + "pretest": "npm run build; standard", "prepublish": "npm run build", "test": "nyc mocha --timeout=10000 test.js", "coverage": "nyc report --reporter=text-lcov | coveralls", @@ -43,8 +43,8 @@ "handlebars": "^4.0.5", "jquery": "^2.2.2" }, - "ignore": { - "ignore": [ + "nyc": { + "exclude": [ "annotation.js" ] }, diff --git a/test.js b/test.js index ea1a6cc..01a26d4 100644 --- a/test.js +++ b/test.js @@ -79,7 +79,7 @@ describe('annotation-poller', function () { $.mockjax({ url: endpoint, status: 500, - responseText: "ENOGOOD" + responseText: 'ENOGOOD' }) var poller = annotationPoller({pollInterval: 50, pkg: pkg}) @@ -288,8 +288,8 @@ describe('annotation-poller', function () { var poller = annotationPoller({pollInterval: 50, pkg: pkg}) poller.start(function () { - $('.addon-container:last > li > a').length.should.be.equal(0); - $('.addon-container:last > li > img').length.should.be.equal(1); + $('.addon-container:last > li > a').length.should.be.equal(0) + $('.addon-container:last > li > img').length.should.be.equal(1) poller.stop() return done() }) @@ -314,8 +314,8 @@ describe('annotation-poller', function () { var poller = annotationPoller({pollInterval: 50, pkg: pkg}) poller.start(function () { - $('.addon-container:last > li > a').length.should.be.equal(1); - $('.addon-container:last > li > a > img').length.should.be.equal(1); + $('.addon-container:last > li > a').length.should.be.equal(1) + $('.addon-container:last > li > a > img').length.should.be.equal(1) poller.stop() return done() }) @@ -347,10 +347,37 @@ describe('annotation-poller', function () { var poller = annotationPoller({pollInterval: 50, pkg: pkg}) poller.start(function () { - $('.addon-container:last > li > a').length.should.be.equal(2); - $('.addon-container:last > li > a > img').length.should.be.equal(2); - $('.addon-container:last > li > img').length.should.be.equal(1); - $('.addon-container:last > li img').length.should.be.equal(3); + $('.addon-container:last > li > a').length.should.be.equal(2) + $('.addon-container:last > li > a > img').length.should.be.equal(2) + $('.addon-container:last > li > img').length.should.be.equal(1) + $('.addon-container:last > li img').length.should.be.equal(3) + poller.stop() + return done() + }) + }) + + it('respects width and height if provided', function (done) { + $.mockjax({ + url: endpoint, + responseText: [{ + id: 'test-fullsize-images', + name: 'fullsize images', + fingerprint: 'tfi', + rows: [{ + image: { + url: 'http://www.example.com/img1.png', + text: 'my awesome image', + width: '100%', + height: 'auto' + } + }] + }] + }) + + var poller = annotationPoller({pollInterval: 50, pkg: pkg}) + poller.start(function () { + $('.addon-container:last > li > img').length.should.be.equal(1) + $('.addon-container:last > li > img').css('width').should.be.equal('100%') poller.stop() return done() })