Skip to content

Commit dfd4876

Browse files
committed
Adapt new page.parse api for tests
1 parent 195374e commit dfd4876

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

lib/generate/json/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ Generator.prototype.convertFile = function(content, input) {
2929
dir: path.dirname(input) || '/'
3030
});
3131
})
32-
.then(function(sections) {
33-
json.sections = sections;
32+
.then(function(parsed) {
33+
json.lexed = parsed.lexed;
34+
json.sections = parsed.sections;
3435
})
3536
.then(function() {
3637
return fs.writeFile(

lib/generate/site/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Generator.prototype.prepareFile = function(content, _input) {
120120
.then(function() {
121121
// Lex, parse includes and get
122122
// Get HTML generated sections
123-
return parse.page(page, {
123+
return parse.page(page.content, {
124124
// Local files path
125125
dir: path.dirname(_input) || '/',
126126

@@ -134,8 +134,9 @@ Generator.prototype.prepareFile = function(content, _input) {
134134
], path.join, fs.readFileSync)
135135
});
136136
})
137-
.then(function(sections) {
138-
page.sections = sections;
137+
.then(function(parsed) {
138+
page.lexed = parsed.lexed;
139+
page.sections = parsed.sections;
139140

140141
// Use plugin hook
141142
return _callHook("page");

lib/parse/page.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ function quizQuestion(node) {
4747
}
4848
}
4949

50-
function parsePage(page, options) {
50+
function parsePage(src, options) {
5151
options = options || {};
5252

5353
// Lex if not already lexed
54-
page.lexed = (_.isArray(page.content) ? page.content : lex(include(page.content, options.includer || function() { return undefined; })))
55-
return page.lexed
56-
.map(function(section) {
54+
var parsed = {
55+
lexed: (_.isArray(src) ? page.content : lex(include(src, options.includer || function() { return undefined; })))
56+
};
57+
parsed.sections = parsed.lexed.map(function(section) {
5758
// Transform given type
5859
if(section.type === 'exercise') {
5960
var nonCodeNodes = _.reject(section, {
@@ -151,6 +152,8 @@ function parsePage(page, options) {
151152
content: render(section, options)
152153
};
153154
});
155+
156+
return parsed;
154157
}
155158

156159
// Exports

test/includes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var FIXTURES_DIR = path.join(__dirname, './fixtures/');
99

1010
function loadPage (name, options) {
1111
var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
12-
return page(CONTENT, options);
12+
return page(CONTENT, options).sections;
1313
}
1414

1515

test/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var page = require('../').parse.page;
66

77
function loadPage (name, options) {
88
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8');
9-
return page(CONTENT, options);
9+
return page(CONTENT, options).sections;
1010
}
1111

1212
var LEXED = loadPage('PAGE', {

0 commit comments

Comments
 (0)