From 20b6cde5b6a392e79467d873fdffad9d34e3a6f3 Mon Sep 17 00:00:00 2001 From: Kevin Frugier Date: Mon, 9 Mar 2015 16:50:42 +0100 Subject: [PATCH 1/3] Attempt at avoid source export whenn showSource is set to false --- lib/scripts/core/group.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/scripts/core/group.js b/lib/scripts/core/group.js index b7f75e1..ec94d94 100755 --- a/lib/scripts/core/group.js +++ b/lib/scripts/core/group.js @@ -221,7 +221,11 @@ var Group = Class.extend({ }, buildRegistry: function () { + var bShowSource = this.option('showSource'); this.docs.forEach(function (doc) { + if (!bShowSource && doc.file) { + delete doc.file; + } this.registry.addItem(doc.id, doc); }.bind(this)); return this.runRecursively('buildRegistry'); From f3f1f3a538ed6fd4a80c9b761a64c8f502494d25 Mon Sep 17 00:00:00 2001 From: Kevin Frugier Date: Tue, 10 Mar 2015 08:47:06 +0100 Subject: [PATCH 2/3] Implementation of showSource as described in the documentation --- lib/resources/js/controllers/index.js | 28 +++++++++++++------------ lib/resources/templates/index_page.html | 2 +- lib/scripts/core/generator.js | 13 ++++++++++-- lib/scripts/core/group.js | 19 ++++++++++++----- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/resources/js/controllers/index.js b/lib/resources/js/controllers/index.js index 0c5ac8f..4f751af 100755 --- a/lib/resources/js/controllers/index.js +++ b/lib/resources/js/controllers/index.js @@ -123,19 +123,21 @@ angular.module('docular.controllers', [ if(!documentationItem) { $scope.isIndex = true; } else { - sourceService.fetchSourceFile(documentationItem.file).then(function (resp) { - var fileType = fileType ? documentationItem.file.match(/[A-Za-z0-9]+$/) : null; - if(fileType && fileType.length == 1) { - fileType = fileType[0]; - } else { - fileType = null; - } - $scope.source = { - content: resp.data, - fileType: fileType - } - console.log($scope.source); - }); + if (documentationItem.showSource) { + sourceService.fetchSourceFile(documentationItem.file).then(function (resp) { + var fileType = fileType ? documentationItem.file.match(/[A-Za-z0-9]+$/) : null; + if(fileType && fileType.length == 1) { + fileType = fileType[0]; + } else { + fileType = null; + } + $scope.source = { + content: resp.data, + fileType: fileType + } + console.log($scope.source); + }); + } $scope.includeUrl = 'resources/plugins/' + documentationItem.handler + '/documentationPartial.html'; } diff --git a/lib/resources/templates/index_page.html b/lib/resources/templates/index_page.html index e6ed8f9..2e04e5b 100755 --- a/lib/resources/templates/index_page.html +++ b/lib/resources/templates/index_page.html @@ -43,7 +43,7 @@
- + diff --git a/lib/scripts/core/generator.js b/lib/scripts/core/generator.js index daa2f85..5976334 100755 --- a/lib/scripts/core/generator.js +++ b/lib/scripts/core/generator.js @@ -125,11 +125,20 @@ var Generator = Group.extend({ fs.writeFileSync(baseFolder + '/site.json', JSON.stringify(docs, null, 4)); fs.writeFileSync(baseFolder + '/structure.json', JSON.stringify(structure, null, 4)); - fse.ensureDirSync(baseFolder + '/sources/'); + var bSourcesFolderCreated = false; + for (var i = 0, l = docs.length; i < l; i++) { - if (docs[i].file) { + if (docs[i].file && docs[i].showSource) { + + //We only create the sources folder if it's needed by at least one file + if (!bSourcesFolderCreated) { + bSourcesFolderCreated = true; + fse.ensureDirSync(baseFolder + '/sources/'); + } + fse.ensureFileSync(baseFolder + '/sources/' + docs[i].file); fse.copySync(docs[i].file, baseFolder + '/sources/' + docs[i].file); + } } diff --git a/lib/scripts/core/group.js b/lib/scripts/core/group.js index b7f75e1..a4f9320 100755 --- a/lib/scripts/core/group.js +++ b/lib/scripts/core/group.js @@ -75,18 +75,20 @@ var Group = Class.extend({ return paths.reverse().join('/'); }, - setupGroups: function () { + setupGroups: function (parentConfig) { + // The root group isn't called with a parentConfig so we set default value of bShowSource at this point + var _parentConfig = parentConfig || {showSource : false}; var groups = this.option('groups'); var self = this; this._groups = []; if(!groups) { return; } for(var i = 0, l = groups.length; i < l; i++) { - var config = Group.normalizeConfig(groups[i]); + var config = Group.normalizeConfig(groups[i], _parentConfig); this.emit('ProcessGroupConfig', config); var group = new Group(config, { registry: this.registry }); - group.setupGroups(); + group.setupGroups(config); this.events.forEach(function (evt) { group.on(evt, function () { self.emit.apply(self, [evt].concat(Array.prototype.slice.apply(arguments))); @@ -193,6 +195,7 @@ var Group = Class.extend({ var promises = []; var self = this; var files = this.option('files') || []; + var showSource = this.option('showSource'); this.docs = []; files.forEach(function (fileName) { @@ -207,6 +210,7 @@ var Group = Class.extend({ } docPromise.then(function (docModel) { docModel.setPath(paths); + docModel.data.showSource = showSource; self.docs.push(docModel); docModel.groupId = self.internalGroupId; self.files[fileName].docs.push(docModel); @@ -222,12 +226,13 @@ var Group = Class.extend({ buildRegistry: function () { this.docs.forEach(function (doc) { - this.registry.addItem(doc.id, doc); + this.registry.addItem(doc.id, doc); }.bind(this)); + return this.runRecursively('buildRegistry'); } }, { - normalizeConfig: function (groupData) { + normalizeConfig: function (groupData, parentGroupData) { /* * Backwards compatibility */ @@ -237,6 +242,10 @@ var Group = Class.extend({ if(!groupData.groupIcon) { groupData.groupIcon = 'code'; } + // If we don't explicitly set showSource, we inherit from parent + if (typeof(groupData.showSource) !== 'boolean') { + groupData.showSource = parentGroupData.showSource; + } return groupData; } From 8265faffbc43656f468392c3d56b76345e997b0d Mon Sep 17 00:00:00 2001 From: Kevin Frugier Date: Tue, 10 Mar 2015 08:47:51 +0100 Subject: [PATCH 3/3] Revert "Attempt at avoid source export whenn showSource is set to false" This reverts commit 20b6cde5b6a392e79467d873fdffad9d34e3a6f3. --- lib/scripts/core/group.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/scripts/core/group.js b/lib/scripts/core/group.js index ec94d94..b7f75e1 100755 --- a/lib/scripts/core/group.js +++ b/lib/scripts/core/group.js @@ -221,11 +221,7 @@ var Group = Class.extend({ }, buildRegistry: function () { - var bShowSource = this.option('showSource'); this.docs.forEach(function (doc) { - if (!bShowSource && doc.file) { - delete doc.file; - } this.registry.addItem(doc.id, doc); }.bind(this)); return this.runRecursively('buildRegistry');