summaryrefslogtreecommitdiffstats
path: root/lib/backbone/file.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backbone/file.js')
-rw-r--r--lib/backbone/file.js61
1 files changed, 61 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;