在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):dustinspecker/generator-ng-poly开源软件地址(OpenSource Url):https://github.com/dustinspecker/generator-ng-poly开源编程语言(OpenSource Language):JavaScript 87.1%开源软件介绍(OpenSource Introduction):generator-ng-poly
Inspired by John Papa's Angular Style Guide and Todd Motto's AngularJS styleguide. PurposeThis generator focuses on organizing Angular components by feature (home, about, video player, etc.) instead of by type (controller, service, directive, etc.) to encourage the development of self-contained, reusable components. A typical workflow with this generator consists of creating an Angular module (ng-poly:module) and then generating controllers, directives, etc. for this module to create a new feature. Polymer is just an added feature, but it isn't required to utilize this generator. UsageInstall
If TypeScript is going to be used,
Run If using Node 0.12, there is a bug in Yeoman or Node causing yeoman generators to hang. With ng-poly, if after it outputs the generated home module files it hangs, then it is safe to enter Run User GroupsPlease feel free to ask any questions on our GitHub Issues or Google Group. GeneratorsAvailable generators:
Languages and Features supported:
† e2e tests are not supported in TypeScript. JavaScript will instead be used for e2e tests. Gulp Tasks Briefing
Using
All generators ask for a module name except app and element. All generators except app take a name as an argument. A name can be written with CamelCase or hyphens. Generators requiring a module can take a module option to bypass the prompt:
A module value of Examples are shown with HTML, LESS, JavaScript, Jasmine, and UI Router as the app configuration. AppAsks for application name and language preferences to scaffold out an application with a home module. It will also ask if tests should be placed in the Example: Run
ng-poly makes some assumptions, but these can be overridden.
Example: A module-only structure produces:
A module-type structure produces:
* Only TypeScript projects will have this. ConstantGenerates a constant and its test. Example:
Produces (function () {
'use strict';
/**
* @ngdoc service
* @name module.constant:theHero
*
* @description
*
*/
angular
.module('module')
.constant('theHero', 0);
}()); Produces /*global describe, beforeEach, it, expect, inject, module*/
'use strict';
describe('theHero', function () {
var constant;
beforeEach(module('module'));
beforeEach(inject(function (theHero) {
constant = theHero;
}));
it('should equal 0', function () {
expect(constant).toBe(0);
});
}); ControllerGenrates a controller and its test. Example:
Produces (function () {
'use strict';
/**
* @ngdoc object
* @name module.controller:MicroCtrl
* @requires $scope
*
* @description
*
*/
angular
.module('module')
.controller('MicroCtrl', MicroCtrl);
function MicroCtrl($scope) {
$scope.micro = {};
$scope.micro.ctrlName = 'MicroCtrl';
}
}()); Produces /*global describe, beforeEach, it, expect, inject, module*/
'use strict';
describe('MicroCtrl', function () {
var scope;
beforeEach(module('module'));
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
$controller('MicroCtrl', {$scope: scope});
}));
it('should have ctrlName as MicroCtrl', function () {
expect(scope.micro.ctrlName).toEqual('MicroCtrl');
});
}); DecoratorGenerates a decorator and its test. Example:
Note: If decorating a service starting with a
Produces (function () {
'use strict';
/**
* @ngdoc decorator
* @name home.decorator:awesomeService
* @restrict EA
* @element
*
* @description
*
*/
angular
.module('module')
.config(decorator);
function decorator($provide) {
$provide.decorator('awesomeService', function ($delegate) {
$delegate.simpleFunction = function () {
return 'awesomeService';
};
return $delegate;
});
}
}()); Produces: /*global describe, beforeEach, it, expect, inject, module*/
'use strict';
describe('awesomeService', function () {
var decorator;
beforeEach(module('module'));
beforeEach(inject(function (awesomeService) {
decorator = awesomeService;
}));
it('should have simpleFunction return awesomeService', function () {
expect(decorator.simpleFunction()).toEqual('awesomeService');
});
}); DirectiveGenerates a directive, its template, and its test. Example:
Produces (function () {
'use strict';
/**
* @ngdoc directive
* @name module.directive:fancyButton
* @restrict EA
* @element
*
* @description
*
* @example
<example module="module">
<file name="index.html">
<fancy-button></fancy-button>
</file>
</example>
*
*/
angular
.module('module')
.directive('fancyButton', fancyButton);
function fancyButton() {
return {
restrict: 'EA',
scope: {},
templateUrl: 'module/fancy-button-directive.tpl.html',
replace: false,
controller: function (scope) {
scope.fancyButton = {};
scope.fancyButton.name = 'fancyButton';
},
link: function (scope, element, attrs) {
/*jshint unused:false */
/*eslint "no-unused-vars": [2, {"args": "none"}]*/
}
};
}
}()); Produces <div>{{fancyButton.name}}</div> Produces /*global describe, beforeEach, it, expect, inject, module*/
'use strict';
describe('fancyButton', function () {
var scope;
var element;
beforeEach(module('module', 'module/fancy-button-directive.tpl.html'));
beforeEach(inject(function ($compile, $rootScope) {
scope = $rootScope.$new();
element = $compile(angular.element('<fancy-button></fancy-button>'))(scope);
}));
it('should have correct text', function () {
scope.$apply();
expect(element.isolateScope().fancyButton.name).toEqual('fancyButton');
});
}); The directive's template (HAML, HTML, or Jade) is converted to a temporary module automatically for testing. FactoryGenerates a factory and its test. Example:
Produces (function () {
'use strict';
/**
* @ngdoc service
* @name module.factory:Cake
*
* @description
*
*/
angular
.module('module')
.factory('Cake', Cake);
function Cake() {
var CakeBase = {};
CakeBase.someValue = 'Cake';
CakeBase.someMethod = function () {
return 'Cake';
};
return CakeBase;
}
}()); Produces /*global describe, beforeEach, it, expect, inject, module*/
'use strict';
describe('Cake', function () {
var factory;
beforeEach(module('module'));
beforeEach(inject(function (Cake) {
factory = Cake;
}));
it('should have someValue be Cake', function () {
expect(factory.someValue).toEqual('Cake');
});
it('should have someMethod return Cake', function () {
expect(factory.someMethod()).toEqual('Cake');
});
}); FilterGenerates a filter and its test. Example:
Produces (function () {
'use strict';
/**
* @ngdoc filter
* @name module.filter:coffee
*
* @description
*
* |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论