Skip to content

Commit 9628565

Browse files
committed
Support for module.classy.controllers[{}, {}]
Accepts an array of controllers and returns the module, e.g.: `module.classy.controllers([xxx, xxx]).config(xxx).run(xxx)` Fixes #29
1 parent eafb7cc commit 9628565

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

angular-classy.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ angular.module = (name, reqs, configFn) ->
7373
# Initialisation (after instance is created)
7474
constructor: -> classFns.init(@, arguments, module)
7575

76+
controllers: (controllerArray) ->
77+
# Accepts an array of controllers and returns the module, e.g.:
78+
# `module.classy.controllers([xxx, xxx]).config(xxx).run(xxx)`
79+
# Requested in issue #29
80+
for classObj in controllerArray
81+
@controller(classObj)
82+
return module
83+
7684
module.cC = module.classy.controller
85+
module.cCs = module.classy.controllers
86+
7787

7888
return module
7989

angular-classy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,18 @@ License: MIT
120120
return classyController;
121121

122122
})();
123+
},
124+
controllers: function(controllerArray) {
125+
var classObj, _i, _len;
126+
for (_i = 0, _len = controllerArray.length; _i < _len; _i++) {
127+
classObj = controllerArray[_i];
128+
this.controller(classObj);
129+
}
130+
return module;
123131
}
124132
};
125133
module.cC = module.classy.controller;
134+
module.cCs = module.classy.controllers;
126135
}
127136
}
128137
return module;

angular-classy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/test/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
app = angular.module('app', ['classy']).classy.controllers([{
2+
name: 'hello',
3+
inject: ['$scope'],
4+
init: function() {
5+
this.$.foo = 'bar'
6+
}
7+
}, {
8+
name: 'goodbye',
9+
inject: ['$scope'],
10+
init: function() {
11+
this.$.foo = 'baz'
12+
}
13+
}])
14+
console.log(app)

examples/test/bower.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "angular-classy-test",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"angular": "~1.2"
6+
}
7+
}

examples/test/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en" ng-app="app">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Simple test for multiple controllers</title>
7+
</head>
8+
<body>
9+
<p>Simple test for multiple controllers, more tests will be added here in future.</p>
10+
<section id="todoapp" ng-controller="hello">
11+
{{ foo }}
12+
</section>
13+
<section id="todoapp" ng-controller="goodbye">
14+
{{ foo }}
15+
</section>
16+
<script src="bower_components/angular/angular.js"></script>
17+
<script src="../../angular-classy.js"></script>
18+
<script src="app.js"></script>
19+
</body>
20+
</html>

src/angular-classy-core.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ angular.module = (name, reqs, configFn) ->
7373
# Initialisation (after instance is created)
7474
constructor: -> classFns.init(@, arguments, module)
7575

76+
controllers: (controllerArray) ->
77+
# Accepts an array of controllers and returns the module, e.g.:
78+
# `module.classy.controllers([xxx, xxx]).config(xxx).run(xxx)`
79+
# Requested in issue #29
80+
for classObj in controllerArray
81+
@controller(classObj)
82+
return module
83+
7684
module.cC = module.classy.controller
85+
module.cCs = module.classy.controllers
86+
7787

7888
return module
7989

0 commit comments

Comments
 (0)