From b5e94749384ab9a3305991df62d7ed9856bded83 Mon Sep 17 00:00:00 2001 From: Tyler Henkel Date: Mon, 16 Dec 2013 17:04:17 -0500 Subject: [PATCH] feat(gen): Added navbar to starting template Should make it easier to start building a multi-page app required for #36 --- app/index.js | 21 ++++++++++++++++++++- templates/coffeescript-min/navbar.coffee | 17 +++++++++++++++++ templates/coffeescript/navbar.coffee | 16 ++++++++++++++++ templates/javascript-min/navbar.js | 21 +++++++++++++++++++++ templates/javascript/navbar.js | 21 +++++++++++++++++++++ templates/views/html/partials/main.html | 9 +-------- templates/views/html/partials/navbar.html | 8 ++++++++ templates/views/jade/partials/main.jade | 11 ++--------- templates/views/jade/partials/navbar.jade | 5 +++++ 9 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 templates/coffeescript-min/navbar.coffee create mode 100644 templates/coffeescript/navbar.coffee create mode 100644 templates/javascript-min/navbar.js create mode 100644 templates/javascript/navbar.js create mode 100644 templates/views/html/partials/navbar.html create mode 100644 templates/views/jade/partials/navbar.jade diff --git a/app/index.js b/app/index.js index ccc4abec9..0b5a36bbc 100644 --- a/app/index.js +++ b/app/index.js @@ -384,12 +384,29 @@ function appendFilesToJade(jadeOrOptions, fileType, optimizedPath, sourceFileLis return updatedContent; } +Generator.prototype.navBarScript = function navBarScript() { + var ext = 'js'; + var folder = 'javascript'; + var minsafe = ''; + + if(this.env.options.coffee) { + ext = 'coffee'; + folder = 'coffeescript'; + } + + if(this.env.options.minsafe) { + minsafe = '-min'; + } + + this.copy('../../templates/' + folder + minsafe + '/navbar.' + ext, 'app/scripts/controllers/navbar.' + ext); +}; + Generator.prototype.appJs = function appJs() { var appendOptions = { html: this.indexFile, fileType: 'js', optimizedPath: 'scripts/scripts.js', - sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js'], + sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js', 'scripts/controllers/navbar.js'], searchPath: ['.tmp', 'app'] }; if (this.jade) { @@ -410,6 +427,7 @@ Generator.prototype.createIndex = function createIndex() { Generator.prototype.addJadeViews = function addHtmlJade() { if(this.jade) { this.copy('../../templates/views/jade/partials/main.jade', 'app/views/partials/main.jade'); + this.copy('../../templates/views/jade/partials/navbar.jade', 'app/views/partials/navbar.jade'); this.copy('../../templates/views/jade/404.jade', 'app/views/404.jade'); } }; @@ -417,6 +435,7 @@ Generator.prototype.addJadeViews = function addHtmlJade() { Generator.prototype.addHtmlViews = function addHtmlViews() { if(!this.jade) { this.copy('../../templates/views/html/partials/main.html', 'app/views/partials/main.html'); + this.copy('../../templates/views/html/partials/navbar.html', 'app/views/partials/navbar.html'); this.copy('../../templates/views/html/404.html', 'app/views/404.html'); } }; diff --git a/templates/coffeescript-min/navbar.coffee b/templates/coffeescript-min/navbar.coffee new file mode 100644 index 000000000..160bb4485 --- /dev/null +++ b/templates/coffeescript-min/navbar.coffee @@ -0,0 +1,17 @@ +'use strict' + +angular.module('<%= scriptAppName %>') + .controller 'NavbarCtrl', ['$scope', '$location', ($scope, $location) -> + $scope.menu = [ + title: 'Home' + link: '/' + , + title: 'About' + link: '#' + , + title: 'Contact' + link: '#' + ] + $scope.isActive = (route) -> + route is $location.path() + ] \ No newline at end of file diff --git a/templates/coffeescript/navbar.coffee b/templates/coffeescript/navbar.coffee new file mode 100644 index 000000000..a734e22c4 --- /dev/null +++ b/templates/coffeescript/navbar.coffee @@ -0,0 +1,16 @@ +'use strict' + +angular.module('<%= scriptAppName %>') + .controller 'NavbarCtrl', ($scope, $location) -> + $scope.menu = [ + title: 'Home' + link: '/' + , + title: 'About' + link: '#' + , + title: 'Contact' + link: '#' + ] + $scope.isActive = (route) -> + route is $location.path() \ No newline at end of file diff --git a/templates/javascript-min/navbar.js b/templates/javascript-min/navbar.js new file mode 100644 index 000000000..84421b4ba --- /dev/null +++ b/templates/javascript-min/navbar.js @@ -0,0 +1,21 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .controller('NavbarCtrl', ['$scope', '$location', function ($scope, $location) { + $scope.menu = [{ + 'title': 'Home', + 'link': '/' + }, + { + 'title': 'About', + 'link': '#' + }, + { + 'title': 'Contact', + 'link': '#' + }]; + + $scope.isActive = function(route) { + return route === $location.path(); + }; + }]); diff --git a/templates/javascript/navbar.js b/templates/javascript/navbar.js new file mode 100644 index 000000000..8921337f7 --- /dev/null +++ b/templates/javascript/navbar.js @@ -0,0 +1,21 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .controller('NavbarCtrl', function ($scope, $location) { + $scope.menu = [{ + 'title': 'Home', + 'link': '/' + }, + { + 'title': 'About', + 'link': '#' + }, + { + 'title': 'Contact', + 'link': '#' + }]; + + $scope.isActive = function(route) { + return route === $location.path(); + }; + }); diff --git a/templates/views/html/partials/main.html b/templates/views/html/partials/main.html index c03ba9a23..17dc9b4d8 100644 --- a/templates/views/html/partials/main.html +++ b/templates/views/html/partials/main.html @@ -1,11 +1,4 @@ -
- -

<%= appname %>

-
+

'Allo, 'Allo!

diff --git a/templates/views/html/partials/navbar.html b/templates/views/html/partials/navbar.html new file mode 100644 index 000000000..66811cdc1 --- /dev/null +++ b/templates/views/html/partials/navbar.html @@ -0,0 +1,8 @@ +
+ +

<%= appname %>

+
\ No newline at end of file diff --git a/templates/views/jade/partials/main.jade b/templates/views/jade/partials/main.jade index e1aee38e3..32dea25a6 100644 --- a/templates/views/jade/partials/main.jade +++ b/templates/views/jade/partials/main.jade @@ -1,12 +1,5 @@ -.header - ul.nav.nav-pills.pull-right - li.active - a(ng-href='#') Home - li - a(ng-href='#') About - li - a(ng-href='#') Contact - h3.text-muted <%= scriptAppName %> +div(ng-include='\'partials/navbar.html\'') + .jumbotron h1 'Allo, 'Allo! p.lead diff --git a/templates/views/jade/partials/navbar.jade b/templates/views/jade/partials/navbar.jade new file mode 100644 index 000000000..8f6506439 --- /dev/null +++ b/templates/views/jade/partials/navbar.jade @@ -0,0 +1,5 @@ +.header(ng-controller='NavbarCtrl') + ul.nav.nav-pills.pull-right + li(ng-repeat='item in menu', ng-class='{active: isActive(item.link)}') + a(ng-href='{{item.link}}') {{item.title}} + h3.text-muted <%= scriptAppName %> \ No newline at end of file