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

fixed the issue which was causing the errors when using old configura… #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ if (config.toc.template){
pmd.validatePathRef(config.toc.template, 'config.toc.template');
}

// Set helper variable so the engine know if the MenuTemplate is being used
config.toc.hasMenuTemplate = (typeof config.toc.menuTemplate !== 'undefined');

// Process data and write to file
var objs = pmd.generateData(config);
objs = pmd.mergeObjs(objs);

// The toc returns the configuration needed for generating the files (determine if we have a folder structured menu or flattened menu).
pmd.generateToc(config, objs);
pmd.saveToFile(config, pmd.globalFiles);
pmd.saveToFile(config, pmd.menuStructure, pmd.globalFiles);

// Check if the search library is enabled
if(config.search) {
Expand Down
47 changes: 41 additions & 6 deletions lib/pmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,17 @@ pmd.mergeObjs = function(objs){
*
* @param objs array of all data
*/
pmd.saveToFile = function(config, objs){
pmd.saveToFile = function(config, tocConfig, objs){
// Finally print out data
objs.files.forEach(function(obj){
if(obj && obj.fileData && !obj.fileData.isFolder) {
obj.fileData.folders = pmd.menuStructure.folders;
obj.fileData.hasMenuTemplate = tocConfig.hasMenuTemplate;

// We use the old way of the menu, set the files variable corresponding to all the files we are generating
if(!obj.fileData.hasMenuTemplate) {
obj.fileData.files = objs.files;
}

var markdown = obj.template(obj.fileData);
let docExtName = path.extname(obj.folder.template);
Expand All @@ -636,8 +642,8 @@ pmd.saveToFile = function(config, objs){
debug.logFile(obj.fileData.name + docExtName, markdown);
}

// Register the list template
Handlebars.registerPartial( "list", fs.readFileSync(path.resolve(config.toc.menuTemplate),'utf8') );
// Register the list template, use the same variable as used inside the toc, this is why we need this variable
Handlebars.registerPartial( "list", tocConfig.listPartialContent);

fs.writeFileSync(path.resolve(obj.folder.output.path,obj.fileData.name + docExtName), markdown);
}
Expand Down Expand Up @@ -679,8 +685,13 @@ pmd.generateToc = function(config, objs){
var
indexData = {
folders: objs.children,
files: null,
projectDispName: config.projectDispName,
search: config.search
search: config.search,
// Determine if we have a menu template if not we use the old flattened menu
hasMenuTemplate: config.toc.hasMenuTemplate,
// Stores the content of the menuTemplate if provided
listPartialContent: ""
},
files = {
files: [],
Expand All @@ -707,14 +718,38 @@ pmd.generateToc = function(config, objs){
templateContent = fs.readFileSync(path.resolve(config.toc.template),'utf8'),
template = Handlebars.compile(templateContent);

// Register the list template
Handlebars.registerPartial( "list", fs.readFileSync(path.resolve(config.toc.menuTemplate),'utf8') );
// Check if we need to apply the flat menu structure or not
if(indexData.hasMenuTemplate) {
// Register the list template
indexData.listPartialContent = fs.readFileSync(path.resolve(config.toc.menuTemplate),'utf8');
}
else {
var filesFlattened = [];

// Iterate over the files and remove the folders out of it
files.files.forEach(function(file) {
// This was actually a folder remove it
if(file && file.docFileName) {
filesFlattened.push(file);
}
});

// Set the files to the flattened list
indexData.files = files.files = filesFlattened;
}

// Register the list partial, this is needed when using it inside the template. When no structured menu is provided the listPartialContent is an empty string.
// That handlebar function is not being used than. When we have a structured menu it contains the content of file provided in the config.json (config.toc.menuTemplate)
Handlebars.registerPartial( "list", indexData.listPartialContent);

// Create the markdown file
markdown = template(indexData);

// Set the global files needed when generating the docs for the objects
pmd.globalFiles = files;
pmd.menuStructure = indexData;

// Save the file to the filesystem
fs.writeFileSync(path.resolve(config.folders[0].output.path, config.toc.fileName), markdown);
}//config.templates.index
}// generateToc
Expand Down
38 changes: 23 additions & 15 deletions templates/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,30 @@ <h1 class="page-title">{{toUpperCase projectDispName}}<small> - API Documentatio
<div class="small-12 large-3 columns" data-sticky-container>
<nav class="sticky" data-sticky data-anchor="main" data-sticky-on="large">
<h3>Files</h3>
{{#each folders}}
{{#if name}}
<ul class="list main-menu menu vertical">
<li>
<a style="padding: 0px;"><h4>{{name}}</h4></a>
{{/if}}

<ul class="{{#unless name}}list main-menu{{/unless}} menu vertical">
{{> list}}
</ul>

{{#if name}}
</li>
{{#if hasMenuTemplate}}
{{#each folders}}
{{#if name}}
<ul class="list main-menu menu vertical">
<li>
<a style="padding: 0px;"><h4>{{name}}</h4></a>
{{/if}}

<ul class="{{#unless name}}list main-menu{{/unless}} menu vertical">
{{> list}}
</ul>
{{/if}}
{{/each}}

{{#if name}}
</li>
</ul>
{{/if}}
{{/each}}
{{else}}
<ul class="menu vertical">
{{#each files}}
<li class="{{#ifCond name '==' @root.name}}active{{/ifCond}}"><a href="{{docFileName}}">{{toUpperCase name}}</a></li>
{{/each}}
</ul>
{{/if}}
</nav>
</div>
<!-- /Index Menu -->
Expand Down
38 changes: 23 additions & 15 deletions templates/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,30 @@ <h1 class="page-title">{{toUpperCase projectDispName}}<small> - API Documentatio
<div class="small-12 large-3 columns">
<nav class="sticky">
<h3>Files</h3>
{{#each folders}}
{{#if name}}
<ul class="list main-menu menu vertical">
<li>
<a style="padding: 0px;"><h4>{{name}}</h4></a>
{{/if}}

<ul class="{{#unless name}}list main-menu{{/unless}} menu vertical">
{{> list}}
</ul>

{{#if name}}
</li>
{{#if hasMenuTemplate}}
{{#each folders}}
{{#if name}}
<ul class="list main-menu menu vertical">
<li>
<a style="padding: 0px;"><h4>{{name}}</h4></a>
{{/if}}

<ul class="{{#unless name}}list main-menu{{/unless}} menu vertical">
{{> list}}
</ul>
{{/if}}
{{/each}}

{{#if name}}
</li>
</ul>
{{/if}}
{{/each}}
{{else}}
<ul class="menu vertical">
{{#each files}}
<li class="{{#ifCond name '==' @root.name}}active{{/ifCond}}"><a href="{{docFileName}}">{{toUpperCase name}}</a></li>
{{/each}}
</ul>
{{/if}}
</nav>
</div>
<!-- /Index Menu -->
Expand Down
9 changes: 7 additions & 2 deletions templates/toc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# {{toUpperCase projectDispName}}

{{#if hasMenuTemplate}}
{{#each folders}}{{#if name}}* [{{name}}]({{name}}){{/if}}
{{> list}}{{/each}}
{{> list}}{{/each}}
{{else}}
{{#each files}}
- [{{toUpperCase name}}]({{docFileName}})
{{/each}}
{{/if}}