summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-10-05 10:32:43 +0200
committerSamy Pessé <samypesse@gmail.com>2015-10-05 10:32:43 +0200
commiteab3c50288a0fa35237bd38536ee1f223250beaf (patch)
tree427078d8e8058a1728453654d8cab4e464d35306 /lib
parent74396e7240f00b6f38239eedf2b10547a4868b4c (diff)
downloadgitbook-eab3c50288a0fa35237bd38536ee1f223250beaf.zip
gitbook-eab3c50288a0fa35237bd38536ee1f223250beaf.tar.gz
gitbook-eab3c50288a0fa35237bd38536ee1f223250beaf.tar.bz2
Add sharing plugin as default
Diffstat (limited to 'lib')
-rw-r--r--lib/configuration.js176
-rw-r--r--lib/pluginslist.js52
2 files changed, 114 insertions, 114 deletions
diff --git a/lib/configuration.js b/lib/configuration.js
index c8b15b8..93dc29c 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -1,13 +1,13 @@
-var _ = require("lodash");
-var Q = require("q");
-var path = require("path");
-var semver = require("semver");
+var _ = require('lodash');
+var Q = require('q');
+var path = require('path');
+var semver = require('semver');
-var pkg = require("../package.json");
-var i18n = require("./utils/i18n");
+var pkg = require('../package.json');
+var i18n = require('./utils/i18n');
// Default plugins added to each books
-var DEFAULT_PLUGINS = ["highlight"];
+var DEFAULT_PLUGINS = ['highlight', 'sharing'];
// Check if a plugin is a default plugin
// Plugin should be in the list
@@ -26,29 +26,29 @@ function isDefaultPlugin(name, version) {
// Normalize a list of plugins to use
function normalizePluginsList(plugins, addDefaults) {
// Normalize list to an array
- plugins = _.isString(plugins) ? plugins.split(",") : (plugins || []);
+ plugins = _.isString(plugins) ? plugins.split(',') : (plugins || []);
// Remove empty parts
plugins = _.compact(plugins);
- // Divide as {name, version} to handle format like "myplugin@1.0.0"
+ // Divide as {name, version} to handle format like 'myplugin@1.0.0'
plugins = _.map(plugins, function(plugin) {
if (plugin.name) return plugin;
- var parts = plugin.split("@");
+ var parts = plugin.split('@');
var name = parts[0];
var version = parts[1];
return {
- "name": name,
- "version": version, // optional
- "isDefault": isDefaultPlugin(name, version)
+ 'name': name,
+ 'version': version, // optional
+ 'isDefault': isDefaultPlugin(name, version)
};
});
// List plugins to remove
var toremove = _.chain(plugins)
.filter(function(plugin) {
- return plugin.name.length > 0 && plugin.name[0] == "-";
+ return plugin.name.length > 0 && plugin.name[0] == '-';
})
.map(function(plugin) {
return plugin.name.slice(1);
@@ -63,15 +63,15 @@ function normalizePluginsList(plugins, addDefaults) {
}
plugins.push({
- "name": plugin,
- "isDefault": true
+ 'name': plugin,
+ 'isDefault': true
});
});
}
// Remove plugin that start with '-'
plugins = _.filter(plugins, function(plugin) {
- return !_.contains(toremove, plugin.name) && !(plugin.name.length > 0 && plugin.name[0] == "-");
+ return !_.contains(toremove, plugin.name) && !(plugin.name.length > 0 && plugin.name[0] == '-');
});
// Remove duplicates
@@ -89,21 +89,21 @@ var Configuration = function(book, options) {
this.options = _.merge(this.options, options || {});
// options.input == book.root
- Object.defineProperty(this.options, "input", {
+ Object.defineProperty(this.options, 'input', {
get: function () {
return that.book.root;
}
});
// options.originalInput == book.parent.root
- Object.defineProperty(this.options, "originalInput", {
+ Object.defineProperty(this.options, 'originalInput', {
get: function () {
return that.book.parent? that.book.parent.root : undefined;
}
});
// options.originalOutput == book.parent.options.output
- Object.defineProperty(this.options, "originalOutput", {
+ Object.defineProperty(this.options, 'originalOutput', {
get: function () {
return that.book.parent? that.book.parent.options.output : undefined;
}
@@ -129,7 +129,7 @@ Configuration.prototype.load = function() {
_config = require(configPath);
that.options = _.merge(
that.options,
- _.omit(_config, "configFile", "defaultsPlugins", "generator", "extension")
+ _.omit(_config, 'configFile', 'defaultsPlugins', 'generator', 'extension')
);
}
catch(err) {
@@ -140,18 +140,18 @@ Configuration.prototype.load = function() {
.then(function() {
if (!that.book.isSubBook()) {
if (!semver.satisfies(pkg.version, that.options.gitbook)) {
- throw new Error("GitBook version doesn't satisfy version required by the book: "+that.options.gitbook);
+ throw new Error('GitBook version doesn't satisfy version required by the book: '+that.options.gitbook);
}
- if (that.options.gitbook != "*" && !semver.satisfies(semver.inc(pkg.version, "patch"), that.options.gitbook)) {
- that.book.log.warn.ln("gitbook version specified in your book.json might be too strict for future patches, \""+(_.first(pkg.version.split("."))+".x.x")+"\" is more adequate");
+ if (that.options.gitbook != '*' && !semver.satisfies(semver.inc(pkg.version, 'patch'), that.options.gitbook)) {
+ that.book.log.warn.ln('gitbook version specified in your book.json might be too strict for future patches, \''+(_.first(pkg.version.split('.'))+'.x.x')+'\' is more adequate');
}
}
- that.options.output = path.resolve(that.options.output || that.book.resolve("_book"));
+ that.options.output = path.resolve(that.options.output || that.book.resolve('_book'));
that.options.plugins = normalizePluginsList(that.options.plugins);
- that.options.defaultsPlugins = normalizePluginsList(that.options.defaultsPlugins || "", false);
+ that.options.defaultsPlugins = normalizePluginsList(that.options.defaultsPlugins || '', false);
that.options.plugins = _.union(that.options.plugins, that.options.defaultsPlugins);
- that.options.plugins = _.uniq(that.options.plugins, "name");
+ that.options.plugins = _.uniq(that.options.plugins, 'name');
// Default value for text direction (from language)
if (!that.options.direction) {
@@ -170,7 +170,7 @@ Configuration.prototype.extend = function(options) {
// Get structure file
Configuration.prototype.getStructure = function(name) {
- return this.options.structure[name].split(".").slice(0, -1).join(".");
+ return this.options.structure[name].split('.').slice(0, -1).join('.');
};
// Return normalized language
@@ -185,120 +185,120 @@ Configuration.prototype.get = function(key, def) {
// Default configuration
Configuration.DEFAULT = {
- // Options that can"t be extend
- "configFile": "book",
- "generator": "website",
- "extension": null,
+ // 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,
+ 'title': null,
+ 'description': null,
+ 'isbn': null,
+ 'language': 'en',
+ 'direction': null,
+ 'author': null,
// version of gitbook to use
- "gitbook": "*",
+ 'gitbook': '*',
// Search index
- "search": {
- "maxIndexSize": 1000000
+ 'search': {
+ 'maxIndexSize': 1000000
},
// Structure
- "structure": {
- "langs": "LANGS.md",
- "readme": "README.md",
- "glossary": "GLOSSARY.md",
- "summary": "SUMMARY.md"
+ '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"
+ '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": [],
+ // Plugins list, can contain '-name' for removing default plugins
+ 'plugins': [],
// Global configuration for plugins
- "pluginsConfig": {
- "fontSettings": {
- "theme": null, //"sepia", "night" or "white",
- "family": "sans",// "serif" or "sans",
- "size": 2 // 1 - 4
+ 'pluginsConfig': {
+ 'fontSettings': {
+ 'theme': null, //'sepia', 'night' or 'white',
+ 'family': 'sans',// 'serif' or 'sans',
+ 'size': 2 // 1 - 4
}
},
// Variables for templating
- "variables": {},
+ 'variables': {},
// Set another theme with your own layout
- // It"s recommended to use plugins or add more options for default theme, though
+ // 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"),
+ 'theme': path.resolve(__dirname, '../theme'),
// Links in template (null: default, false: remove, string: new value)
- "links": {
+ 'links': {
// Custom links at top of sidebar
- "sidebar": {
- //"Custom link name": "https://customlink.com"
+ 'sidebar': {
+ //'Custom link name': 'https://customlink.com'
},
// Sharing links
- "sharing": {
- "google": null,
- "facebook": null,
- "twitter": null,
- "weibo": null,
- "all": null
+ 'sharing': {
+ 'google': null,
+ 'facebook': null,
+ 'twitter': null,
+ 'weibo': null,
+ 'all': null
}
},
// Options for PDF generation
- "pdf": {
+ 'pdf': {
// Add toc at the end of the file
- "toc": true,
+ 'toc': true,
// Add page numbers to the bottom of every page
- "pageNumbers": false,
+ 'pageNumbers': false,
// Font size for the file content
- "fontSize": 12,
+ '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",
+ 'paperSize': 'a4',
// How to mark detected chapters.
- // Choices are “pagebreak”, “rule”, "both" or “none”.
- "chapterMark" : "pagebreak",
+ // 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": "/",
+ // To disable use the expression: '/'
+ 'pageBreaksBefore': '/',
// Margin (in pts)
// Note: 72 pts equals 1 inch
- "margin": {
- "right": 62,
- "left": 62,
- "top": 56,
- "bottom": 56
+ 'margin': {
+ 'right': 62,
+ 'left': 62,
+ 'top': 56,
+ 'bottom': 56
},
//Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
- "headerTemplate": "",
+ 'headerTemplate': '',
//Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
- "footerTemplate": ""
+ 'footerTemplate': ''
}
};
diff --git a/lib/pluginslist.js b/lib/pluginslist.js
index 80e1d3e..e4594d6 100644
--- a/lib/pluginslist.js
+++ b/lib/pluginslist.js
@@ -1,14 +1,14 @@
-var _ = require("lodash");
-var Q = require("q");
-var npmi = require("npmi");
-var npm = require("npm");
-var semver = require("semver");
+var _ = require('lodash');
+var Q = require('q');
+var npmi = require('npmi');
+var npm = require('npm');
+var semver = require('semver');
-var Plugin = require("./plugin");
-var pkg = require("../package.json");
+var Plugin = require('./plugin');
+var pkg = require('../package.json');
var initNPM = _.memoize(function() {
- return Q.nfcall(npm.load, { silent: true, loglevel: "silent" });
+ return Q.nfcall(npm.load, { silent: true, loglevel: 'silent' });
});
@@ -23,7 +23,7 @@ var PluginsList = function(book, plugins) {
this.failed = [];
// Namespaces
- this.namespaces = _.chain(["website", "ebook"])
+ this.namespaces = _.chain(['website', 'ebook'])
.map(function(namespace) {
return [
namespace,
@@ -66,7 +66,7 @@ PluginsList.prototype.load = function(plugin) {
if (_.isObject(plugin) && !(plugin instanceof Plugin)) plugin = plugin.name;
if (_.isString(plugin)) plugin = new Plugin(this.book, plugin);
- that.log.info("load plugin", plugin.name, "....");
+ that.log.info('load plugin', plugin.name, '....');
if (!plugin.isValid()) {
that.log.info.fail();
that.failed.push(plugin.name);
@@ -135,7 +135,7 @@ PluginsList.prototype.html = function(namespace, tag, context, options) {
var htmlSnippets = this.namespaces[namespace].html[tag];
return _.map(htmlSnippets || [], function(code) {
return code.call(context, options);
- }).join("\n");
+ }).join('\n');
};
// Return a resources map for a namespace
@@ -153,10 +153,10 @@ PluginsList.prototype.install = function() {
});
// Install plugins one by one
- that.book.log.info.ln(plugins.length+" plugins to install");
+ that.book.log.info.ln(plugins.length+' plugins to install');
return _.reduce(plugins, function(prev, plugin) {
return prev.then(function() {
- var fullname = "gitbook-plugin-"+plugin.name;
+ var fullname = 'gitbook-plugin-'+plugin.name;
return Q()
@@ -164,10 +164,10 @@ PluginsList.prototype.install = function() {
.then(function() {
if (plugin.version) return plugin.version;
- that.book.log.info.ln("No version specified, resolve plugin", plugin.name);
+ that.book.log.info.ln('No version specified, resolve plugin', plugin.name);
return initNPM()
.then(function() {
- return Q.nfcall(npm.commands.view, [fullname+"@*", "engines"], true);
+ return Q.nfcall(npm.commands.view, [fullname+'@*', 'engines'], true);
})
.then(function(versions) {
return _.chain(versions)
@@ -184,7 +184,7 @@ PluginsList.prototype.install = function() {
.sort(function(v1, v2) {
return semver.lt(v1.version, v2.version)? 1 : -1;
})
- .pluck("version")
+ .pluck('version')
.first()
.value();
});
@@ -193,23 +193,23 @@ PluginsList.prototype.install = function() {
// Install the plugin with the resolved version
.then(function(version) {
if (!version) {
- throw "Found no satisfactory version for plugin "+plugin.name;
+ throw 'Found no satisfactory version for plugin '+plugin.name;
}
- that.book.log.info.ln("install plugin", plugin.name, "from npm ("+fullname+") with version", version);
+ that.book.log.info.ln('install plugin', plugin.name, 'from npm ('+fullname+') with version', version);
return Q.nfcall(npmi, {
- "name": fullname,
- "version": version,
- "path": that.book.root,
- "npmLoad": {
- "loglevel": "silent",
- "loaded": true,
- "prefix": that.book.root
+ 'name': fullname,
+ 'version': version,
+ 'path': that.book.root,
+ 'npmLoad': {
+ 'loglevel': 'silent',
+ 'loaded': true,
+ 'prefix': that.book.root
}
});
})
.then(function() {
- that.book.log.info.ok("plugin", plugin.name, "installed with success");
+ that.book.log.info.ok('plugin', plugin.name, 'installed with success');
});
});
}, Q());