summaryrefslogtreecommitdiffstats
path: root/lib/generate
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-05-23 17:00:37 +0200
committerSamy Pessé <samypesse@gmail.com>2014-05-23 17:00:37 +0200
commit7c0b88cf2e1615e6c9e889052dbda31c3f8ad3f1 (patch)
tree3c2dd8a39cc477f00b1881764f0fd7bf0a67a650 /lib/generate
parentbf21633b6c0f08f69452ceccf5e3c80dcbd62ad4 (diff)
downloadgitbook-7c0b88cf2e1615e6c9e889052dbda31c3f8ad3f1.zip
gitbook-7c0b88cf2e1615e6c9e889052dbda31c3f8ad3f1.tar.gz
gitbook-7c0b88cf2e1615e6c9e889052dbda31c3f8ad3f1.tar.bz2
Plugins can extend html
Diffstat (limited to 'lib/generate')
-rw-r--r--lib/generate/plugin.js15
-rw-r--r--lib/generate/site/index.js1
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js
index 1edb62d..19eec86 100644
--- a/lib/generate/plugin.js
+++ b/lib/generate/plugin.js
@@ -160,6 +160,16 @@ Plugin.fromList = function(names, root) {
})
.object()
.value();
+ resources.html = {}
+
+ _.each(plugins, function(plugin) {
+ var html = plugin.infos.book.html || {};
+ _.each(html, function(code, key) {
+ if (!_.isFunction(code)) code = _.constant(code);
+ if (!resources.html[key]) resources.html[key] = [];
+ resources.html[key].push(code);
+ })
+ });
return Q({
'list': plugins,
@@ -179,6 +189,11 @@ Plugin.fromList = function(names, root) {
if (!withTpl) return null;
return withTpl.resolveFile(withTpl.infos.templates[name]);
+ },
+ 'html': function(tag, context, options) {
+ return _.map(resources.html[tag] || [], function(code) {
+ return code.call(context, options);
+ }).join("\n");
}
});
};
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index 6033fb4..a135cda 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -81,6 +81,7 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate)
plugins: that.plugins,
pluginsConfig: JSON.stringify(that.options.pluginsConfig),
+ htmlSnippet: _.partialRight(that.plugins.html, that, options),
options: that.options
}, options));