-
Notifications
You must be signed in to change notification settings - Fork 21
/
exampleController.js
54 lines (47 loc) · 1.96 KB
/
exampleController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Hilary.scope('heinz').register({
name: 'exampleController',
dependencies: ['newGidgetModule', 'GidgetRoute', 'locale', 'viewEngine'],
factory: function ($this, GidgetRoute, locale, viewEngine) {
'use strict';
// route with `before` and `after` pipelines, using GidgetRoute
$this.get['/gidget/example'] = new GidgetRoute({
routeHandler: function () {
// you may need to use AJAX to connect with the server here
// check out the homeController search route for an example
viewEngine.setVM({
// the id of your template goes here
template: 't-empty',
// data from your model goes here (i.e. `new MyModel()`)
data: {
heading: locale.pages.home.empty.heading,
body: 'Route: "/gidget/example"'
},
after: function (vm) {
console.log('view model:', vm);
}
});
},
before: function (err, req) {
console.log('before example 1 route:', req);
},
after: function (err, req) {
console.log('after example 1 route:', req);
}
});
// route with parameters
$this.get['/gidget/breweries/:brewery/beers/:beer'] = function (err, req) {
var body = 'Route: "/gidget/breweries/:brewery/beers/:beer", Brewery: {brewery}, Beer: {beer}'
.replace('{brewery}', req.params.brewery)
.replace('{beer}', req.params.beer);
viewEngine.setVM({
template: 't-empty',
data: {
heading: locale.pages.home.empty.heading,
body: body
}
});
console.log('this is a Gidget request object:', req);
};
return $this;
}
});