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 3c86eca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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
6 changes: 5 additions & 1 deletion test/integration/structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ describe('index.html', function() {
});

it('should contain serialized styleguide configuration', function() {
expect(indexHtml.contents.toString()).to.contain('var _styleguideConfig = {"appRoot":"/my-styleguide-book"');
expect(indexHtml.contents.toString()).to.contain('var _styleguideConfig = {"title":"Test Styleguide"');
});

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

Expand Down

0 comments on commit 3c86eca

Please sign in to comment.