From cc98790ab0e146248c8536923438192353cd987a Mon Sep 17 00:00:00 2001 From: Varya Stepanova Date: Fri, 27 Nov 2015 15:06:38 +0200 Subject: [PATCH] Options to inject custom HTML in beginning or in the end of tag --- README.md | 10 ++++++++++ lib/app/index.html | 2 ++ lib/modules/cli/argv.js | 2 ++ lib/modules/cli/styleguide-cli.js | 2 ++ lib/modules/common.js | 2 ++ lib/styleguide.js | 4 +++- 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f002613..67418c4d 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,16 @@ This string is used as a page title and in the page header These HTML elements are injected inside the style guide head-tag. + +**beforeBody** (array or string, optional) + +These HTML elements are injected inside the style guide `` tag, before any other content. + + +**afterBody** (array or string, optional) + +These HTML elements are injected inside the style guide `` tag, after any other content. + **commonClass** (string or array of strings, optional) diff --git a/lib/app/index.html b/lib/app/index.html index b8e1bb34..888b354d 100644 --- a/lib/app/index.html +++ b/lib/app/index.html @@ -52,11 +52,13 @@ + {{{beforeBody}}}
{{#socketIo}} {{/socketIo}} + {{{afterBody}}} diff --git a/lib/modules/cli/argv.js b/lib/modules/cli/argv.js index 46554f62..d01d286a 100644 --- a/lib/modules/cli/argv.js +++ b/lib/modules/cli/argv.js @@ -13,6 +13,8 @@ module.exports = function(argLib) { .describe('enableJade', 'This bool use to enable Jade support, false by default') .describe('title', 'This string is used as a page title and in the page header') .describe('extraHead', 'These HTML elements are injected inside the style guide head-tag') + .describe('beforeBody', 'These HTML elements are injected inside the style guide body tag, before any other content') + .describe('afterBody', 'These HTML elements are injected inside the style guide body tag, after any other content') .describe('commonClass', 'The provided classes are added to all preview blocks in the generated style guide') .describe('appRoot', 'Define the appRoot parameter if you are hosting the style guide from a directory other than the root directory of the HTTP server') .describe('styleVariables', 'Specify the files to parse variable definitions from (defaults to all files/glob pattern passed to kssSource') diff --git a/lib/modules/cli/styleguide-cli.js b/lib/modules/cli/styleguide-cli.js index 67a34066..05af0c9b 100755 --- a/lib/modules/cli/styleguide-cli.js +++ b/lib/modules/cli/styleguide-cli.js @@ -20,6 +20,8 @@ module.exports = function(argv) { title: argv.title, rootPath: argv.output, extraHead: argv.extraHead, + beforeBody: argv.beforeBody, + afterBody: argv.afterBody, commonClass: argv.commonClass, appRoot: argv.appRoot, styleVariables: argv.styleVariables, diff --git a/lib/modules/common.js b/lib/modules/common.js index d76c5476..34d2ed6c 100644 --- a/lib/modules/common.js +++ b/lib/modules/common.js @@ -11,6 +11,8 @@ function sanitizeOptions(opt) { kssOpt: opt.kssOpt || {}, overviewPath: opt.overviewPath || path.join(__dirname, '/overview.md'), extraHead: (typeof opt.extraHead === 'object') ? opt.extraHead.join('\n') : opt.extraHead, + beforeBody: (typeof opt.beforeBody === 'object') ? opt.beforeBody.join('\n') : opt.beforeBody, + afterBody: (typeof opt.afterBody === 'object') ? opt.afterBody.join('\n') : opt.afterBody, disableEncapsulation: opt.disableEncapsulation || false, disableHtml5Mode: opt.disableHtml5Mode || (typeof opt.disableHtml5Mode === 'undefined' && !opt.server) || false, appRoot: opt.appRoot || '', diff --git a/lib/styleguide.js b/lib/styleguide.js index d9badf91..5cc584e4 100644 --- a/lib/styleguide.js +++ b/lib/styleguide.js @@ -125,7 +125,7 @@ function replaceSectionReferences(json) { } function copyUsedOptionsToJsonConfig(opt, json) { - var used = ['appRoot', 'extraHead', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly']; + var used = ['appRoot', 'extraHead', 'beforeBody', 'afterBody', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly']; json.config = {}; used.forEach(function(prop) { json.config[prop] = _.cloneDeep(opt[prop]); @@ -338,6 +338,8 @@ module.exports.generate = function(options) { .pipe(mustache({ title: opt.title, extraHead: opt.extraHead, + beforeBody: opt.beforeBody, + afterBody: opt.afterBody, styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config), appRoot: opt.appRoot, socketIo: opt.server,