summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-05-21 17:17:08 +0200
committerSamy Pessé <samypesse@gmail.com>2014-05-21 17:17:08 +0200
commit8d6923ce2cb0d6508a95435afb0cc51045cacaf6 (patch)
tree235edd547d180b55e68a21e290ccee7b5225723b
parent0e1717f4bb979ebdbba5500dd5ae85f7f10f3528 (diff)
parentb21fb24a82577f9caf7fc1db2e1559d128dd798f (diff)
downloadgitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.zip
gitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.tar.gz
gitbook-8d6923ce2cb0d6508a95435afb0cc51045cacaf6.tar.bz2
Merge pull request #234 from davidagraf/livereload
Livereload
-rw-r--r--.gitignore5
-rwxr-xr-xbin/gitbook.js18
-rw-r--r--lib/generate/plugin.js5
-rw-r--r--lib/generate/site/index.js10
-rw-r--r--package.json5
-rw-r--r--theme/templates/site.html6
6 files changed, 40 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 40e6da9..9bcfe7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,4 +24,7 @@ build/Release
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
-theme/javascript/vendors \ No newline at end of file
+theme/javascript/vendors
+
+# vim swapfile
+*.swp
diff --git a/bin/gitbook.js b/bin/gitbook.js
index 88083b9..ca68142 100755
--- a/bin/gitbook.js
+++ b/bin/gitbook.js
@@ -4,6 +4,7 @@ var Q = require('q');
var _ = require('lodash');
var path = require('path');
var prog = require('commander');
+var tinylr = require('tiny-lr-fork');
var pkg = require('../package.json');
var generators = require("../lib/generate").generators;
@@ -26,9 +27,19 @@ build.command(prog.command('serve [source_dir]'))
.description('Build then serve a gitbook from a directory')
.option('-p, --port <port>', 'Port for server to listen on', 4000)
.option('--no-watch', 'Disable restart with file watching')
+.option('--no-cache', 'Disable cache manifest generation')
.action(function(dir, options) {
var server = new Server();
+ // init livereload server
+ var lrOptions = {port: 35729};
+ var lrServer = tinylr(lrOptions);
+ var lrPath = undefined;
+ lrServer.listen(lrOptions.port, function(err) {
+ if (err) { return console.log(err); }
+ console.log('Live reload server started on port: ' + lrOptions.port);
+ });
+
var generate = function() {
if (server.isRunning()) console.log("Stopping server");
@@ -43,9 +54,16 @@ build.command(prog.command('serve [source_dir]'))
.then(function() {
console.log('Serving book on http://localhost:'+options.port);
+ if (lrPath) {
+ // trigger livereload
+ lrServer.changed({body:{files:[lrPath]}})
+ }
+
if (!options.watch) return;
return utils.watch(_options.input)
.then(function(filepath) {
+ // set livereload path
+ lrPath = filepath;
console.log("Restart after change in files");
console.log('');
return generate();
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js
index 2b06c15..5804f91 100644
--- a/lib/generate/plugin.js
+++ b/lib/generate/plugin.js
@@ -186,7 +186,8 @@ Plugin.fromList = function(names, root) {
// Default plugins
Plugin.defaults = [
"mixpanel",
- "mathjax"
+ "mathjax",
+ "livereload"
];
-module.exports = Plugin; \ No newline at end of file
+module.exports = Plugin;
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index b63f703..6033fb4 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -237,9 +237,13 @@ Generator.prototype.writeCacheManifest = function() {
};
Generator.prototype.finish = function() {
- return this.copyAssets()
- .then(this.writeSearchIndex)
- .then(this.writeCacheManifest);
+ var deferred = this.copyAssets().then(this.writeSearchIndex);
+
+ if (this.options.cache) {
+ deferred = deferred.then(this.writeCacheManifest);
+ }
+
+ return deferred;
};
module.exports = Generator;
diff --git a/package.json b/package.json
index 3eec991..93ff9f3 100644
--- a/package.json
+++ b/package.json
@@ -20,10 +20,11 @@
"semver": "2.2.1",
"gaze": "~0.5.1",
"resolve": "0.6.3",
-
+ "tiny-lr-fork": "0.0.5",
"gitbook-plugin": "0.0.2",
"gitbook-plugin-mixpanel": "0.0.2",
- "gitbook-plugin-mathjax": "0.0.3"
+ "gitbook-plugin-mathjax": "0.0.3",
+ "gitbook-plugin-livereload": "0.0.1"
},
"devDependencies": {
"mocha": "1.18.2",
diff --git a/theme/templates/site.html b/theme/templates/site.html
index af73030..a05cf4b 100644
--- a/theme/templates/site.html
+++ b/theme/templates/site.html
@@ -1,6 +1,10 @@
{% extends "layout.html" %}
-{% block htmlTag %}manifest="{{ basePath }}/manifest.appcache"{% endblock %}
+{% block htmlTag %}
+ {% if options.cache %}
+ manifest="{{ basePath }}/manifest.appcache"
+ {% endif %}
+{% endblock %}
{% block title %}{{ progress.current.title }}{% parent %}{% endblock %}
{% block content %}
<div class="book" {% if githubId %}data-github="{{ githubId }}"{% endif %} data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">