summaryrefslogtreecommitdiffstats
path: root/lib/parse
diff options
context:
space:
mode:
authorSoreine <nicolas@gitbook.com>2016-05-17 12:48:03 +0200
committerSoreine <nicolas@gitbook.com>2016-05-17 12:48:03 +0200
commit167d3957bf2caa1f46bc1b1ef5084fd468594c8d (patch)
tree4213d84826f73f25d8d3c12f6d48aad5a6da9c2c /lib/parse
parenta9571fd67d3d638d6d9d6c11a7e626c5600a68a2 (diff)
downloadgitbook-167d3957bf2caa1f46bc1b1ef5084fd468594c8d.zip
gitbook-167d3957bf2caa1f46bc1b1ef5084fd468594c8d.tar.gz
gitbook-167d3957bf2caa1f46bc1b1ef5084fd468594c8d.tar.bz2
Expose lookup method for parsable files
Diffstat (limited to 'lib/parse')
-rw-r--r--lib/parse/findParsableFile.js2
-rw-r--r--lib/parse/index.js21
-rw-r--r--lib/parse/lookupStructureFile.js20
-rw-r--r--lib/parse/parseIgnore.js34
-rw-r--r--lib/parse/parseStructureFile.js7
5 files changed, 52 insertions, 32 deletions
diff --git a/lib/parse/findParsableFile.js b/lib/parse/findParsableFile.js
index 4434d64..51e2dd0 100644
--- a/lib/parse/findParsableFile.js
+++ b/lib/parse/findParsableFile.js
@@ -8,7 +8,7 @@ var parsers = require('../parsers');
@param {Book} book
@param {String} filename
- @return {Promise<>}
+ @return {Promise<File | Undefined>}
*/
function findParsableFile(book, filename) {
var fs = book.getContentFS();
diff --git a/lib/parse/index.js b/lib/parse/index.js
index ac27fcf..fcc5025 100644
--- a/lib/parse/index.js
+++ b/lib/parse/index.js
@@ -1,13 +1,14 @@
module.exports = {
- parseBook: require('./parseBook'),
- parseSummary: require('./parseSummary'),
- parseGlossary: require('./parseGlossary'),
- parseReadme: require('./parseReadme'),
- parseConfig: require('./parseConfig'),
- parsePagesList: require('./parsePagesList'),
- parseIgnore: require('./parseIgnore'),
- listAssets: require('./listAssets'),
- parseLanguages: require('./parseLanguages'),
- parsePage: require('./parsePage')
+ parseBook: require('./parseBook'),
+ parseSummary: require('./parseSummary'),
+ parseGlossary: require('./parseGlossary'),
+ parseReadme: require('./parseReadme'),
+ parseConfig: require('./parseConfig'),
+ parsePagesList: require('./parsePagesList'),
+ parseIgnore: require('./parseIgnore'),
+ listAssets: require('./listAssets'),
+ parseLanguages: require('./parseLanguages'),
+ parsePage: require('./parsePage'),
+ lookupStructureFile: require('./lookupStructureFile')
};
diff --git a/lib/parse/lookupStructureFile.js b/lib/parse/lookupStructureFile.js
new file mode 100644
index 0000000..d4a8f02
--- /dev/null
+++ b/lib/parse/lookupStructureFile.js
@@ -0,0 +1,20 @@
+var findParsableFile = require('./findParsableFile');
+
+/**
+ Lookup a structure file (ex: SUMMARY.md, GLOSSARY.md) in a book. Uses
+ book's config to find it.
+
+ @param {Book} book
+ @param {String} type: one of ["glossary", "readme", "summary", "langs"]
+ @return {Promise<File>} The path of the file found, relative
+ to the book content root.
+*/
+function lookupStructureFile(book, type) {
+ var config = book.getConfig();
+
+ var fileToSearch = config.getValue(['structure', type]);
+
+ return findParsableFile(book, fileToSearch);
+}
+
+module.exports = lookupStructureFile;
diff --git a/lib/parse/parseIgnore.js b/lib/parse/parseIgnore.js
index d13663d..84d8c33 100644
--- a/lib/parse/parseIgnore.js
+++ b/lib/parse/parseIgnore.js
@@ -1,6 +1,23 @@
var Promise = require('../utils/promise');
var IGNORE_FILES = require('../constants/ignoreFiles');
+var DEFAULT_IGNORES = [
+ // Skip Git stuff
+ '.git/',
+
+ // Skip OS X meta data
+ '.DS_Store',
+
+ // Skip stuff installed by plugins
+ 'node_modules',
+
+ // Skip book outputs
+ '_book',
+
+ // Ignore files in the templates folder
+ '_layouts'
+];
+
/**
Parse ignore files
@@ -15,22 +32,7 @@ function parseIgnore(book) {
var fs = book.getFS();
var ignore = book.getIgnore();
- ignore = ignore.add([
- // Skip Git stuff
- '.git/',
-
- // Skip OS X meta data
- '.DS_Store',
-
- // Skip stuff installed by plugins
- 'node_modules',
-
- // Skip book outputs
- '_book',
-
- // Ignore files in the templates folder
- '_layouts'
- ]);
+ ignore = ignore.add(DEFAULT_IGNORES);
return Promise.serie(IGNORE_FILES, function(filename) {
return fs.readAsString(filename)
diff --git a/lib/parse/parseStructureFile.js b/lib/parse/parseStructureFile.js
index fe8c935..718f731 100644
--- a/lib/parse/parseStructureFile.js
+++ b/lib/parse/parseStructureFile.js
@@ -1,6 +1,6 @@
-var findParsableFile = require('./findParsableFile');
var Promise = require('../utils/promise');
var error = require('../utils/error');
+var lookupStructureFile = require('./lookupStructureFile');
/**
Parse a ParsableFile using a specific method
@@ -55,11 +55,8 @@ function parseFile(fs, file, type) {
*/
function parseStructureFile(book, type) {
var fs = book.getContentFS();
- var config = book.getConfig();
- var fileToSearch = config.getValue(['structure', type]);
-
- return findParsableFile(book, fileToSearch)
+ return lookupStructureFile(book, type)
.then(function(file) {
if (!file) return [undefined, undefined];