Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying John Papa Style Guide to generator-ng-component #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions templates/controller/name.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.controller('<%= classedName %>Ctrl', function ($scope) {
$scope.message = 'Hello';
});
angular
.module('<%= scriptAppName %>')
.controller('<%= classedName %>Controller', <%= classedName %>Controller);


function <%= classedName %>Controller() {
var vm = this;
vm.message = 'Hello';
}

})();
13 changes: 5 additions & 8 deletions templates/controller/name.controller.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
'use strict';

describe('Controller: <%= classedName %>Ctrl', function () {
describe('Controller: <%= classedName %>Controller', function () {

// load the controller's module
beforeEach(module('<%= scriptAppName %>'));

var <%= classedName %>Ctrl, scope;
var <%= classedName %>Controller;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {
$scope: scope
});
// Initialize the controller
beforeEach(inject(function ($controller) {
<%= classedName %>Controller = $controller('<%= classedName %>Controller', {});
}));

it('should ...', function () {<% if (hasFilter('jasmine')) { %>
Expand Down
26 changes: 17 additions & 9 deletions templates/decorator/name.decorator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
'use strict';

angular.module('<%= scriptAppName %>')
.config(function ($provide) {
$provide.decorator('<%= cameledName %>', function ($delegate) {
// decorate the $delegate
return $delegate;
});
});
(function() {
'use strict';

angular
.module('<%= scriptAppName %>')
.config(<%= scriptAppName %>Config);

function <%= scriptAppName %>Config($provide) {
$provide.decorator('<%= cameledName %>', <%= scriptAppName %>Decorator);
}

function <%= scriptAppName %>Decorator($delegate) {
// decorate the $delegate
return $delegate;
}

})();
26 changes: 16 additions & 10 deletions templates/directiveComplex/name.directive.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.directive('<%= cameledName %>', function () {
return {
templateUrl: '<%= htmlUrl %>',
restrict: 'EA',
link: function (scope, element, attrs) {
}
};
});
angular
.module('<%= scriptAppName %>')
.directive('<%= cameledName %>', <%= cameledName %>);

function <%= cameledName %>() {
return {
templateUrl: '<%= htmlUrl %>',
restrict: 'EA',
link: function (scope, element, attrs) {
element.text('this is the <%= cameledName %> directive');
}
};
};
})();
27 changes: 16 additions & 11 deletions templates/directiveSimple/name.directive.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.directive('<%= cameledName %>', function () {
return {
template: '<div></div>',
restrict: 'EA',
link: function (scope, element, attrs) {
element.text('this is the <%= cameledName %> directive');
}
};
});
angular
.module('<%= scriptAppName %>')
.directive('<%= cameledName %>', <%= cameledName %>);

function <%= cameledName %>() {
return {
template: '<div></div>',
restrict: 'EA',
link: function (scope, element, attrs) {
element.text('this is the <%= cameledName %> directive');
}
};
}
})();
29 changes: 21 additions & 8 deletions templates/factory/name.service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.factory('<%= cameledName %>', function () {
angular
.module('<%= scriptAppName %>')
.factory('<%= cameledName %>', <%= cameledName %>);

function <%= cameledName %>() {
// Service logic
// ...

var meaningOfLife = 42;

var service = {
someMethod: someMethod
};

// Public API here
return {
someMethod: function () {
return meaningOfLife;
}
return service;

///////

function someMethod() {
return meaningOfLife;
};
});

};

})();
13 changes: 9 additions & 4 deletions templates/filter/name.filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.filter('<%= cameledName %>', function () {
angular
.module('<%= scriptAppName %>')
.filter('<%= cameledName %>', <%= cameledName %>);

function <%= cameledName %>() {
return function (input) {
return '<%= cameledName %> filter: ' + input;
};
});
};
})();
14 changes: 10 additions & 4 deletions templates/provider/name.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.provider('<%= cameledName %>', function () {
angular
.module('<%= scriptAppName %>')
.provider('<%= cameledName %>',<%= cameledName %>Provider);

function <%= cameledName %>Provider() {

// Private variables
var salutation = 'Hello';
Expand All @@ -22,4 +26,6 @@ angular.module('<%= scriptAppName %>')
this.$get = function () {
return new Greeter();
};
});
}

})();
23 changes: 14 additions & 9 deletions templates/route/name(ngroute).js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.config(function ($routeProvider) {
$routeProvider
.when('<%= route %>', {
templateUrl: '<%= htmlUrl %>',
controller: '<%= classedName %>Ctrl'
});
});
angular
.module('<%= scriptAppName %>')
.config(function ($routeProvider) {
$routeProvider
.when('<%= route %>', {
templateUrl: '<%= htmlUrl %>',
controller: '<%= classedName %>Conctroller',
controllerAs: <%= classedName %>
});
});

})();
25 changes: 15 additions & 10 deletions templates/route/name(uirouter).js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.config(function ($stateProvider) {
$stateProvider
.state('<%= name %>', {
url: '<%= route %>',
templateUrl: '<%= htmlUrl %>',
controller: '<%= classedName %>Ctrl'
});
});
angular
.module('<%= scriptAppName %>')
.config(function ($stateProvider) {
$stateProvider
.state('<%= name %>', {
url: '<%= route %>',
templateUrl: '<%= htmlUrl %>',
controller: '<%= classedName %>Controller',
controllerAs: <%= classedName %>
});
});

})();
18 changes: 13 additions & 5 deletions templates/route/name.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.controller('<%= classedName %>Ctrl', function ($scope) {
$scope.message = 'Hello';
});
angular
.module('<%= scriptAppName %>')
.controller('<%= classedName %>Controller', <%= classedName %>Controller);


function <%= classedName %>Controller() {
var vm = this;
vm.message = 'Hello';
}

})();
13 changes: 5 additions & 8 deletions templates/route/name.controller.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
'use strict';

describe('Controller: <%= classedName %>Ctrl', function () {
describe('Controller: <%= classedName %>Controller', function () {

// load the controller's module
beforeEach(module('<%= scriptAppName %>'));

var <%= classedName %>Ctrl, scope;
var <%= classedName %>Controller;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', {
$scope: scope
});
// Initialize the controller
beforeEach(inject(function ($controller) {
<%= classedName %>Controller = $controller('<%= classedName %>Controller', {});
}));

it('should ...', function () {<% if (hasFilter('jasmine')) { %>
Expand Down
2 changes: 1 addition & 1 deletion templates/route/name.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div>This is the <%= name %> view.</div>
<div>This is the <%= name %> view. {{<%= classedName %>.message}}</div>
16 changes: 11 additions & 5 deletions templates/service/name.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use strict';
(function() {
'use strict';

angular.module('<%= scriptAppName %>')
.service('<%= cameledName %>', function () {
// AngularJS will instantiate a singleton by calling "new" on this function
});
angular
.module('<%= scriptAppName %>')
.service('<%= cameledName %>', <%= cameledName %>Service);

function <%= cameledName %>Service() {
// AngularJS will instantiate a singleton by calling "new" on this function
}

})();