Skip to content

Commit b5e9474

Browse files
committed
feat(gen): Added navbar to starting template
Should make it easier to start building a multi-page app required for #36
1 parent 087ede5 commit b5e9474

File tree

9 files changed

+111
-18
lines changed

9 files changed

+111
-18
lines changed

Diff for: app/index.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,29 @@ function appendFilesToJade(jadeOrOptions, fileType, optimizedPath, sourceFileLis
384384
return updatedContent;
385385
}
386386

387+
Generator.prototype.navBarScript = function navBarScript() {
388+
var ext = 'js';
389+
var folder = 'javascript';
390+
var minsafe = '';
391+
392+
if(this.env.options.coffee) {
393+
ext = 'coffee';
394+
folder = 'coffeescript';
395+
}
396+
397+
if(this.env.options.minsafe) {
398+
minsafe = '-min';
399+
}
400+
401+
this.copy('../../templates/' + folder + minsafe + '/navbar.' + ext, 'app/scripts/controllers/navbar.' + ext);
402+
};
403+
387404
Generator.prototype.appJs = function appJs() {
388405
var appendOptions = {
389406
html: this.indexFile,
390407
fileType: 'js',
391408
optimizedPath: 'scripts/scripts.js',
392-
sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js'],
409+
sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js', 'scripts/controllers/navbar.js'],
393410
searchPath: ['.tmp', 'app']
394411
};
395412
if (this.jade) {
@@ -410,13 +427,15 @@ Generator.prototype.createIndex = function createIndex() {
410427
Generator.prototype.addJadeViews = function addHtmlJade() {
411428
if(this.jade) {
412429
this.copy('../../templates/views/jade/partials/main.jade', 'app/views/partials/main.jade');
430+
this.copy('../../templates/views/jade/partials/navbar.jade', 'app/views/partials/navbar.jade');
413431
this.copy('../../templates/views/jade/404.jade', 'app/views/404.jade');
414432
}
415433
};
416434

417435
Generator.prototype.addHtmlViews = function addHtmlViews() {
418436
if(!this.jade) {
419437
this.copy('../../templates/views/html/partials/main.html', 'app/views/partials/main.html');
438+
this.copy('../../templates/views/html/partials/navbar.html', 'app/views/partials/navbar.html');
420439
this.copy('../../templates/views/html/404.html', 'app/views/404.html');
421440
}
422441
};

Diff for: templates/coffeescript-min/navbar.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
angular.module('<%= scriptAppName %>')
4+
.controller 'NavbarCtrl', ['$scope', '$location', ($scope, $location) ->
5+
$scope.menu = [
6+
title: 'Home'
7+
link: '/'
8+
,
9+
title: 'About'
10+
link: '#'
11+
,
12+
title: 'Contact'
13+
link: '#'
14+
]
15+
$scope.isActive = (route) ->
16+
route is $location.path()
17+
]

Diff for: templates/coffeescript/navbar.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
angular.module('<%= scriptAppName %>')
4+
.controller 'NavbarCtrl', ($scope, $location) ->
5+
$scope.menu = [
6+
title: 'Home'
7+
link: '/'
8+
,
9+
title: 'About'
10+
link: '#'
11+
,
12+
title: 'Contact'
13+
link: '#'
14+
]
15+
$scope.isActive = (route) ->
16+
route is $location.path()

Diff for: templates/javascript-min/navbar.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
angular.module('<%= scriptAppName %>')
4+
.controller('NavbarCtrl', ['$scope', '$location', function ($scope, $location) {
5+
$scope.menu = [{
6+
'title': 'Home',
7+
'link': '/'
8+
},
9+
{
10+
'title': 'About',
11+
'link': '#'
12+
},
13+
{
14+
'title': 'Contact',
15+
'link': '#'
16+
}];
17+
18+
$scope.isActive = function(route) {
19+
return route === $location.path();
20+
};
21+
}]);

Diff for: templates/javascript/navbar.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
angular.module('<%= scriptAppName %>')
4+
.controller('NavbarCtrl', function ($scope, $location) {
5+
$scope.menu = [{
6+
'title': 'Home',
7+
'link': '/'
8+
},
9+
{
10+
'title': 'About',
11+
'link': '#'
12+
},
13+
{
14+
'title': 'Contact',
15+
'link': '#'
16+
}];
17+
18+
$scope.isActive = function(route) {
19+
return route === $location.path();
20+
};
21+
});

Diff for: templates/views/html/partials/main.html

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
<div class="header">
2-
<ul class="nav nav-pills pull-right">
3-
<li class="active"><a ng-href="#">Home</a></li>
4-
<li><a ng-href="#">About</a></li>
5-
<li><a ng-href="#">Contact</a></li>
6-
</ul>
7-
<h3 class="text-muted"><%= appname %></h3>
8-
</div>
1+
<div ng-include="'partials/navbar.html'"></div>
92

103
<div class="jumbotron">
114
<h1>'Allo, 'Allo!</h1>

Diff for: templates/views/html/partials/navbar.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="header" ng-controller="NavbarCtrl">
2+
<ul class="nav nav-pills pull-right">
3+
<li ng-repeat="item in menu" ng-class="{active: isActive(item.link)}">
4+
<a ng-href="{{item.link}}">{{item.title}}</a>
5+
</li>
6+
</ul>
7+
<h3 class="text-muted"><%= appname %></h3>
8+
</div>

Diff for: templates/views/jade/partials/main.jade

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
.header
2-
ul.nav.nav-pills.pull-right
3-
li.active
4-
a(ng-href='#') Home
5-
li
6-
a(ng-href='#') About
7-
li
8-
a(ng-href='#') Contact
9-
h3.text-muted <%= scriptAppName %>
1+
div(ng-include='\'partials/navbar.html\'')
2+
103
.jumbotron
114
h1 'Allo, 'Allo!
125
p.lead

Diff for: templates/views/jade/partials/navbar.jade

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.header(ng-controller='NavbarCtrl')
2+
ul.nav.nav-pills.pull-right
3+
li(ng-repeat='item in menu', ng-class='{active: isActive(item.link)}')
4+
a(ng-href='{{item.link}}') {{item.title}}
5+
h3.text-muted <%= scriptAppName %>

0 commit comments

Comments
 (0)