mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
commit
d1db0db073
5 changed files with 68 additions and 15 deletions
|
@ -97,6 +97,18 @@ Ghost = function () {
|
||||||
// there's no management here to be sure this has loaded
|
// there's no management here to be sure this has loaded
|
||||||
settings: function () { return instance.settingsCache; },
|
settings: function () { return instance.settingsCache; },
|
||||||
dataProvider: models,
|
dataProvider: models,
|
||||||
|
blogGlobals: function () {
|
||||||
|
/* this is a bit of a hack until we have a better way to combine settings and config
|
||||||
|
* this data is what becomes globally available to themes */
|
||||||
|
return {
|
||||||
|
url: instance.config().env[process.env.NODE_ENV].url,
|
||||||
|
title: instance.settings().title,
|
||||||
|
description: instance.settings().description,
|
||||||
|
logo: instance.settings().logo,
|
||||||
|
/* urg.. need to fix paths */
|
||||||
|
themedir: path.join('/content/themes', instance.paths().activeTheme, instance.settingsCache.activeTheme)
|
||||||
|
};
|
||||||
|
},
|
||||||
statuses: function () { return statuses; },
|
statuses: function () { return statuses; },
|
||||||
polyglot: function () { return polyglot; },
|
polyglot: function () { return polyglot; },
|
||||||
getPaths: function () {
|
getPaths: function () {
|
||||||
|
@ -296,27 +308,29 @@ Ghost.prototype.initPlugins = function (pluginsToLoad) {
|
||||||
|
|
||||||
// Initialise Theme or admin
|
// Initialise Theme or admin
|
||||||
Ghost.prototype.initTheme = function (app) {
|
Ghost.prototype.initTheme = function (app) {
|
||||||
var self = this;
|
var self = this,
|
||||||
|
hbsOptions;
|
||||||
return function initTheme(req, res, next) {
|
return function initTheme(req, res, next) {
|
||||||
app.set('view engine', 'hbs');
|
app.set('view engine', 'hbs');
|
||||||
// return the correct mime type for woff files
|
// return the correct mime type for woff files
|
||||||
express['static'].mime.define({'application/font-woff': ['woff']});
|
express['static'].mime.define({'application/font-woff': ['woff']});
|
||||||
|
|
||||||
if (!res.isAdmin) {
|
if (!res.isAdmin) {
|
||||||
|
|
||||||
|
// self.globals is a hack til we have a better way of getting combined settings & config
|
||||||
|
hbsOptions = {templateOptions: {data: {blog: self.blogGlobals()}}};
|
||||||
|
|
||||||
if (!self.themeDirectories.hasOwnProperty(self.settings().activeTheme)) {
|
if (!self.themeDirectories.hasOwnProperty(self.settings().activeTheme)) {
|
||||||
// Throw an error if the theme is not available...
|
// Throw an error if the theme is not available...
|
||||||
// TODO: move this to happen on app start
|
// TODO: move this to happen on app start
|
||||||
errors.logAndThrowError('The currently active theme ' + self.settings().activeTheme + ' is missing.');
|
errors.logAndThrowError('The currently active theme ' + self.settings().activeTheme + ' is missing.');
|
||||||
} else if (self.themeDirectories[self.settings().activeTheme].hasOwnProperty('partials')) {
|
} else if (self.themeDirectories[self.settings().activeTheme].hasOwnProperty('partials')) {
|
||||||
// Check that the theme has a partials directory before trying to use it
|
// Check that the theme has a partials directory before trying to use it
|
||||||
app.engine('hbs', hbs.express3(
|
hbsOptions.partialsDir = path.join(self.paths().activeTheme, 'partials');
|
||||||
{partialsDir: path.join(self.paths().activeTheme, 'partials')}
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
// No partial dir, so no need to configure it
|
|
||||||
app.engine('hbs', hbs.express3());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.engine('hbs', hbs.express3(hbsOptions));
|
||||||
|
|
||||||
app.set('views', self.paths().activeTheme);
|
app.set('views', self.paths().activeTheme);
|
||||||
} else {
|
} else {
|
||||||
app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + 'partials'}));
|
app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + 'partials'}));
|
||||||
|
|
|
@ -20,9 +20,22 @@ coreHelpers = function (ghost) {
|
||||||
* @return {Object} A Moment time / date object
|
* @return {Object} A Moment time / date object
|
||||||
*/
|
*/
|
||||||
ghost.registerThemeHelper('date', function (context, options) {
|
ghost.registerThemeHelper('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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var f = options.hash.format || "MMM Do, YYYY",
|
var f = options.hash.format || "MMM Do, YYYY",
|
||||||
timeago = options.hash.timeago,
|
timeago = options.hash.timeago,
|
||||||
date;
|
date;
|
||||||
|
|
||||||
|
|
||||||
if (timeago) {
|
if (timeago) {
|
||||||
date = moment(context).fromNow();
|
date = moment(context).fromNow();
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,11 +44,25 @@ coreHelpers = function (ghost) {
|
||||||
return date;
|
return date;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ### URL helper
|
||||||
|
//
|
||||||
|
// *Usage example:*
|
||||||
|
// `{{url}}`
|
||||||
|
// `{{url absolute}}`
|
||||||
|
//
|
||||||
|
// Returns the URL for the current object context
|
||||||
|
// i.e. If inside a post context will return post permalink
|
||||||
|
// absolute flag outputs absolute URL, else URL is relative
|
||||||
ghost.registerThemeHelper('url', function (context, options) {
|
ghost.registerThemeHelper('url', function (context, options) {
|
||||||
if (models.isPost(this)) {
|
var output = '';
|
||||||
return "/" + this.slug;
|
|
||||||
|
if (options && options.absolute) {
|
||||||
|
output += ghost.config().env[process.NODE_ENV].url;
|
||||||
}
|
}
|
||||||
return '';
|
if (models.isPost(this)) {
|
||||||
|
output += "/" + this.slug;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
});
|
});
|
||||||
|
|
||||||
// ### Author Helper
|
// ### Author Helper
|
||||||
|
|
|
@ -45,6 +45,20 @@ User = GhostBookshelf.Model.extend({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
parse: function (attrs) {
|
||||||
|
// temporary alias of name for full_name (will get changed in the schema)
|
||||||
|
if (attrs.full_name && !attrs.name) {
|
||||||
|
attrs.name = attrs.full_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// temporary alias of website for url (will get changed in the schema)
|
||||||
|
if (attrs.url && !attrs.website) {
|
||||||
|
attrs.website = attrs.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attrs;
|
||||||
|
},
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.on('saving', this.saving, this);
|
this.on('saving', this.saving, this);
|
||||||
this.on('saving', this.validate, this);
|
this.on('saving', this.validate, this);
|
||||||
|
|
6
index.js
6
index.js
|
@ -108,10 +108,8 @@ function ghostLocals(req, res, next) {
|
||||||
if (!res.isAdmin) {
|
if (!res.isAdmin) {
|
||||||
// filter the navigation items
|
// filter the navigation items
|
||||||
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
||||||
// pass the theme navigation items and settings
|
// pass the theme navigation items, settings get configured as globals
|
||||||
_.extend(res.locals, navData, {
|
_.extend(res.locals, navData);
|
||||||
settings: ghost.settings()
|
|
||||||
});
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"engineStrict": true,
|
"engineStrict": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "3.3.4",
|
"express": "3.3.4",
|
||||||
"express-hbs": "0.2.0",
|
"express-hbs": "0.2.1",
|
||||||
"node-polyglot": "0.2.1",
|
"node-polyglot": "0.2.1",
|
||||||
"moment": "2.1.0",
|
"moment": "2.1.0",
|
||||||
"underscore": "1.5.1",
|
"underscore": "1.5.1",
|
||||||
|
|
Loading…
Add table
Reference in a new issue