Skip to content

Commit 65b6674

Browse files
committed
fix line breaks in actions
1 parent 9906ca2 commit 65b6674

File tree

8 files changed

+84
-31
lines changed

8 files changed

+84
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Command line interface for [CodeRoad](http://coderoad.github.io).
3131
```
3232
"name": "coderoad-$my-tutorial-name$",
3333
"main": "coderoad.json",
34-
"keywords": ["coderoad"],
34+
"keywords": ["coderoad", "tutorial"],
3535
"coderoad": {
3636
"testDir": "test",
3737
"testSuffix": ".spec.js"

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var tutorials_1 = require('./src/tutorials/tutorials');
1010
var publish_1 = require('./src/publish/publish');
1111
var docs_1 = require('./src/docs/docs');
1212
program
13-
.version('0.3.7')
13+
.version('0.3.8')
1414
.usage('[options] <keywords>')
1515
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1616
.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.7",
3+
"version": "0.3.8",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

src/build/parser/actions.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ function trimCommandValue(text) {
1010
return command.action + '(\'' + command.value + '\')';
1111
}
1212
exports.trimCommandValue = trimCommandValue;
13-
function getContentInBrackets(text) {
14-
if (text.charAt(0) === '(' && text.charAt(text.length - 1) === ')') {
15-
return text.slice(1, text.length - 1);
16-
}
17-
return '';
18-
}
1913
function addToTasks(result, line, index) {
2014
var match = Match.isAction(line);
2115
var action = match.action;
2216
var task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
23-
var trimmedAction = getContentInBrackets(match.content);
17+
var trimmedAction = line.slice(action.length + 2, line.length - 1);
2418
var actionValue = cleanup_1.trimQuotes(trimmedAction);
25-
3;
2619
var isActionArray = Match.isArray(cleanup_1.trimQuotes(actionValue));
2720
switch (action) {
2821
case 'test':

src/build/parser/brackets.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"use strict";
2+
exports.Brackets = {
3+
trim: function (text) {
4+
text = text.trim();
5+
var firstBracket = text.charAt(0).match(/["']/);
6+
if (firstBracket && !!text.charAt(text.length - 1).match(firstBracket[0])) {
7+
text = text.substring(1, text.length - 1);
8+
}
9+
return text;
10+
},
11+
addBreak: function (char, index) {
12+
switch (char) {
13+
case '(':
14+
this.round += 1;
15+
break;
16+
case ')':
17+
this.round -= 1;
18+
break;
19+
case '[':
20+
this.square += 1;
21+
break;
22+
case ']':
23+
this.square -= 1;
24+
break;
25+
case '{':
26+
this.curly += 1;
27+
break;
28+
case '}':
29+
this.curly -= 1;
30+
break;
31+
default:
32+
break;
33+
}
34+
if (char === ',' &&
35+
this.round === 0 && this.square === 0 && this.curly === 0) {
36+
this.params.push(this.trim(this.current));
37+
this.current = '';
38+
}
39+
else {
40+
this.current += char;
41+
}
42+
},
43+
getParams: function (text) {
44+
this.reset();
45+
for (var i = 0; i < text.length; i++) {
46+
this.addBreak(text[i], i);
47+
}
48+
return this.params.concat(this.trim(this.current));
49+
},
50+
reset: function () {
51+
this.round = 0;
52+
this.square = 0;
53+
this.curly = 0;
54+
this.current = '';
55+
this.params = [];
56+
}
57+
};

src/build/parser/cleanup.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ function trimLineBreaks(text) {
66
return text;
77
}
88
exports.trimLineBreaks = trimLineBreaks;
9+
var quotes = ['\'', '"', '`'];
910
function trimQuotes(text) {
1011
if (!!text.match(/^\s/)) {
1112
return trimQuotes(text.slice(1));
1213
}
13-
else if (!!text.match(/\s$/)) {
14-
return trimQuotes(text.slice(0, -1));
14+
else if (!!text.match(/\s$/m)) {
15+
return trimQuotes(text.slice(0, text.length - 1));
1516
}
16-
else if (!!text.match(/^`{3}.+`{3}$/)) {
17-
return trimQuotes(text.slice(3, -3));
17+
else if (!!text.match(/^`{3}.+`{3}$/m)) {
18+
return trimQuotes(text.slice(3, text.length - 3));
1819
}
19-
else if (!!text.match(/^['"`].+['"`]$/)) {
20-
return trimQuotes(text.slice(1, -1));
20+
else if (quotes.indexOf(text.charAt(0)) > -1 && quotes.indexOf(text.charAt(text.length - 1)) > -1) {
21+
return trimQuotes(text.slice(1, text.length - 1));
2122
}
2223
else {
2324
return text;

src/build/parser/match.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ exports.isArray = function (line) {
3636
return isMatch ? isMatch[0] : false;
3737
};
3838
exports.isAction = function (line) {
39-
var match = line.match(/^@(action|test|hint)(.+)$/);
39+
var match = line.match(/^@(action|test|hint)/);
4040
return !!match ? {
4141
action: match[1],
4242
content: match[2]

src/build/parser/task.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function task(result, lines, index) {
1515
description: cleanup_1.trimLeadingSpaces(Match.task(lines[0]))
1616
});
1717
index.task += 1;
18-
var inCodeBlock = false;
18+
var inExpCodeBlock = false;
1919
var currentAction = null;
2020
var bracketCount = 0;
2121
var i = 0;
@@ -27,23 +27,25 @@ function task(result, lines, index) {
2727
lines = import_1.loadImport(lines, importFile);
2828
}
2929
else {
30-
var finishedAction = (bracketTracker(line) + bracketCount) === 0;
31-
if (!!currentAction && !finishedAction) {
32-
currentAction += line;
33-
bracketCount += bracketTracker(line);
34-
}
35-
else if (!!currentAction) {
36-
currentAction += line;
37-
result = actions_1.addToTasks(result, currentAction, index);
38-
currentAction = null;
39-
bracketCount = 0;
30+
if (!!currentAction) {
31+
var finishedAction = (bracketTracker(line) + bracketCount) === 0;
32+
if (!finishedAction) {
33+
currentAction += line + '\n';
34+
bracketCount += bracketTracker(line);
35+
}
36+
else {
37+
currentAction += line;
38+
result = actions_1.addToTasks(result, currentAction, index);
39+
currentAction = null;
40+
bracketCount = 0;
41+
}
4042
}
4143
else {
4244
var isAction = Match.isAction(line);
4345
if (!isAction && !!Match.codeBlock(line)) {
44-
inCodeBlock = !inCodeBlock;
46+
inExpCodeBlock = !inExpCodeBlock;
4547
}
46-
if (!inCodeBlock) {
48+
if (!inExpCodeBlock) {
4749
if (!!isAction) {
4850
currentAction = line;
4951
bracketCount = bracketTracker(line);

0 commit comments

Comments
 (0)