Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options to inject custom HTML in beginning or in the end of <body> tag #849

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a name="option-beforeBody"></a>
**beforeBody** (array or string, optional)

These HTML elements are injected inside the style guide `<body>` tag, before any other content.

<a name="option-afterBody"></a>
**afterBody** (array or string, optional)

These HTML elements are injected inside the style guide `<body>` tag, after any other content.

<a name="option-commonClass"></a>
**commonClass** (string or array of strings, optional)

Expand Down
2 changes: 2 additions & 0 deletions lib/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
<base href="{{{appRoot}}}/" />
</head>
<body class="sg">
{{{beforeBody}}}
<div class="sg view-index" ui-view></div>
<script src="{{{appRoot}}}/js/vendor.js"></script>
<script src="{{{appRoot}}}/js/app.js"></script>
{{#socketIo}}
<script src="{{{appRoot}}}/socket.io/socket.io.js"></script>
{{/socketIo}}
{{{afterBody}}}
</body>
</html>
2 changes: 2 additions & 0 deletions lib/modules/cli/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/cli/styleguide-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down
4 changes: 3 additions & 1 deletion lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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,
Expand Down