2017-04-24 20:21:47 +03:00
|
|
|
// Usage:
|
|
|
|
// `{{img_url feature_image}}`
|
|
|
|
// `{{img_url profile_image absolute="true"}}`
|
2017-08-27 20:06:53 +03:00
|
|
|
// Note:
|
|
|
|
// `{{img_url}}` - does not work, argument is required
|
2017-04-24 20:21:47 +03:00
|
|
|
//
|
|
|
|
// 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 proxy = require('./proxy'),
|
|
|
|
url = proxy.url;
|
|
|
|
|
|
|
|
module.exports = function imgUrl(attr, options) {
|
2017-08-27 20:06:53 +03:00
|
|
|
// CASE: if no attribute is passed, e.g. `{{img_url}}` we show a warning
|
|
|
|
if (arguments.length < 2) {
|
2017-12-12 00:47:46 +03:00
|
|
|
proxy.logging.warn(proxy.i18n.t('warnings.helpers.img_url.attrIsRequired'));
|
2017-08-27 20:06:53 +03:00
|
|
|
return;
|
2017-04-24 20:21:47 +03:00
|
|
|
}
|
|
|
|
|
2017-08-27 20:06:53 +03:00
|
|
|
var absolute = options && options.hash && options.hash.absolute;
|
2017-04-24 20:21:47 +03:00
|
|
|
|
2017-08-27 20:06:53 +03:00
|
|
|
// CASE: if attribute is passed, but it is undefined, then the attribute was
|
|
|
|
// an unknown value, e.g. {{img_url feature_img}} and we also show a warning
|
2017-04-24 20:21:47 +03:00
|
|
|
if (attr === undefined) {
|
2017-12-12 00:47:46 +03:00
|
|
|
proxy.logging.warn(proxy.i18n.t('warnings.helpers.img_url.attrIsRequired'));
|
2017-08-27 20:06:53 +03:00
|
|
|
return;
|
2017-04-24 20:21:47 +03:00
|
|
|
}
|
|
|
|
|
2017-08-27 20:06:53 +03:00
|
|
|
if (attr) {
|
|
|
|
return url.urlFor('image', {image: attr}, absolute);
|
2017-04-24 20:21:47 +03:00
|
|
|
}
|
2017-11-01 16:44:54 +03:00
|
|
|
|
|
|
|
// CASE: if you pass e.g. cover_image, but it is not set, then attr is null!
|
|
|
|
// in this case we don't show a warning
|
2017-04-24 20:21:47 +03:00
|
|
|
};
|