Skip to content

Commit 439e932

Browse files
committed
First iteration of Chapter 7 on prod deployment
1 parent f149eef commit 439e932

File tree

14 files changed

+225
-0
lines changed

14 files changed

+225
-0
lines changed

Chapter_07/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web/di_factories_gen.dart
2+
web/ng_parser_gen.dart

Chapter_07/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Chapter 7: Prod Deployment
2+
==========================
3+
4+
WIP...

Chapter_07/bin/generator.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
library chapter07.generator;
2+
3+
import 'dart:io';
4+
import 'package:di/generator.dart' as di_generator;
5+
import 'package:angular/tools/expression_extractor.dart' as ng_generator;
6+
7+
main() {
8+
var dartSdkPath = Platform.environment['DART_SDK'];
9+
if (dartSdkPath == null || dartSdkPath.isEmpty) {
10+
throw 'export DART_SDK=/path/to/dart/sdk';
11+
}
12+
var entryPointDartFile = 'web/main.dart';
13+
var injectablesAnnotations = 'angular.core.NgComponent,'
14+
'angular.core.NgController,'
15+
'angular.core.NgDirective,'
16+
'angular.core.NgFilter,'
17+
'injectable.InjectableService,'
18+
'angular.core.service.NgInjectableService';
19+
var diOutputFile = 'web/di_factories_gen.dart';
20+
var packageRoots = 'packages';
21+
22+
_runDiGenerator(dartSdkPath, entryPointDartFile, injectablesAnnotations,
23+
diOutputFile, packageRoots);
24+
25+
var htmlRoot = '.';
26+
var parserOutputFile = 'web/ng_parser_gen.dart';
27+
var parserHeaderFile = 'lib/parser_gen_header.dart';
28+
var parserFooterFile = ''; // we don't need anything in the footer, for now.
29+
30+
_runNgGenerator(entryPointDartFile, htmlRoot, parserHeaderFile,
31+
parserFooterFile, parserOutputFile, packageRoots);
32+
}
33+
34+
_runDiGenerator(dartSdkPath, entryPointDartFile, injectablesAnnotations,
35+
outputFile, packageRoots) {
36+
di_generator.main([
37+
dartSdkPath,
38+
entryPointDartFile,
39+
injectablesAnnotations,
40+
outputFile,
41+
packageRoots
42+
]);
43+
}
44+
45+
_runNgGenerator(entryPointDartFile, htmlRoot, parserHeaderFile, parserFooterFile, parserOutputFile, packageRoots) {
46+
ng_generator.main([
47+
entryPointDartFile,
48+
htmlRoot,
49+
parserHeaderFile,
50+
parserFooterFile,
51+
parserOutputFile,
52+
packageRoots
53+
]);
54+
}

Chapter_07/lib/injectable.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library injectable;
2+
3+
/**
4+
* An annotation specifying that the annotated class will be instantiated by
5+
* di Injector and type factory code generator should include it in its output.
6+
*/
7+
class InjectableService {
8+
const InjectableService();
9+
}

Chapter_07/lib/my_component.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
library my_component;
2+
3+
import 'package:angular/angular.dart';
4+
5+
import 'service.dart';
6+
7+
@NgComponent(
8+
selector: 'my-component',
9+
templateUrl: 'packages/angular_dart_demo/my_component.html',
10+
publishAs: 'ctrl'
11+
)
12+
class MyComponent {
13+
@NgAttr('default-name')
14+
String name;
15+
}

Chapter_07/lib/my_component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Hello, {{ctrl.name}}!</h1>
2+
<input type="text" ng-model="ctrl.name">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library parser_gen;
2+
3+
import 'package:angular/angular.dart';
4+
5+
typedef Function FilterLookup(String filterName);

Chapter_07/lib/service.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library name_service;
2+
3+
import 'injectable.dart';
4+
5+
@InjectableService()
6+
class NameService {
7+
8+
String formatName(String name) =>
9+
name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
10+
}

Chapter_07/pubspec.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: angular_dart_demo
2+
version: 0.0.1
3+
dependencies:
4+
angular: any
5+
browser: any
6+
js: any
7+
dev_dependencies:
8+
unittest: any

Chapter_07/web/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html ng-app>
3+
<head>
4+
<title>Chapter Seven - Hello World in Production</title>
5+
<link rel="stylesheet" href="style.css">
6+
</head>
7+
<body ng-cloak>
8+
<my-component default-name="World"></my-component>
9+
10+
<script type="application/dart" src="main.dart"></script>
11+
<script type="text/javascript" src="packages/browser/dart.js"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)