Add base test for extending code highlighting

This commit is contained in:
Samy Pesse
2015-09-14 11:28:14 +02:00
parent 35c4179ca1
commit fa4e234bab
8 changed files with 51 additions and 41 deletions
-2
View File
@@ -339,7 +339,6 @@ TemplateEngine.prototype.addBlock = function(name, block) {
// Add multiple blocks
TemplateEngine.prototype.addBlocks = function(blocks) {
console.log('add blocks', blocks);
_.each(blocks, function(block, name) {
this.addBlock(name, block);
}, this);
@@ -351,7 +350,6 @@ TemplateEngine.prototype.applyBlock = function(name, blk) {
var func, block, func, r;
block = this.blocks[name];
console.log('applyBlock', name, block);
if (!block) throw new Error('Block not found "'+name+'"');
if (_.isString(blk)) {
blk = {
+1 -1
View File
@@ -13,7 +13,7 @@
"fs-extra": "0.16.5",
"fstream-ignore": "1.0.2",
"gitbook-parsers": "0.8.2",
"nunjucks": "mozilla/nunjucks#146a63571f1910d57cc391dfe64f3789ba1f1fd1",
"nunjucks": "mozilla/nunjucks#dc89bf91611a2101731c2c06afcf5c32160b4dc9",
"nunjucks-autoescape": "1.0.0",
"nunjucks-filter": "1.0.0",
"i18n": "0.5.0",
-4
View File
@@ -1,7 +1,3 @@
# Readme
Default description for the book.
```
test
```
+7
View File
@@ -0,0 +1,7 @@
# Readme
Default description for the book.
```
test
```
+1
View File
@@ -0,0 +1 @@
# Summary
+34
View File
@@ -0,0 +1,34 @@
var _ = require('lodash');
var should = require('should');
var path = require('path');
var fs = require('fs');
var Plugin = require('../lib/plugin');
var PLUGINS_ROOT = path.resolve(__dirname, 'plugins');
describe('Code Highlighting', function () {
it('should correctly replace highlighting', function() {
return books.generate('highlight', 'website', {
prepare: function(book) {
var plugin = new Plugin(book, "highlight");
plugin.load("./highlight", PLUGINS_ROOT);
book.plugins.load(plugin);
}
})
.then(function(book) {
var PAGE = fs.readFileSync(
path.join(book.options.output, "index.html"),
{ encoding: "utf-8" }
);
PAGE.should.be.html({
"code": {
count: 1,
text: 'code_test\n_code'
}
});
});
});
});
+8 -8
View File
@@ -17,18 +17,18 @@ var TMPDIR = os.tmpdir();
// Generate and return a book
function generateBook(bookId, test, options) {
options = _.defaults(options || {}, {
before: function() {}
function generateBook(bookId, test, opts) {
opts = _.defaults(opts || {}, {
prepare: function() {}
});
return parseBook(bookId, test)
.then(function(book) {
return Q(options.before(book))
.thenResolve(book);
})
.then(function(book) {
return book.generate(test)
return Q(opts.prepare(book))
.then(function() {
return book.generate(test);
})
.thenResolve(book);
});
}
-26
View File
@@ -235,31 +235,5 @@ describe('Plugins', function () {
});
});
});
describe('Replace code highlighting', function() {
it('should correctly replace highlighting', function() {
return books.generate('basic', 'website', {
before: function(book) {
var plugin = new Plugin(book, "blocks");
plugin.load("./highlight", PLUGINS_ROOT);
return book.plugins.load(plugin);
}
})
.then(function() {
var PAGE = fs.readFileSync(
path.join(book.options.output, "index.html"),
{ encoding: "utf-8" }
);
PAGE.should.be.html({
"code": {
count: 1,
text: 'code__test\n__code'
}
});
});
})
});
});