ghost/ghost.js

Ghost Module

Defines core methods required to build the frontend

/** * global module, * require, * __dirname **/ (function () { "use strict";

 Setup Prerequisites

var config = require('./config'), express = require('express'), path = require('path'), hbs = require('express-hbs'), _ = require('underscore'), FancyFirstChar = require('../plugins/fancyFirstChar'), DataProvider = require('../ghost/dataProvider'), dataProvider = new DataProvider(), Ghost, instance, filterCallbacks = {}, statuses;

 Article Statuses

/** * A list of atricle status types * @type {Object} */ statuses = { 'draft': 'draft', 'complete': 'complete', 'approved': 'approved', 'scheduled': 'scheduled', 'published': 'published' };

Module Methods

/** * @method Ghost * @returns {*} * @constructor */ Ghost = function () { var app, globals; if (!instance) { instance = this; dataProvider.globals.findAll(function (err, data) { globals = data; }); app = express();

functionality load Plugins... var f = new FancyFirstChar(ghost).init();

_.extend(instance, { app: function () { return app; }, config: function () { return config; }, globals: function () { return globals; }, // there's no management here to be sure this has loaded statuses: function () { return statuses; } }); } return instance; }; /** * @param {string} name * @param {Function} fn * @return {method} hbs.registerHelper */ Ghost.prototype.registerThemeHelper = function (name, fn) { hbs.registerHelper(name, fn); }; /** * @param {string} name * @param {Function} fn * @return {*} */ Ghost.prototype.registerTheme = function (name, fn) {}; /** * @param {string} name * @param {Function} fn * @return {*} */ Ghost.prototype.registerPlugin = function (name, fn) {}; /** * @param {string} name * @param {Function} fn */ Ghost.prototype.registerFilter = function (name, fn) { if (!filterCallbacks.hasOwnProperty(name)) { filterCallbacks[name] = []; } console.log('registering filter for ', name); filterCallbacks[name].push(fn); }; /** * @param {string} name [description] * @param {*} args * @param {Function} callback * @return {method} callback */ Ghost.prototype.doFilter = function (name, args, callback) { var fn; if (filterCallbacks.hasOwnProperty(name)) { for (fn in filterCallbacks[name]) { if (filterCallbacks[name].hasOwnProperty(fn)) { console.log('doing filter for ', name); args = filterCallbacks[name][fn](args); } } } callback(args); }; /** * Initialise Theme * * @todo Tod (?) Old comment * @param {Object} app */ Ghost.prototype.initTheme = function (app) { return function initTheme(req, res, next) { app.set('view engine', 'hbs'); if (/(^\/ghost$|^\/ghost\/)/.test(req.url) === false) { app.engine('hbs', hbs.express3({partialsDir: __dirname + '/../' + config.themeDir + '/' + config.activeTheme + '/partials'})); app.set('views', __dirname + '/../' + config.themeDir + '/' + config.activeTheme); } else { app.engine('hbs', hbs.express3({partialsDir: __dirname + '/../ghost/views/partials'})); app.set('views', __dirname + '/../ghost/views'); } app.use(express['static'](path.join(__dirname, '/../' + config.themeDir + '/' + config.activeTheme))); app.use('/media', express['static'](path.join(__dirname, '/../media'))); app.use('/ghost/assets', express['static'](path.join(__dirname, '/../ghost/assets'))); next(); }; }; module.exports = Ghost; }());