2013-12-28 11:01:08 -05:00
|
|
|
/*globals Handlebars, moment, Ghost */
|
2013-07-04 13:42:49 -05:00
|
|
|
(function () {
|
2013-09-24 05:46:30 -05:00
|
|
|
'use strict';
|
2013-12-21 16:43:38 -05:00
|
|
|
Handlebars.registerHelper('date', function (context, options) {
|
|
|
|
if (!options && context.hasOwnProperty('hash')) {
|
|
|
|
options = context;
|
|
|
|
context = undefined;
|
|
|
|
|
|
|
|
// set to published_at by default, if it's available
|
|
|
|
// otherwise, this will print the current date
|
|
|
|
if (this.published_at) {
|
|
|
|
context = this.published_at;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that context is undefined, not null, as that can cause errors
|
|
|
|
context = context === null ? undefined : context;
|
|
|
|
|
|
|
|
var f = options.hash.format || 'MMM Do, YYYY',
|
|
|
|
timeago = options.hash.timeago,
|
2013-07-04 13:42:49 -05:00
|
|
|
date;
|
2013-12-21 16:43:38 -05:00
|
|
|
|
|
|
|
|
2013-07-04 13:42:49 -05:00
|
|
|
if (timeago) {
|
|
|
|
date = moment(context).fromNow();
|
|
|
|
} else {
|
|
|
|
date = moment(context).format(f);
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
});
|
2013-12-28 11:01:08 -05:00
|
|
|
|
2014-02-25 01:44:06 -05:00
|
|
|
Handlebars.registerHelper('admin_url', function () {
|
2014-01-02 19:37:21 -05:00
|
|
|
return Ghost.paths.subdir + '/ghost';
|
2013-12-28 11:01:08 -05:00
|
|
|
});
|
2013-12-27 10:12:24 -05:00
|
|
|
|
|
|
|
Handlebars.registerHelper('asset', function (context, options) {
|
|
|
|
var output = '',
|
|
|
|
isAdmin = options && options.hash && options.hash.ghost;
|
|
|
|
|
|
|
|
output += Ghost.paths.subdir + '/';
|
|
|
|
|
|
|
|
if (!context.match(/^shared/)) {
|
|
|
|
if (isAdmin) {
|
|
|
|
output += 'ghost/';
|
|
|
|
} else {
|
|
|
|
output += 'assets/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output += context;
|
|
|
|
return new Handlebars.SafeString(output);
|
|
|
|
});
|
2013-07-04 13:42:49 -05:00
|
|
|
}());
|