summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/generators/site.js9
-rw-r--r--lib/template.js4
-rw-r--r--package.json3
-rw-r--r--test/generation.js1
-rw-r--r--theme/templates/ebook/page.html2
-rw-r--r--theme/templates/ebook/summary.html4
-rw-r--r--theme/templates/website/glossary.html2
-rw-r--r--theme/templates/website/includes/exercise.html26
-rw-r--r--theme/templates/website/includes/header.html10
-rw-r--r--theme/templates/website/includes/quiz.html40
-rw-r--r--theme/templates/website/includes/summary.html14
-rw-r--r--theme/templates/website/page.html20
12 files changed, 40 insertions, 95 deletions
diff --git a/lib/generators/site.js b/lib/generators/site.js
index c8b9e91..a19da25 100644
--- a/lib/generators/site.js
+++ b/lib/generators/site.js
@@ -2,7 +2,11 @@ var util = require("util");
var path = require("path");
var Q = require("q");
var _ = require("lodash");
+
var nunjucks = require("nunjucks");
+var ParentExtension = require("nunjucks-parent");
+var AutoEscapeExtension = require("nunjucks-autoescape");
+var FilterExtension = require("nunjucks-filter");
var fs = require("../utils/fs");
var BaseGenerator = require("../generator");
@@ -74,6 +78,11 @@ Generator.prototype.prepareTemplates = function() {
}
);
+ // Add extension
+ this.env.addExtension('ParentExtension', new ParentExtension());
+ this.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(this.env));
+ this.env.addExtension('FilterExtension', new FilterExtension(this.env));
+
return Q();
};
diff --git a/lib/template.js b/lib/template.js
index e4df84c..27234f2 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -1,7 +1,9 @@
var _ = require("lodash");
var Q = require("q");
+
var nunjucks = require("nunjucks");
+
var TemplateEngine = function(book) {
this.book = book;
@@ -22,7 +24,7 @@ TemplateEngine.prototype.renderFile = function(filename) {
return that.book.statFile(filename)
.then(function(stat) {
var context = {
- // Variabels from book.json
+ // Variables from book.json
book: that.book.options.variables,
// infos about the file
diff --git a/package.json b/package.json
index 1037a6f..488c1ea 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,9 @@
"gitbook-markdown": "1.0.0",
"gitbook-asciidoctor": "1.0.0",
"nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747",
+ "nunjucks-parent": "0.1.0",
+ "unjucks-autoescape": "0.1.0",
+ "nunjucks-filter": "0.1.0",
"semver": "2.2.1",
"npmi": "0.1.1",
"cheerio": "0.18.0",
diff --git a/test/generation.js b/test/generation.js
index d2d0574..c2c8094 100644
--- a/test/generation.js
+++ b/test/generation.js
@@ -51,6 +51,7 @@ describe('Book generation', function () {
it('should correctly generate a book to website', function(done) {
testGeneration(book1, "site", function(output) {
+ console.log(fs.readdirSync(output));
assert(fs.existsSync(path.join(output, "index.html")));
}, done);
});
diff --git a/theme/templates/ebook/page.html b/theme/templates/ebook/page.html
index 3af7970..86f0df8 100644
--- a/theme/templates/ebook/page.html
+++ b/theme/templates/ebook/page.html
@@ -20,7 +20,7 @@
<div class="page">
<h1 class="book-chapter book-chapter-{{ progress.current.level|lvl }}">{{ progress.current.title }}</h1>
{% for section in content %}
- <div class="{{ section.type }}" id="section-{{ section.id }}">
+ <div class="{{ section.type }}" id="section-{{ section.id }}">
{% if section.type == "normal" %}
{% autoescape false %}{{ section.content }}{% endautoescape %}
{% elif section.type == "exercise" %}
diff --git a/theme/templates/ebook/summary.html b/theme/templates/ebook/summary.html
index ab4b78f..9a67d28 100644
--- a/theme/templates/ebook/summary.html
+++ b/theme/templates/ebook/summary.html
@@ -8,7 +8,7 @@
<li>
{% if item.path %}
{% if !externalLink %}
- <a href="{{ basePath }}/{{ item.path|mdLink }}">{{ item.title }}</a>
+ <a href="{{ basePath }}/{{ item.path|contentLink }}">{{ item.title }}</a>
{% else %}
<a target="_blank" href="{{ item.path }}">{{ item.title }}</a>
{% endif %}
@@ -17,7 +17,7 @@
{% endif %}
{% if item.articles.length > 0 %}
<ol>
- {{ articles(item.articles) }}
+ {{ articles(item.articles) }}
</ol>
{% endif %}
</li>
diff --git a/theme/templates/website/glossary.html b/theme/templates/website/glossary.html
index 4d9683f..5841f5e 100644
--- a/theme/templates/website/glossary.html
+++ b/theme/templates/website/glossary.html
@@ -10,7 +10,7 @@
<h4>Index</h4>
<ul class="glossary-index">
{% for file in item.files %}
- <li><a href="{{ basePath }}/{{ file.path|mdLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
+ <li><a href="{{ basePath }}/{{ file.path|contentLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
{% endfor %}
</ul>
</section>
diff --git a/theme/templates/website/includes/exercise.html b/theme/templates/website/includes/exercise.html
deleted file mode 100644
index 42b500f..0000000
--- a/theme/templates/website/includes/exercise.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<div class="header">
- <h2>Exercise</h2>
-</div>
-<div class="alert alert-success">
- <b>Correct!</b>
-</div>
-
-<div class="alert alert-danger error-message">
- <b>False!</b>
-</div>
-
-<div class="message">
- {% autoescape false %}{{ section.content }}{% endautoescape %}
-</div>
-<div class="editor" style="height: {{ section.code.solution|lines*20 }}px">{{ section.code.base }}</div>
-
-<pre class="hidden code-solution">{{ section.code.solution }}</pre>
-<pre class="hidden code-validation">{{ section.code.validation }}</pre>
-{% if section.code.context %}
-<pre class="hidden code-context">{{ section.code.context }}</pre>
-{% endif %}
-
-<div class="buttons">
- <a href="#" class="button size-2 action-submit">Submit</a>
- <a href="#" class="button size-2 action-solution">Solution</a>
-</div>
diff --git a/theme/templates/website/includes/header.html b/theme/templates/website/includes/header.html
index ef2de60..d3fb10e 100644
--- a/theme/templates/website/includes/header.html
+++ b/theme/templates/website/includes/header.html
@@ -12,7 +12,7 @@
</div>
<!-- Actions Right -->
- {% if options.links.sharing.all !== false %}
+ {% if options.links.sharing.all != false %}
<div class="dropdown pull-right">
<a href="#" class="btn toggle-dropdown" aria-label="Toggle share dropdown"><i class="fa fa-share-alt"></i>
</a>
@@ -32,16 +32,16 @@
</div>
{% endif %}
- {% if options.links.sharing.google !== false %}
+ {% if options.links.sharing.google != false %}
<a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Share on Google Plus"><i class="fa fa-google-plus"></i></a>
{% endif %}
- {% if options.links.sharing.facebook !== false %}
+ {% if options.links.sharing.facebook != false %}
<a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Share on Facebook"><i class="fa fa-facebook"></i></a>
{% endif %}
- {% if options.links.sharing.twitter !== false %}
+ {% if options.links.sharing.twitter != false %}
<a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Share on Twitter"><i class="fa fa-twitter"></i></a>
{% endif %}
- {% if options.links.sharing.weibo === true %}
+ {% if options.links.sharing.weibo == true %}
<a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="weibo" aria-label="Share on Weibo"><i class="fa fa-weibo"></i></a>
{% endif %}
diff --git a/theme/templates/website/includes/quiz.html b/theme/templates/website/includes/quiz.html
deleted file mode 100644
index 425fa39..0000000
--- a/theme/templates/website/includes/quiz.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<div class="header">
- <h2>Quiz</h2>
-</div>
-
-<div class="message">
- {% autoescape false %}{{ section.content }}{% endautoescape %}
-</div>
-
-
-{% for quiz in section.quiz %}
-<div class="question">
- <div class="question-header">Question {{ loop.index }} of {{ section.quiz.length }}</div>
-
- <div class="question-content">
- <div class="alert alert-success hidden">
- <b>Correct!</b>
- </div>
-
- <div class="alert alert-danger error-message hidden">
- <p><b>Not quite!</b></p>
- {% autoescape false %}{{ quiz.feedback }}{% endautoescape %}
- </div>
-
- <div class="question-inner">
- {% autoescape false %}{{ quiz.base }}{% endautoescape %}
- </div>
- </div>
-
- <div class="hidden question-answers">
- <div class="question-inner">
- {% autoescape false %}{{ quiz.solution }}{% endautoescape %}
- </div>
- </div>
-</div>
-{% endfor %}
-
-<div class="buttons">
- <a href="#" class="button size-2 action-submit">Submit</a>
- <a href="#" class="button size-2 action-solution">Solution</a>
-</div>
diff --git a/theme/templates/website/includes/summary.html b/theme/templates/website/includes/summary.html
index 3fff7fe..ffe9f16 100644
--- a/theme/templates/website/includes/summary.html
+++ b/theme/templates/website/includes/summary.html
@@ -1,12 +1,12 @@
{% macro articles(_articles) %}
{% for item in _articles %}
{% set externalLink = item.path|isExternalLink %}
- <li class="chapter {% if item.path == _input %}active{% endif %}" data-level="{{ item.level }}" {% if item.path && !externalLink %}data-path="{{ item.path|mdLink }}"{% endif %}>
+ <li class="chapter {% if item.path == _input %}active{% endif %}" data-level="{{ item.level }}" {% if item.path and not externalLink %}data-path="{{ item.path|contentLink }}"{% endif %}>
{% if item.path %}
- {% if !externalLink %}
- <a href="{{ basePath }}/{{ item.path|mdLink }}">
+ {% if not externalLink %}
+ <a href="{{ basePath }}/{{ item.path|contentLink }}">
<i class="fa fa-check"></i>
- {% if item.level !== "0" %}
+ {% if item.level != "0" %}
<b>{{ item.level }}.</b>
{% endif %}
{{ item.title }}
@@ -14,7 +14,7 @@
{% else %}
<a target="_blank" href="{{ item.path }}">
<i class="fa fa-check"></i>
- {% if item.level !== "0" %}
+ {% if item.level != "0" %}
<b>{{ item.level }}.</b>
{% endif %}
{{ item.title }}
@@ -25,7 +25,7 @@
{% endif %}
{% if item.articles.length > 0 %}
<ul class="articles">
- {{ articles(item.articles) }}
+ {{ articles(item.articles) }}
</ul>
{% endif %}
</li>
@@ -53,7 +53,7 @@
{{ articles(summary.chapters) }}
- {% if options.links.gitbook !== false %}
+ {% if options.links.gitbook != false %}
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">Published using GitBook</a>
diff --git a/theme/templates/website/page.html b/theme/templates/website/page.html
index 91f2162..37fc9dd 100644
--- a/theme/templates/website/page.html
+++ b/theme/templates/website/page.html
@@ -1,20 +1,20 @@
{% extends "./layout.html" %}
{% block head %}
- {% parent %}
+ {{ super() }}
{% if progress.current.next and progress.current.next.path %}
- <link rel="next" href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" />
+ <link rel="next" href="{{ basePath }}/{{ progress.current.next.path|contentLink }}" />
{% endif %}
{% if progress.current.prev and progress.current.prev.path %}
- <link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" />
+ <link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|contentLink }}" />
{% endif %}
{% endblock %}
{% block title %}{{ progress.current.title }} | {{ title }}{% endblock %}
-{% block description %}{% if progress.current.level == "0" %}{{ description }}{% endif %}{% endblock %}
+{% block description %}{% if progress.current.level == "0" %}{{ description }}{% endif %}{% endblock %}
{% block content %}
- <div class="book" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
+ <div class="book" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
{% include "includes/summary.html" %}
<div class="book-body">
<div class="body-inner">
@@ -23,13 +23,9 @@
<div class="page-inner">
{% block page_inner %}
{% for section in content %}
- <section class="{{ section.type }}" id="section-{{ section.id }}">
+ <section class="{{ section.type }}" id="section-{{ section.id }}">
{% if section.type == "normal" %}
{% autoescape false %}{{ section.content }}{% endautoescape %}
- {% elif section.type == "exercise" %}
- {% include "./includes/exercise.html" with {section: section} %}
- {% elif section.type == "quiz" %}
- {% include "./includes/quiz.html" with {section: section} %}
{% endif %}
</section>
{% endfor %}
@@ -39,10 +35,10 @@
</div>
{% if progress.current.prev and progress.current.prev.path %}
- <a href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" class="navigation navigation-prev {% if !progress.current.next or !progress.current.next.path %}navigation-unique{% endif %}" aria-label="Previous page: {{ progress.current.prev.title }}"><i class="fa fa-angle-left"></i></a>
+ <a href="{{ basePath }}/{{ progress.current.prev.path|contentLink }}" class="navigation navigation-prev {% if not (progress.current.next and progress.current.next.path) %}navigation-unique{% endif %}" aria-label="Previous page: {{ progress.current.prev.title }}"><i class="fa fa-angle-left"></i></a>
{% endif %}
{% if progress.current.next and progress.current.next.path %}
- <a href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" class="navigation navigation-next {% if !progress.current.prev or !progress.current.prev.path %}navigation-unique{% endif %}" aria-label="Next page: {{ progress.current.next.title }}"><i class="fa fa-angle-right"></i></a>
+ <a href="{{ basePath }}/{{ progress.current.next.path|contentLink }}" class="navigation navigation-next {% if not (progress.current.prev or progress.current.prev.path) %}navigation-unique{% endif %}" aria-label="Next page: {{ progress.current.next.title }}"><i class="fa fa-angle-right"></i></a>
{% endif %}
</div>
</div>