From 1a4165c0ab0cc784c7a2870747c7dac4c46eac1d Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Sun, 14 Feb 2016 23:01:22 +0100 Subject: [PATCH] ADD dynamic navigation items for header.inc.html FIX a typo: "heagerFooter" > "headerFooter" ADD a property to templateJSON object in wrap.js middleware ADD (placeholder) header navigation items in options.js, it's added into the modulesOptions.headerFooter object. (which was unused until now). ADD an options property to headerFooter.js, seems to me that it there's a file specific for finding the template files and rendering the header & footer, this is the place to add the data about which navigation items the header contains. --- assets/templates/header.inc.html | 11 ++++++++--- core/headerFooter.js | 28 +++++++++++++++------------- core/middlewares/wrap.js | 17 +++++++++-------- options.js | 8 ++++++++ 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/assets/templates/header.inc.html b/assets/templates/header.inc.html index 33a0708..cc5ae24 100644 --- a/assets/templates/header.inc.html +++ b/assets/templates/header.inc.html @@ -14,12 +14,17 @@ - \ No newline at end of file + diff --git a/core/headerFooter.js b/core/headerFooter.js index 5eb7cbf..ac3995c 100644 --- a/core/headerFooter.js +++ b/core/headerFooter.js @@ -4,21 +4,23 @@ var fs = require('fs'); var path = require('path'); exports.getHeaderAndFooter = function () { - var defaultTemplatePath = path.join(global.pathToApp, 'assets/templates'); - var userTemplatePath = path.join(global.userPath, 'assets/templates'); - var headerFile = 'header.inc.html'; - var footerFile = 'footer.inc.html'; + var defaultTemplatePath = path.join(global.pathToApp, 'assets/templates'); + var userTemplatePath = path.join(global.userPath, 'assets/templates'); + var headerFile = 'header.inc.html'; + var footerFile = 'footer.inc.html'; + var options = global.opts.assets.modulesOptions.headerFooter; - var output = {}; + var output = {}; - var userHeaderTplPath = path.join(userTemplatePath, headerFile); - output.headerPath = fs.existsSync(userHeaderTplPath) ? userHeaderTplPath : path.join(defaultTemplatePath, headerFile); + var userHeaderTplPath = path.join(userTemplatePath, headerFile); + output.headerPath = fs.existsSync(userHeaderTplPath) ? userHeaderTplPath : path.join(defaultTemplatePath, headerFile); - var userFooterTplPath = path.join(userTemplatePath, footerFile); - output.footerPath = fs.existsSync(userFooterTplPath) ? userFooterTplPath : path.join(defaultTemplatePath, footerFile); + var userFooterTplPath = path.join(userTemplatePath, footerFile); + output.footerPath = fs.existsSync(userFooterTplPath) ? userFooterTplPath : path.join(defaultTemplatePath, footerFile); - output.header = fs.readFileSync(output.headerPath, 'utf-8'); - output.footer = fs.readFileSync(output.footerPath, 'utf-8'); + output.header = fs.readFileSync(output.headerPath, 'utf-8'); + output.footer = fs.readFileSync(output.footerPath, 'utf-8'); + output.options = options; - return output; -}; \ No newline at end of file + return output; +}; diff --git a/core/middlewares/wrap.js b/core/middlewares/wrap.js index 4efb4b4..422a3a0 100644 --- a/core/middlewares/wrap.js +++ b/core/middlewares/wrap.js @@ -83,30 +83,31 @@ exports.process = function (req, res, next) { content = $.html(); } - var heagerFooter = getHeaderAndFooter(); + var headerFooter = getHeaderAndFooter(); // final data object for the template var templateJSON = { engineVersion: global.engineVersion, content: content, head: head, - info: info + info: info, + headerNavItems: headerFooter.options.headerNavItems }; try { - templateJSON.header = ejs.render(heagerFooter.header, templateJSON); + templateJSON.header = ejs.render(headerFooter.header, templateJSON); } catch(err){ - var headerMsg = 'Error: EJS could render header template: ' + heagerFooter.headerPath; + var headerMsg = 'Error: EJS could render header template: ' + headerFooter.headerPath; templateJSON.header = headerMsg; global.log.warn(headerMsg, err.stack); } try { - templateJSON.footer = ejs.render(heagerFooter.footer, templateJSON, { - filename: heagerFooter.footerPath + templateJSON.footer = ejs.render(headerFooter.footer, templateJSON, { + filename: headerFooter.footerPath }); } catch(err){ - var footerMsg = 'Error: EJS could render footer template: ' + heagerFooter.footerPath; + var footerMsg = 'Error: EJS could render footer template: ' + headerFooter.footerPath; templateJSON.footer = footerMsg; global.log.warn(footerMsg, err.stack); } @@ -129,4 +130,4 @@ exports.process = function (req, res, next) { // proceed to next middleware next(); } -}; \ No newline at end of file +}; diff --git a/options.js b/options.js index c250a17..6f2da52 100644 --- a/options.js +++ b/options.js @@ -148,6 +148,14 @@ module.exports = { // Page navigation hash update on scroll turned off because of performance issues updateHash: false }, + headerFooter: { + headerNavItems: [ + {name: 'Home', path: '/'}, + {name: 'Docs', path: '/docs/'}, + {name: 'Twitter', path: 'http://twitter.com/sourcejs'}, + {name: 'Mail', path: 'mailto:address@example.com'} + ] + }, search: { autofocusOnNavigationPage: true,