-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created image helper with absolute url option
closes #4231 - Adds {{image}} helper - Adds image_spec test unit - Updated {{ghost_head}} to use image helper
- Loading branch information
Showing
6 changed files
with
130 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
// Usage: `{{image}}`, `{{image absolute="true"}}` | ||
// | ||
// Returns the URL for the current object scope i.e. If inside a post scope will return image permalink | ||
// `absolute` flag outputs absolute URL, else URL is relative. | ||
|
||
var Promise = require('bluebird'), | ||
config = require('../config'), | ||
image; | ||
|
||
image = function (options) { | ||
var absolute = options && options.hash.absolute; | ||
if (this.image) { | ||
return Promise.resolve(config.urlFor('image', {image: this.image}, absolute)); | ||
} else { | ||
return Promise.resolve(); | ||
} | ||
}; | ||
|
||
module.exports = image; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*globals describe, before, afterEach, after, it*/ | ||
/*jshint expr:true*/ | ||
var should = require('should'), | ||
sinon = require('sinon'), | ||
hbs = require('express-hbs'), | ||
utils = require('./utils'), | ||
|
||
// Stuff we are testing | ||
handlebars = hbs.handlebars, | ||
helpers = require('../../../server/helpers'); | ||
|
||
describe('{{image}} helper', function () { | ||
var sandbox; | ||
|
||
before(function () { | ||
sandbox = sinon.sandbox.create(); | ||
utils.overrideConfig({url: 'http://testurl.com/'}); | ||
utils.loadHelpers(); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
after(function () { | ||
utils.restoreConfig(); | ||
}); | ||
|
||
it('has loaded image helper', function () { | ||
should.exist(handlebars.helpers.image); | ||
}); | ||
|
||
it('should output relative url of image', function (done) { | ||
helpers.image.call({ | ||
image: '/content/images/image-relative-url.png', | ||
author: { | ||
image: '/content/images/author-image-relatve-url.png' | ||
} | ||
}).then(function (rendered) { | ||
should.exist(rendered); | ||
rendered.should.equal('/content/images/image-relative-url.png'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
it('should output absolute url of image if the option is present ', function (done) { | ||
helpers.image.call({image: '/content/images/image-relative-url.png', | ||
author: {image: '/content/images/author-image-relatve-url.png'}}, | ||
{hash: {absolute: 'true'}}).then(function (rendered) { | ||
should.exist(rendered); | ||
rendered.should.equal('http://testurl.com/content/images/image-relative-url.png'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
it('should have no output if there is no image ', function (done) { | ||
helpers.image.call({image: null}, {hash: {absolute: 'true'}}).then(function (rendered) { | ||
should.not.exist(rendered); | ||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
it('should have no output if there is no image property ', function (done) { | ||
helpers.image.call({}, {hash: {absolute: 'true'}}).then(function (rendered) { | ||
should.not.exist(rendered); | ||
done(); | ||
}).catch(done); | ||
}); | ||
}); |