Skip to content

Commit

Permalink
TypeScriptifying the generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Eggers committed Jan 7, 2014
1 parent acf9cff commit c7a37fa
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 62 deletions.
8 changes: 7 additions & 1 deletion templates/typescript/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular.d.ts" />
<% if (ngRoute) { %>/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-route.d.ts" /><% } %>
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-resource.d.ts" />
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-sanitize.d.ts" />
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-resource.d.ts" />

'use strict';

angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) { %>
.config(function ($routeProvider) {
.config(function ($routeProvider:ng.route.IRouteProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
Expand Down
27 changes: 20 additions & 7 deletions templates/typescript/controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/// <reference path="../app.ts" />

'use strict';

module <%= scriptAppName %> {
export interface I<%= classedName %>Scope extends ng.IScope {
awesomeThings: any[];
}

export class <%= classedName %>Ctrl {

constructor (private $scope:I<%= classedName %>Scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}
}
}

angular.module('<%= scriptAppName %>')
.controller('<%= classedName %>Ctrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
});
.controller('<%= classedName %>Ctrl', <%= scriptAppName %>.<%= classedName %>Ctrl);
21 changes: 15 additions & 6 deletions templates/typescript/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/// <reference path="../app.ts" />

'use strict';

module <%= scriptAppName %>{
export function <%= cameledName %>DecoratorProvider($provide:ng.auto.IProvideService):void {
//decorate <%= cameledName %>
$provide.decorator('<%= cameledName %>', <%= cameledName %>Decorator);
}

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

angular.module('<%= scriptAppName %>')
.config(function ($provide) {
$provide.decorator('<%= cameledName %>', function ($delegate) {
// decorate the $delegate
return $delegate;
});
});
.config(<%= scriptAppName %>.<%= cameledName %>DecoratorProvider);
28 changes: 19 additions & 9 deletions templates/typescript/directive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/// <reference path="../app.ts" />

'use strict';

module <%= scriptAppName %> {

export class <%= classedName %> implements ng.IDirective {
template = '<div></div>';
restrict = 'E';
link = function (scope, element: JQuery, attrs: ng.IAttributes):void {
element.text('this is the <%= cameledName %> directive');
}
}

export function <%= cameledName %>Factory() {
return new <%= scriptAppName %>.<%= classedName %>();
}

}

angular.module('<%= scriptAppName %>')
.directive('<%= cameledName %>', function () {
return {
template: '<div></div>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
element.text('this is the <%= cameledName %> directive');
}
};
});
.directive('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>Factory);
20 changes: 15 additions & 5 deletions templates/typescript/filter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
/// <reference path="../app.ts" />

'use strict';

module <%= scriptAppName %> {
export function <%= cameledName %>FilterFactory():Function {
return <%= cameledName %>Filter;
}

function <%= cameledName %>Filter(input, param) {
//usage {{"text" | <%= cameledName %>: "suffix"}}
//returns '<%= cameledName %> filter: text suffix'
return '<%= cameledName %> filter: ' + input + (param ? ' ' + param: '');
}
}

angular.module('<%= scriptAppName %>')
.filter('<%= cameledName %>', function () {
return function (input) {
return '<%= cameledName %> filter: ' + input;
};
});
.filter('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>FilterFactory);
29 changes: 17 additions & 12 deletions templates/typescript/service/factory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/// <reference path="../app.ts" />

'use strict';

angular.module('<%= scriptAppName %>')
.factory('<%= cameledName %>', function () {
// Service logic
// ...
module <%= scriptAppName %> {
export function <%= cameledName %>Factory() {
return new <%= classedName %>(42);
}
export class <%= classedName %> {

var meaningOfLife = 42;
constructor (private meaningOfLife) {
}

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

angular.module('<%= scriptAppName %>')
.factory('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>Factory);
38 changes: 19 additions & 19 deletions templates/typescript/service/provider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/// <reference path="../app.ts" />

'use strict';

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

// Private variables
var salutation = 'Hello';
var salutation:string;

export class Greeter {
greet = () => salutation;
}


export class <%= classedName %>Provider {
$get = () => new Greeter();

// Public API for configuration
setSalutation = (s:string) => salutation = s;
}

// 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();
};
});
angular.module('<%= scriptAppName %>')
.provider('<%= cameledName %>', <%= scriptAppName %>.<%= classedName %>Provider);
16 changes: 13 additions & 3 deletions templates/typescript/service/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/// <reference path="../app.ts" />

'use strict';

module <%= scriptAppName %> {
export class <%= classedName %> {
awesomeThings:any[] = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}
}

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

0 comments on commit c7a37fa

Please sign in to comment.