Skip to content

Commit 889befb

Browse files
committed
Merge pull request #408 from eddiemonge/refac
refactor(route): dry up and refactor code
2 parents 94e3eda + 698bfa0 commit 889befb

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

Diff for: route/index.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,26 @@ var Generator = module.exports = function Generator() {
1414
util.inherits(Generator, ScriptBase);
1515

1616
Generator.prototype.rewriteAppJs = function () {
17-
if (this.env.options.coffee) {
18-
angularUtils.rewriteFile({
19-
file: path.join(this.env.options.appPath, 'scripts/app.coffee'),
20-
needle: '.otherwise',
21-
splicable: [
22-
'.when \'/' + this.name + '\',',
23-
' templateUrl: \'views/' + this.name + '.html\',',
24-
' controller: \'' + this._.classify(this.name) + 'Ctrl\''
25-
]
26-
});
17+
var coffee = this.env.options.coffee;
18+
var config = {
19+
file: path.join(
20+
this.env.options.appPath,
21+
'scripts/app.' + (coffee ? 'coffee' : 'js')
22+
),
23+
needle: '.otherwise',
24+
splicable: [
25+
" templateUrl: 'views/" + this.name + ".html'" + (coffee ? "" : "," ),
26+
" controller: '" + this._.classify(this.name) + "Ctrl'"
27+
]
28+
};
29+
30+
if (coffee) {
31+
config.splicable.unshift(".when '/" + this.name + "',");
2732
}
2833
else {
29-
angularUtils.rewriteFile({
30-
file: path.join(this.env.options.appPath, 'scripts/app.js'),
31-
needle: '.otherwise',
32-
splicable: [
33-
'.when(\'/' + this.name + '\', {',
34-
' templateUrl: \'views/' + this.name + '.html\',',
35-
' controller: \'' + this._.classify(this.name) + 'Ctrl\'',
36-
'})'
37-
]
38-
});
34+
config.splicable.unshift(".when('/" + this.name + "', {");
35+
config.splicable.push("})");
3936
}
37+
38+
angularUtils.rewriteFile(config);
4039
};

0 commit comments

Comments
 (0)