Skip to content

Commit

Permalink
Do not expose all configuration params to index.html JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pelkonen committed Apr 20, 2015
1 parent cca9cc6 commit b4e011d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ function copyUsedOptionsToJsonConfig(opt, json) {
return json;
}

function copyUsedOptionsToInlineJsonConfig(opt, json) {
var used = ['title', 'disableEncapsulation', 'disableHtml5Mode'];
json.config = {};
used.forEach(function(prop) {
json.config[prop] = _.cloneDeep(opt[prop]);
});
return json;
}

function addFileHashesAndReplaceAbsolutePaths(json) {
if (!json) {
return;
Expand Down Expand Up @@ -258,7 +267,7 @@ module.exports.generate = function(options) {
.pipe(mustache({
title: opt.title,
extraHead: opt.extraHead,
styleguideConfig: JSON.stringify(copyUsedOptionsToJsonConfig(opt, {}).config),
styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config),
appRoot: opt.appRoot,
socketIo: opt.server,
filesConfig: JSON.stringify(opt.filesConfig)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ describe('index.html', function() {
it('should contain serialized styleguide configuration', function() {
expect(indexHtml.contents.toString()).to.contain('var _styleguideConfig = {"appRoot":"/my-styleguide-book"');
});

it('should not add extraHead to serialized configuration', function() {
expect(indexHtml.contents.toString()).not.to.contain('"extreHead":');
});
});

describe('styleguide_pseudo_styles.css', function() {
Expand Down

0 comments on commit b4e011d

Please sign in to comment.