Skip to content

Commit

Permalink
Merge pull request #586 from hannu/remove-from-inline-json
Browse files Browse the repository at this point in the history
Do not expose all configuration params to index.html JSON
  • Loading branch information
hannu committed Apr 20, 2015
2 parents 99baadc + df91dde commit 92f8a6b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ If you modify you assets in gulp streams, you can add styleguide output director
gulp.task('images', function() {
gulp.src(['images/**'])
// Do image sprites, optimizations etc.
.pipe(gulp.dest(buildPath + '/images'));
.pipe(gulp.dest(buildPath + '/images'))
.pipe(gulp.dest(outputPath + '/images'));
});
Expand Down
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 92f8a6b

Please sign in to comment.