diff --git a/templates/common/root/app/.buildignore b/templates/common/root/app/.buildignore index fc98b8eb5..548f58c3c 100644 --- a/templates/common/root/app/.buildignore +++ b/templates/common/root/app/.buildignore @@ -1 +1,2 @@ -*.coffee \ No newline at end of file +*.coffee +*.ts \ No newline at end of file diff --git a/templates/typescript/app.ts b/templates/typescript/app.ts new file mode 100644 index 000000000..58f75e3dc --- /dev/null +++ b/templates/typescript/app.ts @@ -0,0 +1,13 @@ +'use strict'; + +angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) { %> + .config(function ($routeProvider) { + $routeProvider + .when('/', { + templateUrl: 'views/main.html', + controller: 'MainCtrl' + }) + .otherwise({ + redirectTo: '/' + }); + })<% } %>; diff --git a/templates/typescript/controller.ts b/templates/typescript/controller.ts new file mode 100644 index 000000000..216a5ea20 --- /dev/null +++ b/templates/typescript/controller.ts @@ -0,0 +1,10 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .controller('<%= classedName %>Ctrl', function ($scope) { + $scope.awesomeThings = [ + 'HTML5 Boilerplate', + 'AngularJS', + 'Karma' + ]; + }); diff --git a/templates/typescript/decorator.ts b/templates/typescript/decorator.ts new file mode 100644 index 000000000..57efaa3f6 --- /dev/null +++ b/templates/typescript/decorator.ts @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .config(function ($provide) { + $provide.decorator('<%= cameledName %>', function ($delegate) { + // decorate the $delegate + return $delegate; + }); + }); diff --git a/templates/typescript/directive.ts b/templates/typescript/directive.ts new file mode 100644 index 000000000..57b0e1f3d --- /dev/null +++ b/templates/typescript/directive.ts @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .directive('<%= cameledName %>', function () { + return { + template: '
', + restrict: 'E', + link: function postLink(scope, element, attrs) { + element.text('this is the <%= cameledName %> directive'); + } + }; + }); diff --git a/templates/typescript/filter.ts b/templates/typescript/filter.ts new file mode 100644 index 000000000..9f897ab76 --- /dev/null +++ b/templates/typescript/filter.ts @@ -0,0 +1,8 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .filter('<%= cameledName %>', function () { + return function (input) { + return '<%= cameledName %> filter: ' + input; + }; + }); diff --git a/templates/typescript/service/constant.ts b/templates/typescript/service/constant.ts new file mode 100644 index 000000000..0c02a8a8a --- /dev/null +++ b/templates/typescript/service/constant.ts @@ -0,0 +1,4 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .constant('<%= cameledName %>', 42); diff --git a/templates/typescript/service/factory.ts b/templates/typescript/service/factory.ts new file mode 100644 index 000000000..f7e942eb9 --- /dev/null +++ b/templates/typescript/service/factory.ts @@ -0,0 +1,16 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .factory('<%= cameledName %>', function () { + // Service logic + // ... + + var meaningOfLife = 42; + + // Public API here + return { + someMethod: function () { + return meaningOfLife; + } + }; + }); diff --git a/templates/typescript/service/provider.ts b/templates/typescript/service/provider.ts new file mode 100644 index 000000000..101e774c5 --- /dev/null +++ b/templates/typescript/service/provider.ts @@ -0,0 +1,25 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .provider('<%= cameledName %>', function () { + + // Private variables + var salutation = 'Hello'; + + // Private constructor + function Greeter() { + this.greet = function () { + return salutation; + }; + } + + // Public API for configuration + this.setSalutation = function (s) { + salutation = s; + }; + + // Method for instantiating + this.$get = function () { + return new Greeter(); + }; + }); diff --git a/templates/typescript/service/service.ts b/templates/typescript/service/service.ts new file mode 100644 index 000000000..1adfe44b4 --- /dev/null +++ b/templates/typescript/service/service.ts @@ -0,0 +1,6 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .service('<%= classedName %>', function <%= classedName %>() { + // AngularJS will instantiate a singleton by calling "new" on this function + }); diff --git a/templates/typescript/service/value.ts b/templates/typescript/service/value.ts new file mode 100644 index 000000000..01507e03f --- /dev/null +++ b/templates/typescript/service/value.ts @@ -0,0 +1,4 @@ +'use strict'; + +angular.module('<%= scriptAppName %>') + .value('<%= cameledName %>', 42); diff --git a/templates/typescript/spec/controller.ts b/templates/typescript/spec/controller.ts new file mode 100644 index 000000000..95005029e --- /dev/null +++ b/templates/typescript/spec/controller.ts @@ -0,0 +1,22 @@ +'use strict'; + +describe('Controller: <%= classedName %>Ctrl', function () { + + // load the controller's module + beforeEach(module('<%= scriptAppName %>')); + + var <%= classedName %>Ctrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + <%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', { + $scope: scope + }); + })); + + it('should attach a list of awesomeThings to the scope', function () { + expect(scope.awesomeThings.length).toBe(3); + }); +}); diff --git a/templates/typescript/spec/directive.ts b/templates/typescript/spec/directive.ts new file mode 100644 index 000000000..fbe52519c --- /dev/null +++ b/templates/typescript/spec/directive.ts @@ -0,0 +1,20 @@ +'use strict'; + +describe('Directive: <%= cameledName %>', function () { + + // load the directive's module + beforeEach(module('<%= scriptAppName %>')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); + + it('should make hidden element visible', inject(function ($compile) { + element = angular.element('<<%= _.dasherize(name) %>><%= _.dasherize(name) %>>'); + element = $compile(element)(scope); + expect(element.text()).toBe('this is the <%= cameledName %> directive'); + })); +}); diff --git a/templates/typescript/spec/filter.ts b/templates/typescript/spec/filter.ts new file mode 100644 index 000000000..7fbea7257 --- /dev/null +++ b/templates/typescript/spec/filter.ts @@ -0,0 +1,19 @@ +'use strict'; + +describe('Filter: <%= cameledName %>', function () { + + // load the filter's module + beforeEach(module('<%= scriptAppName %>')); + + // initialize a new instance of the filter before each test + var <%= cameledName %>; + beforeEach(inject(function ($filter) { + <%= cameledName %> = $filter('<%= cameledName %>'); + })); + + it('should return the input prefixed with "<%= cameledName %> filter:"', function () { + var text = 'angularjs'; + expect(<%= cameledName %>(text)).toBe('<%= cameledName %> filter: ' + text); + }); + +}); diff --git a/templates/typescript/spec/service.ts b/templates/typescript/spec/service.ts new file mode 100644 index 000000000..1e0c27c21 --- /dev/null +++ b/templates/typescript/spec/service.ts @@ -0,0 +1,18 @@ +'use strict'; + +describe('Service: <%= cameledName %>', function () { + + // load the service's module + beforeEach(module('<%= scriptAppName %>')); + + // instantiate service + var <%= cameledName %>; + beforeEach(inject(function (_<%= cameledName %>_) { + <%= cameledName %> = _<%= cameledName %>_; + })); + + it('should do something', function () { + expect(!!<%= cameledName %>).toBe(true); + }); + +});