Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Commit 89db5d1

Browse files
authored
New Gallery and examples and code generators
Initial export of the code generators and examples used internally to generate the example gallery for angular_components. Travis is disabled for now until the mono-repo has organization has settled.
1 parent 798518b commit 89db5d1

File tree

262 files changed

+9726
-4205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+9726
-4205
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Files and directories created by pub
2+
.dart_tool
23
.packages
34
.pub/
45
build/
File renamed without changes.

README.md

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
This is a basic gallery of the various AngularDart Components.
1+
These packages provide code generation for the AngularDart Components gallery.
22

33
* **[See the gallery](https://dart-lang.github.io/angular_components_example/)**
4-
* [See the code](https://github.com/dart-lang/angular_components_example/blob/master/lib/app_component.html)
54
* [Use the package](https://pub.dartlang.org/packages/angular_components)
65
* [Browse the API](https://www.dartdocs.org/documentation/angular_components/latest)
76

8-
For a walk-through of how to *use* these components, see
9-
[Code Lab: AngularDart Components](https://webdev.dartlang.org/codelabs/angular2_components).
7+
This is repo now contains the initial release of two new experimental code
8+
generating packages.
9+
10+
## `angular_gallery`
11+
12+
A package that generates a the gallery from each page that is generated by the
13+
`angular_gallery_section` package.
14+
15+
## `angular_gallery_section`
16+
17+
A package that generates a gallery page containing documentation and examples
18+
from a `@GallerySectionConfig` annotation.
19+
20+
## `example`
21+
Contains individual examples for all the components as well as the base package
22+
of the entire gallery `example/angular_components_example`.
1023

1124
## Development
1225

@@ -16,7 +29,8 @@ code generation through package [build]. This package must be built with package
1629

1730
### Build
1831

19-
Build the package to the given directory.
32+
Build the entire gallery from the `example/angular_components_example`
33+
directory.
2034

2135
```
2236
pub run build_runner build --output <output directory>
@@ -27,16 +41,25 @@ pub run build_runner build --output <output directory>
2741
Run a local development server with a file watcher and incremental rebuilds:
2842

2943
```
30-
pub run build_runner serve
44+
pub run build_runner serve web
3145
```
3246

33-
Both of the build and serve commands can use `--config release` to build with
34-
dart2js instead of the the default dartdevc.
47+
__Known Issues:__
3548

36-
[build_runner]: https://pub.dartlang.org/packages/build_runner
37-
[build]: https://pub.dartlang.org/packages/build
49+
When building and viewing the gallery these issues are expected at this time:
3850

39-
### Test
51+
* Build Warnings:
4052

41-
Run `dart tool/sanity_check.dart` to execute a simple Selenium test of the
42-
gallery.
53+
`Generator does not support multiple @GallerySectionConfig annotations in a
54+
single lib directory.`
55+
56+
* Runtime Warning:
57+
58+
`SEVERE: OverlayService must be a singleton: Check that there is no nested
59+
overlayBindings or popupBindings`
60+
61+
* Loading deferred libraries is not yet supported when _dart2js_ is configured
62+
as the _build_web_compiler_.
63+
64+
[build_runner]: https://pub.dartlang.org/packages/build_runner
65+
[build]: https://pub.dartlang.org/packages/build

angular_gallery/build.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
targets:
2+
$default:
3+
builders:
4+
angular_components|scss_builder:
5+
enabled: True
6+
angular|angular:
7+
generate_for:
8+
exclude: ["lib/**"]
9+
10+
builders:
11+
angular_gallery:
12+
target: ":angular_gallery"
13+
import: "package:angular_gallery/builders.dart"
14+
builder_factories: [galleryAppBuilder, galleryLibBuilder]
15+
build_extensions: {
16+
".html": [".dart"],
17+
"$web$": ["index.html", "main.dart", "style.scss"]}
18+
auto_apply: dependents
19+
runs_before: ["angular|angular", "angular_components|scss_builder"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:build/build.dart';
8+
9+
import '../src/template_util.dart';
10+
11+
/// Generates web/index.html, web/main.dart, and web/style.scss for the ACX
12+
/// component gallery.
13+
class GalleryWebBuilder extends Builder {
14+
final String _galleryTitle;
15+
16+
GalleryWebBuilder(this._galleryTitle);
17+
18+
@override
19+
Future build(BuildStep buildStep) async {
20+
await _generateIndexHtml(buildStep);
21+
await _generateMainDart(buildStep);
22+
await _generateStyleScss(buildStep);
23+
}
24+
25+
Future _generateIndexHtml(BuildStep buildStep) async {
26+
final mustacheContext = {'galleryTitle': _galleryTitle};
27+
final newAssetId = new AssetId(buildStep.inputId.package, 'web/index.html');
28+
await writeAsset(buildStep, 'lib/builder/template/index.html.mustache',
29+
mustacheContext, newAssetId);
30+
}
31+
32+
Future _generateMainDart(BuildStep buildStep) async {
33+
final mustacheContext = {
34+
'galleryImportUri':
35+
'package:${buildStep.inputId.package}/gallery/gallery.dart'
36+
};
37+
final newAssetId = new AssetId(buildStep.inputId.package, 'web/main.dart');
38+
await writeAsset(buildStep, 'lib/builder/template/main.dart.mustache',
39+
mustacheContext, newAssetId);
40+
}
41+
42+
Future _generateStyleScss(BuildStep buildStep) async {
43+
final newAssetId = new AssetId(buildStep.inputId.package, 'web/style.scss');
44+
await writeAsset(
45+
buildStep, 'lib/builder/template/style.scss.mustache', {}, newAssetId);
46+
}
47+
48+
@override
49+
Map<String, List<String>> get buildExtensions => {
50+
r'$web$': ['index.html', 'main.dart', 'style.scss']
51+
};
52+
}
53+
54+
/// Generates a home.dart component for the html template.
55+
class HomeDartBuilder extends Builder {
56+
@override
57+
Future build(BuildStep buildStep) async {
58+
final inputId = buildStep.inputId;
59+
final mustacheContext = {
60+
'htmlTemplateUrl':
61+
'package:${inputId.package}${inputId.path.replaceFirst('lib', '')}'
62+
};
63+
await writeAsset(buildStep, 'lib/builder/template/home.dart.mustache',
64+
mustacheContext, inputId.changeExtension('.dart'));
65+
}
66+
67+
@override
68+
Map<String, List<String>> get buildExtensions => {
69+
'.html': ['.dart']
70+
};
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:convert';
7+
8+
import 'package:build/build.dart';
9+
import 'package:angular_components/utils/strings/string_utils.dart' as strings;
10+
11+
import '../src/template_util.dart';
12+
13+
/// Generates lib/gallery/gallery.dart, lib/gallery/gallery.html,
14+
/// lib/gallery/gallery.scss, and lib/gallery/gallery_route_library.dart for the
15+
/// ACX component gallery.
16+
class GalleryLibBuilder extends Builder {
17+
final String _galleryTitle;
18+
final List<String> _styleUrls;
19+
final List<String> _examplePackages;
20+
21+
GalleryLibBuilder(this._galleryTitle, this._styleUrls, this._examplePackages);
22+
23+
@override
24+
Future build(BuildStep buildStep) async {
25+
final examples = await loadSummaries(buildStep);
26+
await _generateGalleryDart(buildStep, examples);
27+
await _generateGalleryHtml(buildStep);
28+
await _generateGalleryScss(buildStep);
29+
await _generateGalleryRouteLibraryDart(buildStep, examples);
30+
}
31+
32+
@override
33+
Map<String, List<String>> get buildExtensions => {
34+
r'$lib$': [
35+
'gallery/gallery.dart',
36+
'gallery/gallery.html',
37+
'gallery/gallery.scss',
38+
'gallery/gallery_route_library.dart'
39+
]
40+
};
41+
42+
Future _generateGalleryHtml(BuildStep buildStep) async {
43+
final mustacheContext = {'galleryTitle': _galleryTitle};
44+
final newAssetId =
45+
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.html');
46+
await writeAsset(buildStep, 'lib/builder/template/gallery.html.mustache',
47+
mustacheContext, newAssetId);
48+
}
49+
50+
Future _generateGalleryDart(
51+
BuildStep buildStep, List<Example> examples) async {
52+
final mustacheContext = {
53+
'styleUrls': _styleUrls,
54+
'examples': examples,
55+
};
56+
57+
final newAssetId =
58+
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.dart');
59+
await writeAsset(buildStep, 'lib/builder/template/gallery.dart.mustache',
60+
mustacheContext, newAssetId);
61+
}
62+
63+
Future _generateGalleryScss(BuildStep buildStep) async {
64+
final newAssetId =
65+
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.scss');
66+
await writeAsset(buildStep, 'lib/builder/template/gallery.scss.mustache',
67+
{}, newAssetId);
68+
}
69+
70+
Future _generateGalleryRouteLibraryDart(
71+
BuildStep buildStep, List<Example> examples) async {
72+
final mustacheContext = {
73+
'examples': examples,
74+
};
75+
76+
final newAssetId = new AssetId(
77+
buildStep.inputId.package, 'lib/gallery/gallery_route_library.dart');
78+
await writeAsset(
79+
buildStep,
80+
'lib/builder/template/gallery_route_library.dart.mustache',
81+
mustacheContext,
82+
newAssetId);
83+
}
84+
85+
/// Reads gallery_section_summary.json files from all `_examplePackages`.
86+
Future<List<Example>> loadSummaries(BuildStep buildStep) async {
87+
final examples = new List<Example>();
88+
89+
for (var package in _examplePackages) {
90+
final gallerySectionSummaryId =
91+
new AssetId(package, 'lib/gallery_section_summary.json');
92+
if (!await buildStep.canRead(gallerySectionSummaryId)) continue;
93+
94+
final summaries =
95+
JSON.decode(await buildStep.readAsString(gallerySectionSummaryId));
96+
examples.addAll(summaries.map((summary) => new Example(
97+
summary['displayName'],
98+
summary['dartImport'],
99+
summary['componentClass'],
100+
summary['docs'])));
101+
}
102+
103+
examples
104+
.sort((Example a, Example b) => a.displayName.compareTo(b.displayName));
105+
return examples;
106+
}
107+
}
108+
109+
class Example {
110+
final String displayName;
111+
final String dartImport;
112+
final String component;
113+
final List<String> relatedComponents;
114+
115+
Example(this.displayName, this.dartImport, this.component,
116+
this.relatedComponents);
117+
118+
String get name => strings
119+
.underscore(displayName.replaceAll(new RegExp(r'[^a-zA-Z0-9 _-]'), ''));
120+
121+
String get linkName => strings.capitalizeFirstLetter(name);
122+
123+
String get loader => 'load${name}Example';
124+
}

0 commit comments

Comments
 (0)