diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-04 14:40:27 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-04 14:40:27 -0700 |
commit | b3adedb468231e1a8497607ceb7455d58037c2c4 (patch) | |
tree | 44ef8c3e2ca6b82e18cd295f2da9368a22246ece | |
parent | 026e4362d825f004c4eb9a6471dc5bb91bbac198 (diff) | |
download | gitbook-b3adedb468231e1a8497607ceb7455d58037c2c4.zip gitbook-b3adedb468231e1a8497607ceb7455d58037c2c4.tar.gz gitbook-b3adedb468231e1a8497607ceb7455d58037c2c4.tar.bz2 |
Add base for generating single page html
-rw-r--r-- | lib/generate/index.js | 5 | ||||
-rw-r--r-- | lib/generate/page/index.js | 57 | ||||
-rw-r--r-- | lib/generate/site/index.js | 5 | ||||
-rw-r--r-- | theme/templates/layout.html | 2 | ||||
-rw-r--r-- | theme/templates/page.html | 18 |
5 files changed, 79 insertions, 8 deletions
diff --git a/lib/generate/index.js b/lib/generate/index.js index 9dcf409..4ed9f08 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -30,7 +30,10 @@ var generate = function(options) { // Origin github repository id github: null, - githubHost: 'https://github.com/' + githubHost: 'https://github.com/', + + // Theming + theme: path.resolve(__dirname, '../../theme') }); if (!options.github || !options.title || !options.input || !options.output) { diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js index 4b22dba..896bf52 100644 --- a/lib/generate/page/index.js +++ b/lib/generate/page/index.js @@ -1,6 +1,7 @@ var util = require("util"); var path = require("path"); var Q = require("q"); +var swig = require('swig'); var fs = require("../fs"); var parse = require("../../parse"); @@ -12,6 +13,12 @@ var BaseGenerator = require("../generator"); */ var Generator = function() { BaseGenerator.apply(this, arguments); + + // Load base template + this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/page.html')); + + // List of pages content + this.pages = []; }; util.inherits(Generator, BaseGenerator); @@ -20,11 +27,57 @@ Generator.prototype.transferFile = function(input) { }; Generator.prototype.convertFile = function(content, input) { - + var that = this; + var json = { + path: input, + progress: parse.progress(this.options.navigation, input) + }; + + return Q() + .then(function() { + return parse.page(content, { + repo: that.options.githubId, + dir: path.dirname(input) || '/' + }); + }) + .then(function(sections) { + json.content = sections; + }) + .then(function() { + that.pages.push(json); + }); }; Generator.prototype.finish = function() { - // ignore + var that = this; + var basePath = "."; + var output = path.join(this.options.output, "index.html"); + + return Q() + .then(function() { + return that.template({ + title: that.options.title, + description: that.options.description, + + githubAuthor: that.options.github.split("/")[0], + githubId: that.options.github, + githubHost: that.options.githubHost, + + summary: that.options.summary, + allNavigation: that.options.navigation, + + pages: that.pages, + + basePath: basePath, + staticBase: path.join(basePath, "gitbook"), + }); + }) + .then(function(html) { + return fs.writeFile( + output, + html + ); + }); }; module.exports = Generator;
\ No newline at end of file diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 3110d4f..84a0d2f 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -21,11 +21,6 @@ swig.setFilter('mdLink', function(link) { var Generator = function() { BaseGenerator.apply(this, arguments); - // Options - this.options = _.defaults(this.options, { - theme: path.resolve(__dirname, '../../../theme') - }); - // Load base template this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/site.html')); }; diff --git a/theme/templates/layout.html b/theme/templates/layout.html index dd319d0..3057f4b 100644 --- a/theme/templates/layout.html +++ b/theme/templates/layout.html @@ -37,9 +37,11 @@ </head> <body> {% block content %}{% endblock %} + {% block javascript %} <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/mode-javascript.js"></script> <script src="{{ staticBase }}/jsrepl/jsrepl.js" id="jsrepl-script"></script> <script src="{{ staticBase }}/app.js"></script> + {% endblock %} </body> </html> diff --git a/theme/templates/page.html b/theme/templates/page.html new file mode 100644 index 0000000..8b1048d --- /dev/null +++ b/theme/templates/page.html @@ -0,0 +1,18 @@ +{% extends "layout.html" %} + +{% block title %}{{ title }}{% endblock %} + +{% block content %} + {% for page in pages %} + <hr> + <article id="{{ page.path }}"> + {% for section in page.content %} + {% if section.type == "normal" %} + {% autoescape false %}{{ section.content }}{% endautoescape %} + {% endif %} + {% endfor %} + </article> + {% endfor %} +{% endblock %} + +{% block javascript %}{% endblock %}
\ No newline at end of file |