Skip to content

Commit 7737fb4

Browse files
committed
@onPageComplete added
1 parent 5d58fae commit 7737fb4

File tree

11 files changed

+52
-31
lines changed

11 files changed

+52
-31
lines changed

lib/build/parser/match.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ var regex = {
99
'###': match('#', 3),
1010
'+': match('\\+', 1),
1111
'```': match('`', 3),
12-
'action': /^@(action|test|hint|continue)/,
12+
'action': /^@(action|test|hint)/,
1313
'import': /^@import\((.+)\)$/,
14-
'onComplete': /^(@onComplete.+)/
14+
'onPageComplete': /^(@onPageComplete.+)/
1515
};
1616
function parseWithCode(code) {
1717
return function (line) {
@@ -33,7 +33,7 @@ exports.task = parseWithCode('+');
3333
exports.codeBlock = parseWithCode('```');
3434
exports.isAction = parseWithCode('action');
3535
exports.isImport = parseWithCode('import');
36-
exports.isComplete = parseWithCode('onComplete');
36+
exports.isPageComplete = parseWithCode('onPageComplete');
3737
exports.isArray = function (line) {
3838
var isMatch = line.match(/^\[.+\]$/);
3939
return isMatch ? isMatch[0] : null;

lib/build/parser/page.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function page(result, lines, index) {
1212
description: ''
1313
});
1414
var inCodeBlock = false;
15-
var currentComplete = null;
15+
var currentPageComplete = null;
1616
var bracketCount = 0;
1717
var i = 0;
1818
while (i < lines.length - 1) {
@@ -22,12 +22,12 @@ function page(result, lines, index) {
2222
case !!Match.isImport(line):
2323
lines = import_1.loadImport(lines, Match.isImport(line));
2424
continue;
25-
case (!!Match.isComplete(line) || !!currentComplete):
26-
currentComplete = !!currentComplete ? currentComplete += '\n' + line : Match.isComplete(line);
27-
bracketCount = cleanup_1.bracketTracker(currentComplete);
25+
case (!!Match.isPageComplete(line) || !!currentPageComplete):
26+
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
27+
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
2828
if (bracketCount === 0) {
29-
result.chapters[index.chapter].pages[index.page].onComplete = cleanup_1.trimValue(currentComplete);
30-
currentComplete = null;
29+
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
30+
currentPageComplete = null;
3131
}
3232
continue;
3333
case !!Match.codeBlock(line):

lib/build/parser/task.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function task(result, lines, index) {
1111
});
1212
index.task += 1;
1313
var inCodeBlock = false;
14+
var currentPageComplete = null;
1415
var currentAction = null;
1516
var bracketCount = 0;
1617
var i = 0;
@@ -21,6 +22,14 @@ function task(result, lines, index) {
2122
case !!Match.isImport(line):
2223
lines = import_1.loadImport(lines, Match.isImport(line));
2324
continue;
25+
case (!!Match.isPageComplete(line) || !!currentPageComplete):
26+
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
27+
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
28+
if (bracketCount === 0) {
29+
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
30+
currentPageComplete = null;
31+
}
32+
continue;
2433
case !!currentAction:
2534
if (line.length === 0) {
2635
currentAction += '\n';

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var search_1 = require('./search/search');
99
var tutorials_1 = require('./tutorials/tutorials');
1010
var publish_1 = require('./publish/publish');
1111
program
12-
.version('0.3.23')
12+
.version('0.3.24')
1313
.usage('[options] <keywords>')
1414
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1515
.option('-c, --create [name]', 'tutorial name')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-cli",
3-
"version": "0.3.23",
3+
"version": "0.3.24",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

src/build/parser/match.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ var regex = {
1010
'###': match('#', 3),
1111
'+': match('\\+', 1),
1212
'```': match('`', 3),
13-
'action': /^@(action|test|hint|continue)/,
13+
'action': /^@(action|test|hint)/,
1414
'import': /^@import\((.+)\)$/,
15-
'onComplete': /^(@onComplete.+)/
15+
'onPageComplete': /^(@onPageComplete.+)/
1616
};
1717

1818
function parseWithCode(code: string) {
@@ -35,7 +35,7 @@ export const task = parseWithCode('+');
3535
export const codeBlock = parseWithCode('```');
3636
export const isAction = parseWithCode('action');
3737
export const isImport = parseWithCode('import');
38-
export const isComplete = parseWithCode('onComplete');
38+
export const isPageComplete = parseWithCode('onPageComplete');
3939

4040
export const isArray = function(line: string): string {
4141
let isMatch = line.match(/^\[.+\]$/);

src/build/parser/page.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function page(result: CR.Output, lines: string[], index: CR.Index): CR.Ou
1212
description: ''
1313
});
1414
let inCodeBlock = false;
15-
let currentComplete = null;
15+
let currentPageComplete = null;
1616
let bracketCount = 0;
1717

1818
let i = 0;
@@ -28,13 +28,13 @@ export function page(result: CR.Output, lines: string[], index: CR.Index): CR.Ou
2828
continue;
2929

3030
// @onComplete
31-
case (!!Match.isComplete(line) || !!currentComplete):
32-
currentComplete = !!currentComplete ? currentComplete += '\n' + line : Match.isComplete(line);
33-
bracketCount = bracketTracker(currentComplete);
31+
case (!!Match.isPageComplete(line) || !!currentPageComplete):
32+
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
33+
bracketCount = bracketTracker(currentPageComplete);
3434
// complete
3535
if (bracketCount === 0) {
36-
result.chapters[index.chapter].pages[index.page].onComplete = trimValue(currentComplete);
37-
currentComplete = null;
36+
result.chapters[index.chapter].pages[index.page].onPageComplete = trimValue(currentPageComplete);
37+
currentPageComplete = null;
3838
}
3939
continue;
4040

src/build/parser/task.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Match from './match';
22
import {chapter} from './chapter';
33
import {page} from './page';
44
import {addToTasks} from './actions';
5-
import {trimLeadingSpaces, bracketTracker} from './cleanup';
5+
import {trimLeadingSpaces, bracketTracker, trimValue} from './cleanup';
66
import {loadImport} from './import';
77

88

@@ -13,6 +13,7 @@ export function task(result: CR.Output, lines: string[], index: CR.Index): CR.Ou
1313
});
1414
index.task += 1;
1515
let inCodeBlock = false;
16+
let currentPageComplete = null;
1617
let currentAction = null;
1718
let bracketCount = 0;
1819

@@ -28,6 +29,17 @@ export function task(result: CR.Output, lines: string[], index: CR.Index): CR.Ou
2829
lines = loadImport(lines, Match.isImport(line));
2930
continue;
3031

32+
// @onComplete
33+
case (!!Match.isPageComplete(line) || !!currentPageComplete):
34+
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
35+
bracketCount = bracketTracker(currentPageComplete);
36+
// complete
37+
if (bracketCount === 0) {
38+
result.chapters[index.chapter].pages[index.page].onPageComplete = trimValue(currentPageComplete);
39+
currentPageComplete = null;
40+
}
41+
continue;
42+
3143
// @action multiline
3244
case !!currentAction:
3345
if (line.length === 0) {

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import tutorials from './tutorials/tutorials';
99
import publish from './publish/publish';
1010

1111
program
12-
.version('0.3.23')
12+
.version('0.3.24')
1313
.usage('[options] <keywords>')
1414
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1515
.option('-c, --create [name]', 'tutorial name')

src/typings/cr.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare namespace CR {
1515
title: string;
1616
description: string;
1717
tasks?: Task[];
18-
onComplete?: string;
18+
onPageComplete?: string;
1919
}
2020
interface Task {
2121
description: string;

test/build-onComplete.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var expect = require('chai').expect;
22
var page = require('../lib/build/parser/page').page;
33
var task = require('../lib/build/parser/task').task;
44

5-
describe('@onComplete', function() {
5+
describe('@onPageComplete', function() {
66

77
var result = function() {
88
return {
@@ -39,40 +39,40 @@ describe('@onComplete', function() {
3939
};
4040
};
4141

42-
it('should add @onComplete string to the page', function() {
43-
var lines = ['### Page One', 'page description', 'more page description', '@onComplete("next page")'];
42+
it('should add @onPageComplete string to the page', function() {
43+
var lines = ['### Page One', 'page description', 'more page description', '@onPageComplete("next page")'];
4444
var next = page(result(), lines, index());
4545
var nextPage = next.chapters[0].pages[0];
4646
expect(nextPage).to.deep.equal({
4747
title: 'Page One',
4848
description: 'page description\nmore page description',
49-
onComplete: 'next page'
49+
onPageComplete: 'next page'
5050
});
5151
});
5252

5353
it('should handle multi-line codeblocks', function() {
5454
var lines = ['### Page One', 'page description', 'more page description',
55-
'@onComplete("next page', '```', 'var a = 42;', '```', '")'
55+
'@onPageComplete("next page', '```', 'var a = 42;', '```', '")'
5656
];
5757
var next = page(result(), lines, index());
5858
var nextPage = next.chapters[0].pages[0];
5959
expect(nextPage).to.deep.equal({
6060
title: 'Page One',
6161
description: 'page description\nmore page description',
62-
onComplete: 'next page\n```\nvar a = 42;\n```'
62+
onPageComplete: 'next page\n```\nvar a = 42;\n```'
6363
});
6464
});
6565

6666
it('should handle string literals', function() {
6767
var lines = ['### Page One', 'page description', 'more page description',
68-
'@onComplete("next page', '`var a = 42;`', '")'
68+
'@onPageComplete("next page', '`var a = 42;`', '")'
6969
];
7070
var next = page(result(), lines, index());
7171
var nextPage = next.chapters[0].pages[0];
7272
expect(nextPage).to.deep.equal({
7373
title: 'Page One',
7474
description: 'page description\nmore page description',
75-
onComplete: 'next page\n`var a = 42;`'
75+
onPageComplete: 'next page\n`var a = 42;`'
7676
});
7777
});
7878

0 commit comments

Comments
 (0)