From bd931c5cbdced15701a9bba4806350dedc359221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 21 Jan 2015 19:15:57 +0100 Subject: [PATCH] Adapt themes website templates --- lib/generators/site.js | 9 +++++ lib/template.js | 4 +- package.json | 3 ++ test/generation.js | 1 + theme/templates/ebook/page.html | 2 +- theme/templates/ebook/summary.html | 4 +- theme/templates/website/glossary.html | 2 +- .../templates/website/includes/exercise.html | 26 ------------ theme/templates/website/includes/header.html | 10 ++--- theme/templates/website/includes/quiz.html | 40 ------------------- theme/templates/website/includes/summary.html | 14 +++---- theme/templates/website/page.html | 20 ++++------ 12 files changed, 40 insertions(+), 95 deletions(-) delete mode 100644 theme/templates/website/includes/exercise.html delete mode 100644 theme/templates/website/includes/quiz.html diff --git a/lib/generators/site.js b/lib/generators/site.js index c8b9e91b4..a19da25f1 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 e4df84cf0..27234f22a 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 1037a6ffc..488c1ea6e 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 d2d057430..c2c80947e 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 3af7970cb..86f0df869 100644 --- a/theme/templates/ebook/page.html +++ b/theme/templates/ebook/page.html @@ -20,7 +20,7 @@

{{ progress.current.title }}

{% for section in content %} -
+
{% 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 ab4b78fb1..9a67d2800 100644 --- a/theme/templates/ebook/summary.html +++ b/theme/templates/ebook/summary.html @@ -8,7 +8,7 @@
  • {% if item.path %} {% if !externalLink %} - {{ item.title }} + {{ item.title }} {% else %} {{ item.title }} {% endif %} @@ -17,7 +17,7 @@ {% endif %} {% if item.articles.length > 0 %}
      - {{ articles(item.articles) }} + {{ articles(item.articles) }}
    {% endif %}
  • diff --git a/theme/templates/website/glossary.html b/theme/templates/website/glossary.html index 4d9683f2a..5841f5e97 100644 --- a/theme/templates/website/glossary.html +++ b/theme/templates/website/glossary.html @@ -10,7 +10,7 @@

    Index

    diff --git a/theme/templates/website/includes/exercise.html b/theme/templates/website/includes/exercise.html deleted file mode 100644 index 42b500f53..000000000 --- a/theme/templates/website/includes/exercise.html +++ /dev/null @@ -1,26 +0,0 @@ -
    -

    Exercise

    -
    -
    - Correct! -
    - -
    - False! -
    - -
    - {% autoescape false %}{{ section.content }}{% endautoescape %} -
    -
    {{ section.code.base }}
    - - - -{% if section.code.context %} - -{% endif %} - - diff --git a/theme/templates/website/includes/header.html b/theme/templates/website/includes/header.html index ef2de6010..d3fb10e32 100644 --- a/theme/templates/website/includes/header.html +++ b/theme/templates/website/includes/header.html @@ -12,7 +12,7 @@
    - {% if options.links.sharing.all !== false %} + {% if options.links.sharing.all != false %} {% endif %} - {% if options.links.sharing.google !== false %} + {% if options.links.sharing.google != false %} {% endif %} - {% if options.links.sharing.facebook !== false %} + {% if options.links.sharing.facebook != false %} {% endif %} - {% if options.links.sharing.twitter !== false %} + {% if options.links.sharing.twitter != false %} {% endif %} - {% if options.links.sharing.weibo === true %} + {% if options.links.sharing.weibo == true %} {% endif %} diff --git a/theme/templates/website/includes/quiz.html b/theme/templates/website/includes/quiz.html deleted file mode 100644 index 425fa398a..000000000 --- a/theme/templates/website/includes/quiz.html +++ /dev/null @@ -1,40 +0,0 @@ -
    -

    Quiz

    -
    - -
    - {% autoescape false %}{{ section.content }}{% endautoescape %} -
    - - -{% for quiz in section.quiz %} -
    -
    Question {{ loop.index }} of {{ section.quiz.length }}
    - -
    - - - - -
    - {% autoescape false %}{{ quiz.base }}{% endautoescape %} -
    -
    - - -
    -{% endfor %} - - diff --git a/theme/templates/website/includes/summary.html b/theme/templates/website/includes/summary.html index 3fff7fe6e..ffe9f16b3 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 %} -
  • +
  • {% if item.path %} - {% if !externalLink %} - + {% if not externalLink %} + - {% if item.level !== "0" %} + {% if item.level != "0" %} {{ item.level }}. {% endif %} {{ item.title }} @@ -14,7 +14,7 @@ {% else %} - {% if item.level !== "0" %} + {% if item.level != "0" %} {{ item.level }}. {% endif %} {{ item.title }} @@ -25,7 +25,7 @@ {% endif %} {% if item.articles.length > 0 %}
      - {{ articles(item.articles) }} + {{ articles(item.articles) }}
    {% endif %}
  • @@ -53,7 +53,7 @@ {{ articles(summary.chapters) }} - {% if options.links.gitbook !== false %} + {% if options.links.gitbook != false %}
  • Published using GitBook diff --git a/theme/templates/website/page.html b/theme/templates/website/page.html index 91f2162dd..37fc9ddbb 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 %} - + {% endif %} {% if progress.current.prev and progress.current.prev.path %} - + {% 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 %} -
    +
    {% include "includes/summary.html" %}
    @@ -23,13 +23,9 @@
    {% block page_inner %} {% for section in content %} -
    +
    {% 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 %}
    {% endfor %} @@ -39,10 +35,10 @@
    {% if progress.current.prev and progress.current.prev.path %} - + {% endif %} {% if progress.current.next and progress.current.next.path %} - + {% endif %}