summaryrefslogtreecommitdiffstats
path: root/lib/backbone
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-11 21:44:38 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-11 21:44:38 +0100
commit669f3b39849890c48171d807225cd6eaa3c9086b (patch)
treebc07fefc4e13ac8f737174166ac1d19512379298 /lib/backbone
parente7eed2abbe91fa44bd071819123bd9ea04d1702a (diff)
downloadgitbook-669f3b39849890c48171d807225cd6eaa3c9086b.zip
gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.gz
gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.bz2
Add base for normalizing html
Diffstat (limited to 'lib/backbone')
-rw-r--r--lib/backbone/page.js100
1 files changed, 0 insertions, 100 deletions
diff --git a/lib/backbone/page.js b/lib/backbone/page.js
deleted file mode 100644
index 94812d9..0000000
--- a/lib/backbone/page.js
+++ /dev/null
@@ -1,100 +0,0 @@
-var _ = require('lodash');
-var path = require('path');
-var parsers = require('gitbook-parsers');
-
-var error = require('../utils/error');
-
-/*
-A page represent a parsable file in the book (Markdown, Asciidoc, etc)
-*/
-
-function Page(book, filename) {
- if (!(this instanceof Page)) return new Page(book, filename);
- var extension;
- _.bindAll(this);
-
- this.book = book;
- this.log = this.book.log;
-
- // Current content
- this.content = '';
-
- // Relative path to the page
- this.path = filename;
-
- // Absolute path to the page
- this.rawPath = this.book.resolve(filename);
-
- // Last modification date
- this.mtime = 0;
-
- // Can we parse it?
- extension = path.extname(this.path);
- this.parser = parsers.get(extension);
- if (!this.parser) throw error.ParsingError(new Error('Can\'t parse file "'+this.path+'"'));
-
- this.type = this.parser.name;
-}
-
-// Return the filename of the page with another extension
-// "README.md" -> "README.html"
-Page.prototype.withExtension = function(ext) {
- return path.join(
- path.dirname(this.path),
- path.basename(this.path, path.extname(this.path)) + ext
- );
-};
-
-// Update content of the page
-Page.prototype.update = function(content) {
- this.content = content;
-};
-
-// Read the page as a string
-Page.prototype.read = function() {
- var that = this;
-
- return this.book.statFile(this.path)
- .then(function(stat) {
- that.mtime = stat.mtime;
- return that.book.readFile(that.path);
- })
- .then(this.update);
-};
-
-// Parse the page and return its content
-Page.prototype.parse = function() {
- var that = this;
-
- this.log.debug.ln('start parsing file', this.path);
-
- return this.read()
-
- // Pre-process page with parser
- .then(function() {
- return that.parser.page.prepare(that.content)
- .then(that.update);
- })
-
- // Render template
- .then(function() {
- return that.book.template.renderString(that.content, {
- file: {
- path: that.path,
- mtime: that.mtime
- }
- }, {
- file: that.path
- })
- .then(that.update);
- })
-
- // Render markup using the parser
- .then(function() {
- return that.parser.page(that.content)
- .then(that.update);
- });
-};
-
-
-module.exports = Page;