Adapt new page.parse api for tests

This commit is contained in:
Samy Pessé
2014-11-03 17:40:38 +01:00
parent 195374ecee
commit dfd487692a
5 changed files with 16 additions and 11 deletions
+3 -2
View File
@@ -29,8 +29,9 @@ Generator.prototype.convertFile = function(content, input) {
dir: path.dirname(input) || '/'
});
})
.then(function(sections) {
json.sections = sections;
.then(function(parsed) {
json.lexed = parsed.lexed;
json.sections = parsed.sections;
})
.then(function() {
return fs.writeFile(
+4 -3
View File
@@ -120,7 +120,7 @@ Generator.prototype.prepareFile = function(content, _input) {
.then(function() {
// Lex, parse includes and get
// Get HTML generated sections
return parse.page(page, {
return parse.page(page.content, {
// Local files path
dir: path.dirname(_input) || '/',
@@ -134,8 +134,9 @@ Generator.prototype.prepareFile = function(content, _input) {
], path.join, fs.readFileSync)
});
})
.then(function(sections) {
page.sections = sections;
.then(function(parsed) {
page.lexed = parsed.lexed;
page.sections = parsed.sections;
// Use plugin hook
return _callHook("page");
+7 -4
View File
@@ -47,13 +47,14 @@ function quizQuestion(node) {
}
}
function parsePage(page, options) {
function parsePage(src, options) {
options = options || {};
// Lex if not already lexed
page.lexed = (_.isArray(page.content) ? page.content : lex(include(page.content, options.includer || function() { return undefined; })))
return page.lexed
.map(function(section) {
var parsed = {
lexed: (_.isArray(src) ? page.content : lex(include(src, options.includer || function() { return undefined; })))
};
parsed.sections = parsed.lexed.map(function(section) {
// Transform given type
if(section.type === 'exercise') {
var nonCodeNodes = _.reject(section, {
@@ -151,6 +152,8 @@ function parsePage(page, options) {
content: render(section, options)
};
});
return parsed;
}
// Exports
+1 -1
View File
@@ -9,7 +9,7 @@ var FIXTURES_DIR = path.join(__dirname, './fixtures/');
function loadPage (name, options) {
var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
return page(CONTENT, options);
return page(CONTENT, options).sections;
}
+1 -1
View File
@@ -6,7 +6,7 @@ var page = require('../').parse.page;
function loadPage (name, options) {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8');
return page(CONTENT, options);
return page(CONTENT, options).sections;
}
var LEXED = loadPage('PAGE', {