Created
December 28, 2016 05:23
-
-
Save thosakwe/faf9d3f6aeb2eca444bf1af25e15b7f8 to your computer and use it in GitHub Desktop.
Angel template hypothetical thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:angel_framework/angel_framework.dart'; | |
import 'package:angular2/angular2.dart'; | |
import 'playing_card.dart'; | |
import 'lib/models/user.dart'; | |
@Component( | |
selector: 'home', | |
templateUrl: 'home.html', | |
directives: const [PlayingCardComponent]) | |
class HomeComponent { | |
@Input() | |
String suit; | |
@Input() | |
User user; | |
bool get loggedIn => user != null; | |
HomeComponent(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:angel_framework/angel_framework.dart'; | |
import 'playing_card.dart'; | |
import 'lib/models/user.dart'; | |
import 'playing_card.g.dart'; | |
/// Auto-generated template - DO NOT MODIFY!!! | |
RequestMiddleware Home({String suit, User user}) { | |
return (RequestContext req, ResponseContext res) async { | |
var template = new _HomeComponent(req, suit: suit); | |
res.contentType = ContentType.HTML; | |
res.write(template.render(req, res)); | |
res.end(); | |
}; | |
} | |
class _HomeComponent { | |
final RequestContext req; | |
String suit; | |
User user; | |
bool get loggedIn => user != null; | |
_HomeComponent(this.req, {this.suit, this.user}); | |
String render(RequestContext req, ResponseContext res) { | |
var buf = new StringBuffer(); | |
buf.write('''<html> | |
<head> | |
<title>'''); | |
buf.write(user.name); | |
buf.write(''' - My Site</title> | |
</head> | |
<body> | |
<h1>Angel</h1> | |
'''); | |
if (loggedIn) { | |
// render div | |
} | |
if (!loggedIn) { | |
// render div | |
} | |
var playing_card$1 = new _PlayingCardComponent(req, suit: suit); | |
buf.write(playing_card$1.render(req, res)); | |
buf.write(''' | |
</body> | |
</html>'''); | |
return buf.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>{{user.name}} - My Site</title> | |
</head> | |
<body> | |
<h1>Angel</h1> | |
<div *ngIf="loggedIn"></div> | |
<div *ngIf="!loggedIn"></div> | |
<playing-card [suit]="suit"></playing-card> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:angel_framework/angel_framework.dart'; | |
import 'package:angular2/angular2.dart'; | |
@Component(selector: 'playing-card', templateUrl: 'playing_card.html') | |
class PlayingCardComponent { | |
// Should support DI :) | |
final RequestContext req; | |
@Input() | |
String suit; | |
String get ip => req.ip; | |
PlayingCard(this.req); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:angel_framework/angel_framework.dart'; | |
/// Auto-generated template - DO NOT MODIFY!!! | |
RequestMiddleware PlayingCard({String suit}) { | |
return (RequestContext req, ResponseContext res) async { | |
var template = new _PlayingCardComponent(req, suit: suit); | |
res.contentType = ContentType.HTML; | |
res.write(template.render(req, res)); | |
res.end(); | |
}; | |
} | |
class _PlayingCardComponent { | |
final RequestContext req; | |
String suit; | |
String get ip => req.ip; | |
_PlayingCardComponent(this.req, {this.suit}); | |
String render(RequestContext req, ResponseContext res) { | |
var buf = new StringBuffer(); | |
buf.write('''<div> | |
Pretend this is a playing card of suit '''); | |
buf.write(suit); | |
buf.write(''' | |
Your IP is: '''); | |
buf.write(''' | |
</div>'''); | |
return buf.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
Pretend this is a playing card of suit {{suit}}. | |
Your IP is: {{ip}}. | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:angel_framework/angel_framework.dart'; | |
import 'views/views.dart'; | |
main() async { | |
var app = new Angel(); | |
await app.configure(compiledTemplates); | |
app.get('/card/:suit', (req, res) { | |
return res.render('home', suit: req.params['suit'], user: req.user); | |
}); | |
await app.startServer(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment