summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-21 11:28:55 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-21 11:28:55 +0100
commitca1313e891f7cfbdffaf6a47bb75a8bc1d77c1a4 (patch)
treec121c0ead1b515145e5e563ce1c48ff293b59a6f
parent8df18746face0bf43d18540d3de5ac0cdd795549 (diff)
downloadgitbook-ca1313e891f7cfbdffaf6a47bb75a8bc1d77c1a4.zip
gitbook-ca1313e891f7cfbdffaf6a47bb75a8bc1d77c1a4.tar.gz
gitbook-ca1313e891f7cfbdffaf6a47bb75a8bc1d77c1a4.tar.bz2
Extend configuration with infos from readme
-rw-r--r--lib/book.js8
-rw-r--r--test/page.js8
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/book.js b/lib/book.js
index cbb85c0..c81d255 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -196,9 +196,13 @@ Book.prototype.parse = function() {
// Parse the readme
.then(that.readme.load)
.then(function() {
- if (that.readme.exists()) return;
+ if (!that.readme.exists()) {
+ throw new error.FileNotFoundError({ filename: 'README' });
+ }
- throw new error.FileNotFoundError({ filename: 'README' });
+ // Default configuration to infos extracted from readme
+ if (!that.config.get('title')) that.config.set('title', that.readme.title);
+ if (!that.config.get('description')) that.config.set('description', that.readme.description);
})
// Parse the summary
diff --git a/test/page.js b/test/page.js
index 9afec1c..8eb2096 100644
--- a/test/page.js
+++ b/test/page.js
@@ -6,6 +6,7 @@ describe('Page', function() {
before(function() {
return mock.setupDefaultBook({
+ 'README.md': ' # Hello World\n\nThis is a description',
'heading.md': '# Hello\n\n## World',
'links.md': '[link](hello.md) [link 2](variables/page/next.md) [readme](README.md)',
@@ -31,6 +32,7 @@ describe('Page', function() {
'variables/page/next.md': '{{ page.next.title }} {{ page.next.path }}',
'variables/page/dir/ltr.md': 'This is english: {{ page.dir }}',
'variables/page/dir/rtl.md': 'بسيطة {{ page.dir }}',
+ 'variables/book/title.md': '{{ book.title}}',
'GLOSSARY.md': '# Glossary\n\n\n## abracadabra\n\nthis is the description'
}, [
@@ -315,6 +317,12 @@ describe('Page', function() {
.should.be.fulfilledWith('<p>Test Variables variables/page/title.md</p>\n');
});
+ it('should set book.title', function() {
+ var page = book.addPage('variables/book/title.md');
+ return page.toHTML(output)
+ .should.be.fulfilledWith('<p>Hello World</p>\n');
+ });
+
describe('page.dir', function() {
it('should detect ltr', function() {
var page = book.addPage('variables/page/dir/ltr.md');