Index page of summary when parsing

This commit is contained in:
Samy Pessé
2016-01-28 23:42:00 +01:00
parent ff30ba62ba
commit e83d63c2aa
6 changed files with 63 additions and 6 deletions
+6 -1
View File
@@ -5,7 +5,7 @@ A page represent a parsable file in the book (Markdown, Asciidoc, etc)
*/
function Page(book, filename) {
if (!(this instanceof Page)) return new Page();
if (!(this instanceof Page)) return new Page(book, filename);
this.book = book;
this.filename = filename;
@@ -20,5 +20,10 @@ Page.prototype.withExtension = function(ext) {
);
};
// Read the page as a string
Page.prototype.read = function() {
return this.book.readFile(this.filename);
};
module.exports = Page;
+5
View File
@@ -39,6 +39,11 @@ TOCArticle.prototype.walk = function(iter) {
});
};
// Return true if is pointing to a file
TOCArticle.prototype.hasLocation = function() {
return Boolean(this.filename);
};
// Return true if has children
TOCArticle.prototype.hasChildren = function() {
return this.articles.length > 0;
+12 -2
View File
@@ -168,6 +168,8 @@ Book.prototype.parse = function() {
}
return Promise()
// Parse the readme
.then(that.readme.load)
.then(function() {
if (that.readme.exists()) return;
@@ -175,13 +177,21 @@ Book.prototype.parse = function() {
throw new Error('No README file (or is ignored)');
})
// Parse the summary
.then(that.summary.load)
.then(function() {
if (that.summary.exists()) return;
if (!that.summary.exists()) {
throw new Error('No SUMMARY file (or is ignored)');
}
throw new Error('No SUMMARY file (or is ignored)');
// Index summary's articles
that.summary.walk(function(article) {
if (!article.hasLocation()) return;
that.addPage(article.filename);
});
})
// Parse the glossary
.then(that.glossary.load);
});
};
+1 -1
View File
@@ -7,7 +7,7 @@ function JSONGenerator() {
util.inherits(JSONGenerator, Generator);
// Write a page (parsable file)
Generator.prototype.writePage = function(page) {
JSONGenerator.prototype.writePage = function(page) {
var json = {};
+27
View File
@@ -0,0 +1,27 @@
var util = require('util');
var Generator = require('./base');
function WebsiteGenerator() {
Generator.apply(this, arguments);
}
util.inherits(WebsiteGenerator, Generator);
// Copy an asset file
WebsiteGenerator.prototype.writeAsset = function(filename) {
var that = this;
return that.book.readFile(filename)
.then(function(buf) {
return that.output.writeFile(filename, buf);
});
};
// Write a page (parsable file)
WebsiteGenerator.prototype.writePage = function(page) {
};
module.exports = WebsiteGenerator;
+12 -2
View File
@@ -1,6 +1,9 @@
var _ = require('lodash');
var fs = require('fs');
var Ignore = require('ignore');
var Promise = require('./utils/promise');
var pathUtil = require('./utils/path');
var generators = require('./generators');
var PluginsManager = require('./plugins');
@@ -24,9 +27,16 @@ function Output(book, type) {
]);
}
// Write a file to the output folder
Output.prototype.writeFile = function(filename, buf) {
// Resolve a file in the output directory
Output.prototype.resolve = function(filename) {
return pathUtil.resolveInRoot.apply(null, [this.book.config.get('output')].concat(_.toArray(arguments)));
};
// Write a file/buffer to the output folder
Output.prototype.writeFile = function(filename, buf) {
filename = this.resolve(filename);
return Promise.nfcall(fs.writeFileSync, filename, buf);
};
// Start the generation, for a parsed book