2013-05-11 20:44:25 +04:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var _ = require('underscore'),
|
|
|
|
moment = require('moment'),
|
2013-05-27 23:27:41 +04:00
|
|
|
when = require('when'),
|
|
|
|
navHelper = require('./ghostNav'),
|
2013-05-11 20:44:25 +04:00
|
|
|
coreHelpers;
|
|
|
|
|
|
|
|
coreHelpers = function (ghost) {
|
|
|
|
/**
|
|
|
|
* [ description]
|
|
|
|
* @todo ghost core helpers + a way for themes to register them
|
|
|
|
* @param {Object} context date object
|
|
|
|
* @param {*} block
|
|
|
|
* @return {Object} A Moment time / date object
|
|
|
|
*/
|
|
|
|
ghost.registerThemeHelper('dateFormat', function (context, block) {
|
|
|
|
var f = block.hash.format || "MMM Do, YYYY";
|
|
|
|
return moment(context).format(f);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [ description]
|
|
|
|
*
|
|
|
|
* @param String key
|
|
|
|
* @param String default translation
|
|
|
|
* @param {Object} options
|
|
|
|
* @return String A correctly internationalised string
|
|
|
|
*/
|
|
|
|
ghost.registerThemeHelper('e', function (key, defaultString, options) {
|
|
|
|
var output;
|
|
|
|
|
|
|
|
if (ghost.config().defaultLang === 'en' && _.isEmpty(options.hash) && !ghost.config().forceI18n) {
|
|
|
|
output = defaultString;
|
|
|
|
} else {
|
|
|
|
output = ghost.polyglot().t(key, options.hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
});
|
|
|
|
|
2013-06-09 20:45:17 +04:00
|
|
|
ghost.registerThemeHelper('json', function (object, options) {
|
|
|
|
return JSON.stringify(object);
|
|
|
|
});
|
|
|
|
|
2013-05-27 23:27:41 +04:00
|
|
|
return when.all([
|
|
|
|
// Just one async helper for now, but could be more in the future
|
|
|
|
navHelper.registerWithGhost(ghost)
|
|
|
|
]);
|
2013-05-11 20:44:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.loadCoreHelpers = coreHelpers;
|
|
|
|
}());
|
|
|
|
|