summaryrefslogtreecommitdiffstats
path: root/lib/backbone
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-01-22 21:04:36 +0100
committerSamy Pessé <samypesse@gmail.com>2016-01-22 21:04:36 +0100
commit877f2e477b010f9f37a9044606f110a90f077680 (patch)
tree5cd61cf3b00ba10dc6110535ed9fdf67d8baba72 /lib/backbone
parentc8e2fc0e57d223c01a51d6ee186fc1662cd74d13 (diff)
downloadgitbook-877f2e477b010f9f37a9044606f110a90f077680.zip
gitbook-877f2e477b010f9f37a9044606f110a90f077680.tar.gz
gitbook-877f2e477b010f9f37a9044606f110a90f077680.tar.bz2
Start rewrite
Diffstat (limited to 'lib/backbone')
-rw-r--r--lib/backbone/file.js61
-rw-r--r--lib/backbone/glossary.js8
-rw-r--r--lib/backbone/index.js8
-rw-r--r--lib/backbone/langs.js15
-rw-r--r--lib/backbone/readme.js26
-rw-r--r--lib/backbone/summary.js9
6 files changed, 127 insertions, 0 deletions
diff --git a/lib/backbone/file.js b/lib/backbone/file.js
new file mode 100644
index 0000000..71fc78c
--- /dev/null
+++ b/lib/backbone/file.js
@@ -0,0 +1,61 @@
+
+function BackboneFile(book) {
+ if (!(this instanceof BackboneFile)) return new BackboneFile(book);
+
+ this.book = book;
+ this.log = this.book.log;
+
+ // Filename in the book
+ this.filename = '';
+ this.parser;
+}
+
+// Type of the backbone file
+BackboneFile.prototype.type = '';
+
+// Parse a backbone file
+BackboneFile.prototype.parse = function() {
+
+};
+
+// Return true if backbone file exists
+BackboneFile.prototype.exists = function() {
+ return Boolean(this.filename);
+};
+
+// Locate a backbone file, could be .md, .asciidoc, etc
+BackboneFile.prototype.locate = function() {
+ var that = this;
+ var filename = this.book.config.getStructure(this.type, true);
+ this.log.debug.ln('locating', this.type, ':', filename);
+
+ return this.book.findParsableFile(filename)
+ .then(function(result) {
+ if (!result) return;
+
+ that.filename = result.path;
+ that.parser = result.parser;
+ });
+};
+
+// Read and parse the file
+BackboneFile.prototype.load = function() {
+ var that = this;
+ this.log.debug.ln('loading', this.type, ':', that.filename);
+
+ return this.locate()
+ .then(function() {
+ if (!that.filename) return;
+
+ that.log.debug.ln(that.type, 'located at', that.filename);
+
+ return that.book.readFile(that.filename)
+
+ // Parse it
+ .then(function(content) {
+ return that.parse(content);
+ });
+ });
+};
+
+module.exports = BackboneFile;
diff --git a/lib/backbone/glossary.js b/lib/backbone/glossary.js
new file mode 100644
index 0000000..aba83cf
--- /dev/null
+++ b/lib/backbone/glossary.js
@@ -0,0 +1,8 @@
+
+function Glossary() {
+ if (!(this instanceof Glossary)) return new Glossary();
+}
+
+Glossary.prototype.type = 'glossary';
+
+module.exports = Glossary;
diff --git a/lib/backbone/index.js b/lib/backbone/index.js
new file mode 100644
index 0000000..4c3c3f3
--- /dev/null
+++ b/lib/backbone/index.js
@@ -0,0 +1,8 @@
+
+module.exports = {
+ Readme: require('./readme'),
+ Summary: require('./summary'),
+ Glossary: require('./glossary'),
+ Langs: require('./langs')
+};
+
diff --git a/lib/backbone/langs.js b/lib/backbone/langs.js
new file mode 100644
index 0000000..2818519
--- /dev/null
+++ b/lib/backbone/langs.js
@@ -0,0 +1,15 @@
+
+function Langs() {
+ if (!(this instanceof Langs)) return new Langs();
+
+ this.languages = [];
+}
+
+Langs.prototype.type = 'langs';
+
+// Return the count of languages
+Langs.prototype.count = function() {
+ return this.languages.length;
+};
+
+module.exports = Langs;
diff --git a/lib/backbone/readme.js b/lib/backbone/readme.js
new file mode 100644
index 0000000..a4cd9d8
--- /dev/null
+++ b/lib/backbone/readme.js
@@ -0,0 +1,26 @@
+var util = require('util');
+var BackboneFile = require('./file');
+
+function Readme() {
+ BackboneFile.apply(this, arguments);
+
+ this.title;
+ this.description;
+}
+util.inherits(Readme, BackboneFile);
+
+Readme.prototype.type = 'readme';
+
+// Parse the readme content
+Readme.prototype.parse = function(content) {
+ var that = this;
+
+ return this.parser.readme(content)
+ .then(function(out) {
+ that.title = out.title;
+ that.description = out.description;
+ });
+};
+
+
+module.exports = Readme;
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
new file mode 100644
index 0000000..e2cd485
--- /dev/null
+++ b/lib/backbone/summary.js
@@ -0,0 +1,9 @@
+
+function Summary() {
+ if (!(this instanceof Summary)) return new Summary();
+}
+
+Summary.prototype.type = 'summary';
+
+
+module.exports = Summary;