docs: sort by groups by default

This commit is contained in:
Andy Joslin
2014-03-17 14:22:05 -06:00
parent 8c55e280ba
commit e9bf43a813
5 changed files with 46 additions and 81 deletions

View File

@@ -66,8 +66,7 @@ module.exports = function(config) {
require('./processors/keywords'),
require('./processors/pages-data'),
require('./processors/index-page'),
require('./processors/version-data'),
require('./processors/output')
require('./processors/version-data')
]);
return config;

View File

@@ -1,29 +0,0 @@
var _ = require('lodash');
var path = require('canonical-path');
var fs = require('fs');
module.exports = {
name: 'output',
description: 'log all doc urls after everything is done',
runAfter: ['files-written'],
process: function(docs, config) {
var links = docs
.filter(function(doc) {
return doc.match(/\/api\/.*?\/index.md$/) && doc.indexOf('/module/ionic') == -1;
})
.map(function(doc) {
return doc.replace(/^.*?\/docs/,'/docs').replace(/\/index.md$/, '');
});
var outputFolder = path.join(config.get('basePath'), config.get('rendering.outputFolder'));
var menuInclude = path.join(outputFolder, '_includes/api_menu_' + config.versionData.current.name + '.html');
if (!fs.existsSync(menuInclude)) {
fs.writeFileSync(menuInclude, links.map(function(link) {
return '<li class="menu-item{% if page.path == "' + link.replace(/^.*?\/api/, 'api') + '" %} active{% endif %}">\n' +
' <a href="' + link + '">' + link.replace(/^.*?\/api\//, '') + '</a>\n' +
'</li>';
}).join('\n'));
}
}
};

View File

@@ -1,4 +1,5 @@
var _ = require('lodash');
var fs = require('fs');
var path = require('canonical-path');
var log = require('winston');
@@ -17,7 +18,7 @@ module.exports = {
processorConfig = config.get('processing.pages-data', {});
currentVersion = config.get('currentVersion');
},
process: function(docs) {
process: function(docs, config) {
// Generate an object collection of pages that is grouped by section e.g.
// - section "directive"
// - group "Tab Bar"
@@ -28,67 +29,49 @@ module.exports = {
// - ion-checkbox
// - ...
//
var groups = _(docs)
var sections = _(docs)
.filter(function(doc) { return doc.area === 'api'; })
.filter(function(doc) { return doc.module === 'ionic'; })
.filter(function(doc) { return doc.docType !== 'componentGroup'; })
.groupBy(function(doc) { if (!doc.group) doc.group = 'Other'; return doc.group; })
.map(function(pages, groupName) {
var sections = _(pages)
.groupBy('docType')
.map(function(pages, docType) {
.groupBy('docType')
.map(function(pages, docType) {
return {
name: docType,
components: pages.map(function(page) {
return {
name: docType,
pages: _(pages)
.sortBy(function(doc) {
return doc.groupMainItem;
})
.map(function(doc) {
return {
href: doc.path,
name: doc.name,
docType: doc.docType,
type: doc.docType,
};
})
.filter(function(doc) {
return !!doc.name;
})
.value()
href: page.path,
name: page.name,
docType: page.docType,
type: page.docType
};
})
.sortBy(function(section) {
//Directives always first
return section.name != 'directive';
})
.value();
return {
name: groupName,
sections: sections
};
})
.sortBy(function(group) {
//Sort by groups with most items last
return _.values(group.sections).length;
.sortBy(function(section) {
//Directives always first
return section.name != 'directive';
})
.value();
_.forEach(docs, function(doc) {
if ( !doc.path ) {
log.warn('Missing path property for ', doc.id);
}
});
var outputFolder = path.join(config.get('basePath'), config.get('rendering.outputFolder'));
var menuFileName = '_includes/api_menu_' + config.versionData.current.name + '.html';
var menuInclude = path.join(outputFolder, menuFileName);
var docData = {
if (!fs.existsSync(menuInclude)) {
docs.push({
docType: 'menu-data',
id: 'menu-data',
template: 'menu-data.template.html',
outputPath: menuFileName,
sections: sections
});
}
docs.push({
docType: 'pages-data',
id: 'pages-data',
template: processorConfig.template || 'pages-data.template.js',
outputPath: processorConfig.outputPath || 'js/pages-data.js',
groups: groups
};
docs.push(docData);
});
}
};

12
docs/templates/menu-data.template.html vendored Normal file
View File

@@ -0,0 +1,12 @@
<@ for section in doc.sections @>
<li class="menu-section">
<$ section.name $>
</li>
<@ for component in section.components @>
<li class="menu-item{% if page.path == "<$ component.href $>" %} active{% endif %}">
<a href="<$ version.current.href $>/<$ component.href $>">
<@ if component.docType == "directive" @> <$ component.name | dashCase $><@ else @><$ component.name $><@ endif @>
</a>
</li>
<@ endfor @>
<@ endfor @>

View File

@@ -191,9 +191,9 @@ function($scope, $element, $ionicViewService, $animate, $compile) {
* ```html
* <body ng-app="starter">
* <!-- The nav bar that will be updated as we navigate -->
* <ion-nav-bar
* animation="nav-title-slide-ios7"
* class="bar-positive"></ion-nav-bar>
* <ion-nav-bar class="bar-positive"
* animation="nav-title-slide-ios7">
* </ion-nav-bar>
*
* <!-- where the initial view template will be rendered -->
* <ion-nav-view animation="slide-left-right"></ion-nav-view>