Skip to content

Commit b4b940b

Browse files
committed
Improve the regex for matching coffeescript functions
1 parent f4b67c9 commit b4b940b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

blueprints/route/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ function addRouteToRouter(name, options) {
2828
return;
2929
}
3030

31-
// This regex needs some work. I'd like to not need () around my map-func.
32-
var funcRegex = /(map \(->[\s\S]+)\)/;
31+
var funcRegex = /(map\s*->[\s\S]+)(\n^\S+)/m;
3332

3433
switch (type) {
3534
case 'route':
3635
newContent = oldContent.replace(
3736
funcRegex,
38-
"$1 @route '" + name + "'\n)"
37+
"$1 @route '" + name + "'\n$2"
3938
);
4039
break;
4140
case 'resource':
@@ -44,12 +43,12 @@ function addRouteToRouter(name, options) {
4443
if (plural === name) {
4544
newContent = oldContent.replace(
4645
funcRegex,
47-
"$1 @resource '" + name + "'\n)"
46+
"$1 @resource '" + name + "'\n$2"
4847
);
4948
} else {
5049
newContent = oldContent.replace(
5150
funcRegex,
52-
"$1 @resource '" + name + "', path: '" + plural + "/:" + name + "_id'\n)"
51+
"$1 @resource '" + name + "', path: '" + plural + "/:" + name + "_id'\n$2"
5352
);
5453
}
5554
break;

0 commit comments

Comments
 (0)