summaryrefslogtreecommitdiffstats
path: root/lib/configuration.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-10-12 10:43:14 +0200
committerSamy Pessé <samypesse@gmail.com>2015-10-12 10:43:14 +0200
commit9ba1075f4866131f790388ebabc1b8636926dd7f (patch)
tree38ba7f7bb414fc8c8589901c90d4863b800614c6 /lib/configuration.js
parent4ae5b2e05001df9bdf8c5b64f8a82725e14d6414 (diff)
downloadgitbook-9ba1075f4866131f790388ebabc1b8636926dd7f.zip
gitbook-9ba1075f4866131f790388ebabc1b8636926dd7f.tar.gz
gitbook-9ba1075f4866131f790388ebabc1b8636926dd7f.tar.bz2
Add hook "config" to transform configuration before generation
Diffstat (limited to 'lib/configuration.js')
-rw-r--r--lib/configuration.js125
1 files changed, 15 insertions, 110 deletions
diff --git a/lib/configuration.js b/lib/configuration.js
index 7488fae..24d435b 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -1,12 +1,13 @@
var _ = require('lodash');
var Q = require('q');
-var fs = require('fs');
var path = require('path');
var semver = require('semver');
var pkg = require('../package.json');
var i18n = require('./utils/i18n');
+var DEFAULT_CONFIG = require('./config_default');
+
// Default plugins added to each books
var DEFAULT_PLUGINS = ['highlight', 'search', 'sharing', 'fontsettings'];
@@ -85,9 +86,7 @@ var Configuration = function(book, options) {
var that = this;
this.book = book;
-
- this.options = _.cloneDeep(Configuration.DEFAULT);
- this.options = _.merge(this.options, options || {});
+ this.replace(options);
// options.input == book.root
Object.defineProperty(this.options, 'input', {
@@ -169,6 +168,17 @@ Configuration.prototype.extend = function(options) {
_.extend(this.options, options);
};
+// Replace the configuration
+Configuration.prototype.replace = function(options) {
+ this.options = _.cloneDeep(DEFAULT_CONFIG);
+ this.options = _.merge(this.options, options || {});
+};
+
+// Dump configuration as json object
+Configuration.prototype.dump = function() {
+ return _.cloneDeep(this.options);
+};
+
// Get structure file
Configuration.prototype.getStructure = function(name) {
return this.options.structure[name].split('.').slice(0, -1).join('.');
@@ -185,111 +195,6 @@ Configuration.prototype.get = function(key, def) {
};
// Default configuration
-Configuration.DEFAULT = {
- // Options that can't be extend
- 'configFile': 'book',
- 'generator': 'website',
- 'extension': null,
-
- // Book metadats (somes are extracted from the README by default)
- 'title': null,
- 'description': null,
- 'isbn': null,
- 'language': 'en',
- 'direction': null,
- 'author': null,
-
- // version of gitbook to use
- 'gitbook': '*',
-
- // Structure
- 'structure': {
- 'langs': 'LANGS.md',
- 'readme': 'README.md',
- 'glossary': 'GLOSSARY.md',
- 'summary': 'SUMMARY.md'
- },
-
- // CSS Styles
- 'styles': {
- 'website': 'styles/website.css',
- 'print': 'styles/print.css',
- 'ebook': 'styles/ebook.css',
- 'pdf': 'styles/pdf.css',
- 'mobi': 'styles/mobi.css',
- 'epub': 'styles/epub.css'
- },
-
- // Plugins list, can contain '-name' for removing default plugins
- 'plugins': [],
-
- // Global configuration for plugins
- 'pluginsConfig': {},
-
- // Variables for templating
- 'variables': {},
-
- // Set another theme with your own layout
- // It's recommended to use plugins or add more options for default theme, though
- // See https://github.com/GitbookIO/gitbook/issues/209
- 'theme': path.resolve(__dirname, '../theme'),
-
- // Links in template (null: default, false: remove, string: new value)
- 'links': {
- // Custom links at top of sidebar
- 'sidebar': {
- // 'Custom link name': 'https://customlink.com'
- },
-
- // Sharing links
- 'sharing': {
- 'google': null,
- 'facebook': null,
- 'twitter': null,
- 'weibo': null,
- 'all': null
- }
- },
-
-
- // Options for PDF generation
- 'pdf': {
- // Add toc at the end of the file
- 'toc': true,
-
- // Add page numbers to the bottom of every page
- 'pageNumbers': false,
-
- // Font size for the file content
- 'fontSize': 12,
-
- // Paper size for the pdf
- // Choices are [u’a0’, u’a1’, u’a2’, u’a3’, u’a4’, u’a5’, u’a6’, u’b0’, u’b1’, u’b2’, u’b3’, u’b4’, u’b5’, u’b6’, u’legal’, u’letter’]
- 'paperSize': 'a4',
-
- // How to mark detected chapters.
- // Choices are “pagebreak”, “rule”, 'both' or “none”.
- 'chapterMark' : 'pagebreak',
-
- // An XPath expression. Page breaks are inserted before the specified elements.
- // To disable use the expression: '/'
- 'pageBreaksBefore': '/',
-
- // Margin (in pts)
- // Note: 72 pts equals 1 inch
- 'margin': {
- 'right': 62,
- 'left': 62,
- 'top': 56,
- 'bottom': 56
- },
-
- // Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
- 'headerTemplate': null,
-
- // Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
- 'footerTemplate': null
- }
-};
+Configuration.DEFAULT = DEFAULT_CONFIG;
module.exports= Configuration;