summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-06-02 11:00:22 +0200
committerSamy Pessé <samypesse@gmail.com>2015-06-02 11:00:22 +0200
commita9a230dfc31d9d5092adda51344b0c9f725d9788 (patch)
treee9b864c6c0e08d37afce0df70b1a9bffdb3f94a9
parent13fb949d6818bc47a2215ee788c392fa38e1e1d6 (diff)
parent6d53e5277100fe6a9372dea4ab9d70c769a28176 (diff)
downloadgitbook-a9a230dfc31d9d5092adda51344b0c9f725d9788.zip
gitbook-a9a230dfc31d9d5092adda51344b0c9f725d9788.tar.gz
gitbook-a9a230dfc31d9d5092adda51344b0c9f725d9788.tar.bz2
Merge pull request #781 from GitbookIO/fix/775
Fix #775: add optional print.css style
-rw-r--r--lib/configuration.js1
-rw-r--r--lib/generators/ebook.js2
-rw-r--r--lib/generators/website.js5
-rw-r--r--test/assertions.js2
-rw-r--r--test/books/style-print/README.md3
-rw-r--r--test/books/style-print/SUMMARY.md1
-rw-r--r--test/books/style-print/styles/print.css3
-rw-r--r--test/ebook.js31
-rw-r--r--theme/templates/ebook/page.html4
-rw-r--r--theme/templates/website/page.html2
10 files changed, 48 insertions, 6 deletions
diff --git a/lib/configuration.js b/lib/configuration.js
index d206505..29776bd 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -186,6 +186,7 @@ Configuration.DEFAULT = {
// CSS Styles
"styles": {
"website": "styles/website.css",
+ "print": "styles/print.css",
"ebook": "styles/ebook.css",
"pdf": "styles/pdf.css",
"mobi": "styles/mobi.css",
diff --git a/lib/generators/ebook.js b/lib/generators/ebook.js
index 0bad35a..cff9ef6 100644
--- a/lib/generators/ebook.js
+++ b/lib/generators/ebook.js
@@ -18,7 +18,7 @@ var Generator = function(book, format) {
this.namespace = "ebook";
// Styles to use
- this.styles = _.compact(["ebook", this.ebookFormat]);
+ this.styles = _.compact(["print", "ebook", this.ebookFormat]);
// Convert images (svg -> png)
this.convertImages = true;
diff --git a/lib/generators/website.js b/lib/generators/website.js
index 8d1a3c5..de833d3 100644
--- a/lib/generators/website.js
+++ b/lib/generators/website.js
@@ -50,12 +50,13 @@ Generator.prototype.prepareStyles = function() {
this.styles = _.chain(this.styles)
.map(function(style) {
var stylePath = that.options.styles[style];
- if (fs.existsSync(path.resolve(that.book.root, stylePath))) {
- return stylePath;
+ if (stylePath && fs.existsSync(path.resolve(that.book.root, stylePath))) {
+ return [style, stylePath];
}
return null;
})
.compact()
+ .object()
.value();
return Q();
diff --git a/test/assertions.js b/test/assertions.js
index d807d4d..7a34380 100644
--- a/test/assertions.js
+++ b/test/assertions.js
@@ -35,7 +35,7 @@ should.Assertion.add('html', function(rules, description) {
var $el = $(query);
// Test number of elements
- $el.should.have.lengthOf(validations.count);
+ $el.length.should.be.equal(validations.count);
// Test text
if (validations.text !== undefined) {
diff --git a/test/books/style-print/README.md b/test/books/style-print/README.md
new file mode 100644
index 0000000..09ade40
--- /dev/null
+++ b/test/books/style-print/README.md
@@ -0,0 +1,3 @@
+# Readme
+
+Default description for the book.
diff --git a/test/books/style-print/SUMMARY.md b/test/books/style-print/SUMMARY.md
new file mode 100644
index 0000000..ac9323c
--- /dev/null
+++ b/test/books/style-print/SUMMARY.md
@@ -0,0 +1 @@
+# Summary
diff --git a/test/books/style-print/styles/print.css b/test/books/style-print/styles/print.css
new file mode 100644
index 0000000..b05faf8
--- /dev/null
+++ b/test/books/style-print/styles/print.css
@@ -0,0 +1,3 @@
+body {
+ color: red;
+}
diff --git a/test/ebook.js b/test/ebook.js
index c9bb924..9b353d2 100644
--- a/test/ebook.js
+++ b/test/ebook.js
@@ -21,4 +21,35 @@ describe('eBook generator', function () {
book.should.have.file("gitbook/style.css");
});
});
+
+ describe('Custom styles', function() {
+ var book;
+
+ before(function() {
+ return books.generate("style-print", "ebook")
+ .then(function(_book) {
+ book = _book;
+ });
+ });
+
+ it('should remove default print.css', function() {
+ var PAGE = fs.readFileSync(
+ path.join(book.options.output, "index.html"),
+ { encoding: "utf-8" }
+ );
+ PAGE.should.be.html({
+ "link": {
+ count: 1,
+ attributes: {
+ href: "./styles/print.css"
+ }
+ }
+ });
+ });
+
+ it('should correctly print.css', function() {
+ book.should.have.file("styles");
+ book.should.have.file("styles/print.css");
+ });
+ })
});
diff --git a/theme/templates/ebook/page.html b/theme/templates/ebook/page.html
index 0951c27..f207184 100644
--- a/theme/templates/ebook/page.html
+++ b/theme/templates/ebook/page.html
@@ -3,7 +3,9 @@
{% block title %}{{ progress.current.title }} | {{ title }}{% endblock %}
{% block style %}
+ {% if not styles.print %}
<link rel="stylesheet" href="{{ staticBase }}/print.css">
+ {% endif %}
{% for resource in plugins.resources.css %}
{% if resource.url %}
<link rel="stylesheet" href="{{ resource.url }}">
@@ -11,7 +13,7 @@
<link rel="stylesheet" href="{{ staticBase }}/plugins/{{ resource.path }}">
{% endif %}
{% endfor %}
- {% for style in styles %}
+ {% for type, style in styles %}
<link rel="stylesheet" href="{{ basePath }}/{{ style }}">
{% endfor %}
{% endblock %}
diff --git a/theme/templates/website/page.html b/theme/templates/website/page.html
index 37fc9dd..7f424e1 100644
--- a/theme/templates/website/page.html
+++ b/theme/templates/website/page.html
@@ -70,7 +70,7 @@ require(["gitbook"], function(gitbook) {
<link rel="stylesheet" href="{{ staticBase }}/plugins/{{ resource.path }}">
{% endif %}
{% endfor %}
- {% for style in styles %}
+ {% for type, style in styles %}
<link rel="stylesheet" href="{{ basePath }}/{{ style }}">
{% endfor %}
{% endblock %}