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

Commit fecf215

Browse files
authored
Sync recent updates to gallery generator and examples (#93)
1 parent 63214f8 commit fecf215

File tree

118 files changed

+746
-774
lines changed

Some content is hidden

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

118 files changed

+746
-774
lines changed

angular_gallery/lib/builder/gallery_app_builder.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GalleryWebBuilder extends Builder {
2424

2525
Future _generateIndexHtml(BuildStep buildStep) async {
2626
final mustacheContext = {'galleryTitle': _galleryTitle};
27-
final newAssetId = new AssetId(buildStep.inputId.package, 'web/index.html');
27+
final newAssetId = AssetId(buildStep.inputId.package, 'web/index.html');
2828
await writeAsset(buildStep, 'lib/builder/template/index.html.mustache',
2929
mustacheContext, newAssetId);
3030
}
@@ -34,13 +34,13 @@ class GalleryWebBuilder extends Builder {
3434
'galleryImportUri':
3535
'package:${buildStep.inputId.package}/gallery/gallery.template.dart'
3636
};
37-
final newAssetId = new AssetId(buildStep.inputId.package, 'web/main.dart');
37+
final newAssetId = AssetId(buildStep.inputId.package, 'web/main.dart');
3838
await writeAsset(buildStep, 'lib/builder/template/main.dart.mustache',
3939
mustacheContext, newAssetId);
4040
}
4141

4242
Future _generateStyleScss(BuildStep buildStep) async {
43-
final newAssetId = new AssetId(buildStep.inputId.package, 'web/style.scss');
43+
final newAssetId = AssetId(buildStep.inputId.package, 'web/style.scss');
4444
await writeAsset(
4545
buildStep, 'lib/builder/template/style.scss.mustache', {}, newAssetId);
4646
}

angular_gallery/lib/builder/gallery_lib_builder.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GalleryLibBuilder extends Builder {
4242
Future _generateGalleryHtml(BuildStep buildStep) async {
4343
final mustacheContext = {'galleryTitle': _galleryTitle};
4444
final newAssetId =
45-
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.html');
45+
AssetId(buildStep.inputId.package, 'lib/gallery/gallery.html');
4646
await writeAsset(buildStep, 'lib/builder/template/gallery.html.mustache',
4747
mustacheContext, newAssetId);
4848
}
@@ -55,14 +55,14 @@ class GalleryLibBuilder extends Builder {
5555
};
5656

5757
final newAssetId =
58-
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.dart');
58+
AssetId(buildStep.inputId.package, 'lib/gallery/gallery.dart');
5959
await writeAsset(buildStep, 'lib/builder/template/gallery.dart.mustache',
6060
mustacheContext, newAssetId);
6161
}
6262

6363
Future _generateGalleryScss(BuildStep buildStep) async {
6464
final newAssetId =
65-
new AssetId(buildStep.inputId.package, 'lib/gallery/gallery.scss');
65+
AssetId(buildStep.inputId.package, 'lib/gallery/gallery.scss');
6666
await writeAsset(buildStep, 'lib/builder/template/gallery.scss.mustache',
6767
{}, newAssetId);
6868
}
@@ -73,7 +73,7 @@ class GalleryLibBuilder extends Builder {
7373
'examples': examples,
7474
};
7575

76-
final newAssetId = new AssetId(
76+
final newAssetId = AssetId(
7777
buildStep.inputId.package, 'lib/gallery/gallery_route_library.dart');
7878
await writeAsset(
7979
buildStep,
@@ -84,18 +84,18 @@ class GalleryLibBuilder extends Builder {
8484

8585
/// Reads gallery_section_summary.json files from all `_examplePackages`.
8686
Future<List<Example>> loadSummaries(BuildStep buildStep) async {
87-
final examples = new List<Example>();
87+
final examples = List<Example>();
8888

8989
for (var package in _examplePackages) {
9090
final gallerySectionSummaryId =
91-
new AssetId(package, 'lib/gallery_section_summary.json');
91+
AssetId(package, 'lib/gallery_section_summary.json');
9292
if (!await buildStep.canRead(gallerySectionSummaryId)) continue;
9393

9494
final summaryContents =
9595
await buildStep.readAsString(gallerySectionSummaryId);
9696
final summaries = (jsonDecode(summaryContents) as Iterable)
9797
.map((m) => (m as Map).cast<String, dynamic>());
98-
examples.addAll(summaries.map((summary) => new Example(
98+
examples.addAll(summaries.map((summary) => Example(
9999
summary['displayName'],
100100
summary['dartImport'],
101101
summary['componentClass'],
@@ -118,7 +118,7 @@ class Example {
118118
this.relatedComponents);
119119

120120
String get name => strings
121-
.underscore(displayName.replaceAll(new RegExp(r'[^a-zA-Z0-9 _-]'), ''));
121+
.underscore(displayName.replaceAll(RegExp(r'[^a-zA-Z0-9 _-]'), ''));
122122

123123
String get linkName => strings.capitalizeFirstLetter(name);
124124

angular_gallery/lib/builders.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import 'package:angular_gallery/builder/gallery_app_builder.dart';
77
import 'package:angular_gallery/builder/gallery_lib_builder.dart';
88

99
/// Builders used to generate files in the gallery app target.
10-
Builder galleryAppBuilder(BuilderOptions options) => new MultiplexingBuilder([
11-
new GalleryWebBuilder(
12-
options.config['galleryTitle'] ?? 'Example Gallery'),
13-
new HomeDartBuilder(),
10+
Builder galleryAppBuilder(BuilderOptions options) => MultiplexingBuilder([
11+
GalleryWebBuilder(options.config['galleryTitle'] ?? 'Example Gallery'),
12+
HomeDartBuilder(),
1413
]);
1514

1615
/// Builder used to generate files in the gallery library target.
17-
Builder galleryLibBuilder(BuilderOptions options) => new GalleryLibBuilder(
16+
Builder galleryLibBuilder(BuilderOptions options) => GalleryLibBuilder(
1817
options.config['galleryTitle'] ?? 'Example Gallery',
1918
options.config['styleUrls'].cast<String>(),
2019
(options.config['examples'] as String).split(','),

angular_gallery/lib/src/template_util.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import 'package:mustache/mustache.dart';
1414
/// in package:ads.acx2.demo.
1515
Future writeAsset(BuildStep buildStep, String templatePath,
1616
Map<String, dynamic> mustacheContext, AssetId newAssetId) async {
17-
final templateId = new AssetId('angular_gallery', templatePath);
18-
final mustacheTemplate =
19-
new Template(await buildStep.readAsString(templateId));
17+
final templateId = AssetId('angular_gallery', templatePath);
18+
final mustacheTemplate = Template(await buildStep.readAsString(templateId));
2019
buildStep.writeAsString(
2120
newAssetId, mustacheTemplate.renderString(mustacheContext));
2221
}

angular_gallery/pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ author: Dart Team <[email protected]>
33
environment:
44
sdk: '>=2.0.0-dev.64.2 <3.0.0'
55
dependencies:
6-
angular: ^5.0.0-beta+1
7-
angular_components: 0.9.0-beta+1
8-
angular_forms: ^2.0.0-beta+1
9-
angular_router: 2.0.0-alpha+16
6+
angular: ^5.0.0-beta+2
7+
angular_components: 0.9.0-beta+2
8+
angular_forms: ^2.0.0-beta+2
9+
angular_router: 2.0.0-alpha+17
1010
build: '>=0.11.1 <0.13.0'
1111
build_config: '>=0.2.6 <0.4.0'
1212
mustache: ^1.0.0

angular_gallery_section/lib/builder.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ import 'package:angular_gallery_section/builder/gallery_section_summary_builder.
1212
/// @GallerySectionConfig to be read by the other builders that might not
1313
/// have access to a resolver.
1414
Builder galleryInfoBuilder(BuilderOptions options) =>
15-
new GalleryInfoBuilder(options.config['staticImageServer']);
15+
GalleryInfoBuilder(options.config['staticImageServer']);
1616

1717
/// Builder used to generate the API page for the gallery from a
1818
/// @GallerySectionConfig-annotated class.
19-
Builder componentApiBuilder(BuilderOptions options) =>
20-
new ComponentApiBuilder();
19+
Builder componentApiBuilder(BuilderOptions options) => ComponentApiBuilder();
2120

2221
/// Builder used to generate the page for a stand alone example app and a
2322
/// summary used in building the gallery from a @GallerySectionConfig-annotated
2423
/// class.
25-
Builder gallerySectionBuilder(BuilderOptions options) =>
26-
new MultiplexingBuilder([
27-
new GallerySectionBuilder(),
28-
new GallerySectionSummaryBuilder(),
24+
Builder gallerySectionBuilder(BuilderOptions options) => MultiplexingBuilder([
25+
GallerySectionBuilder(),
26+
GallerySectionSummaryBuilder(),
2927
]);

angular_gallery_section/lib/builder/component_api_builder.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,29 @@ class ComponentApiBuilder extends Builder {
2929
Future build(BuildStep buildStep) async {
3030
final inputId = buildStep.inputId;
3131
final infoList = (jsonDecode(await buildStep.readAsString(inputId)) as List)
32-
.map((info) => new ResolvedConfig.fromJson(info));
32+
.map((info) => ResolvedConfig.fromJson(info));
3333

3434
final mustacheContext = await _mustacheContext(infoList);
35-
final templateId = new AssetId('angular_gallery_section',
35+
final templateId = AssetId('angular_gallery_section',
3636
'lib/builder/template/component.api.dart.mustache');
37-
final mustacheTemplate = new Template(
38-
await buildStep.readAsString(templateId),
37+
final mustacheTemplate = Template(await buildStep.readAsString(templateId),
3938
htmlEscapeValues: false);
4039

41-
final newAssetId = new AssetId(inputId.package,
40+
final newAssetId = AssetId(inputId.package,
4241
inputId.path.replaceFirst('.gallery_info.json', '.api.dart'));
4342
buildStep.writeAsString(
4443
newAssetId, mustacheTemplate.renderString(mustacheContext));
4544
}
4645

4746
@override
4847
Map<String, List<String>> get buildExtensions => const {
49-
'.gallery_info.json': const ['.api.dart']
48+
'.gallery_info.json': ['.api.dart']
5049
};
5150

5251
/// Returns a context with the useful values from the [configs].
5352
Future<Map<String, dynamic>> _mustacheContext(
5453
Iterable<ResolvedConfig> configs) async {
55-
final dedupedImports = new Set<String>();
54+
final dedupedImports = Set<String>();
5655
final context = <String, dynamic>{'apiComponents': []};
5756
for (final config in configs) {
5857
// If multiple components are defined in a demo file, we would end up with

angular_gallery_section/lib/builder/gallery_info_builder.dart

+13-14
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GalleryInfoBuilder extends Builder {
4646

4747
@override
4848
Map<String, List<String>> get buildExtensions => const {
49-
'.dart': const ['.gallery_info.json'],
49+
'.dart': ['.gallery_info.json'],
5050
};
5151

5252
/// Resolve the docs and demos within all [configs].
@@ -56,7 +56,7 @@ class GalleryInfoBuilder extends Builder {
5656
Future<Iterable<ResolvedConfig>> _resolveConfigs(Iterable<ConfigInfo> configs,
5757
LibraryElement rootLibrary, AssetReader assetReader) async =>
5858
Future.wait(configs.map((config) async {
59-
final resolved = new ResolvedConfig()
59+
final resolved = ResolvedConfig()
6060
..displayName = config.displayName
6161
..benchmarks = config.benchmarks
6262
..benchmarkPrefix = config.benchmarkPrefix
@@ -68,8 +68,7 @@ class GalleryInfoBuilder extends Builder {
6868
Future.wait(_resolveDocs(config.docs, rootLibrary, assetReader)).then(
6969
(docs) =>
7070
resolved.docs = docs.where((doc) => doc != null).toList()),
71-
Future
72-
.wait(_resolveDemos(
71+
Future.wait(_resolveDemos(
7372
config.demoClassNames, rootLibrary, assetReader))
7473
.then((demos) => resolved.demos =
7574
demos.where((demo) => demo != null).toList()),
@@ -108,7 +107,7 @@ class GalleryInfoBuilder extends Builder {
108107
/// Read the [markdownAsset] with [assetReader] and render as HTML.
109108
Future<DocInfo> _readMarkdownAsset(
110109
String markdownAsset, AssetReader assetReader) async {
111-
final assetId = new AssetId.resolve(markdownAsset);
110+
final assetId = AssetId.resolve(markdownAsset);
112111
if (extension(assetId.path) != '.md') {
113112
log.warning('Generator only supports .md files as supplementary docs. '
114113
'Can not insert $assetId into gallery.');
@@ -124,7 +123,7 @@ class GalleryInfoBuilder extends Builder {
124123
// Convert markdown to html and insert static server for images.
125124
final htmlContent = _replaceImgTags(g3docMarkdownToHtml(content));
126125

127-
return new DocInfo()
126+
return DocInfo()
128127
..name = basenameWithoutExtension(assetId.path)
129128
..path = path_utils.assetToPath(assetId.toString())
130129
..comment = htmlContent;
@@ -137,7 +136,7 @@ class GalleryInfoBuilder extends Builder {
137136
/// [assetReader].
138137
Future<DocInfo> _resolveDocFromClass(String identifier,
139138
LibraryElement library, AssetReader assetReader) async {
140-
final libraryId = new AssetId.resolve(library.source.uri.toString());
139+
final libraryId = AssetId.resolve(library.source.uri.toString());
141140
final docClass = library.getType(identifier);
142141
DocInfo docs;
143142

@@ -160,15 +159,15 @@ class GalleryInfoBuilder extends Builder {
160159
// classElement.documentationComment, classElement.metadata, etc are not
161160
// populated in the resolved element model available here.
162161
var libraryId =
163-
new AssetId.resolve(classElement.library.source.uri.toString());
162+
AssetId.resolve(classElement.library.source.uri.toString());
164163
docs =
165164
await extractDocumentation(classElement.name, libraryId, assetReader);
166165

167166
if (docs == null) {
168167
// The super class must be defined in the library as a part file.
169168
for (var part in classElement.library.parts) {
170169
if (part.getType(classElement.name) != null) {
171-
libraryId = new AssetId.resolve(part.source.uri.toString());
170+
libraryId = AssetId.resolve(part.source.uri.toString());
172171
docs = await extractDocumentation(
173172
classElement.name, libraryId, assetReader);
174173
}
@@ -235,7 +234,7 @@ class GalleryInfoBuilder extends Builder {
235234

236235
/// Replace web server in `<img>` tags with the [_staticImageServer].
237236
String _replaceImgTags(String content) => content.replaceAllMapped(
238-
new RegExp(r'<img alt="(.*)" src="(\S*g3doc\S+)" \/>'),
237+
RegExp(r'<img alt="(.*)" src="(\S*g3doc\S+)" \/>'),
239238
(Match m) => '<img alt="${m[1]}" src="$_staticImageServer${m[2]}" />');
240239

241240
/// Resolve all [demoClassNames] into [_DemoInfo]s.
@@ -263,15 +262,15 @@ class GalleryInfoBuilder extends Builder {
263262
/// [assetReader].
264263
Future<DemoInfo> _resolveDemo(String demoClassName, LibraryElement library,
265264
AssetReader assetReader) async {
266-
final libraryId = new AssetId.resolve(library.source.uri.toString());
265+
final libraryId = AssetId.resolve(library.source.uri.toString());
267266
final extractedDemo =
268267
await extractDocumentation(demoClassName, libraryId, assetReader);
269268

270269
if (extractedDemo == null) {
271270
log.warning('Failed to extract demo information from: $demoClassName.');
272271
return null;
273272
}
274-
return new DemoInfo()
273+
return DemoInfo()
275274
..type = extractedDemo.name
276275
..name = extractedDemo.name
277276
..selector = extractedDemo.selector
@@ -284,8 +283,8 @@ class GalleryInfoBuilder extends Builder {
284283
/// Searches imports with a breadth-first search, as that should find
285284
/// [identifier] faster than a depth-first search.
286285
LibraryElement _searchFor(String identifier, LibraryElement rootLibrary) {
287-
final visited = new Set<LibraryElement>();
288-
final toVisit = new Queue<LibraryElement>();
286+
final visited = Set<LibraryElement>();
287+
final toVisit = Queue<LibraryElement>();
289288

290289
toVisit.add(rootLibrary);
291290

angular_gallery_section/lib/builder/gallery_section_builder.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ class GallerySectionBuilder extends Builder {
2121
Future build(BuildStep buildStep) async {
2222
final inputId = buildStep.inputId;
2323
final infoAssets =
24-
await buildStep.findAssets(new Glob('**/*.gallery_info.json')).toList();
24+
await buildStep.findAssets(Glob('**/*.gallery_info.json')).toList();
2525
if (infoAssets.isEmpty) return;
2626

27-
final mergedImports = new Set<String>();
27+
final mergedImports = Set<String>();
2828
final mergedDemos = <String, String>{};
2929
final apis = [];
3030

3131
for (final assetId in infoAssets) {
3232
final infoList =
3333
(jsonDecode(await buildStep.readAsString(assetId)) as List)
34-
.map((info) => new ResolvedConfig.fromJson(info));
34+
.map((info) => ResolvedConfig.fromJson(info));
3535

3636
// There is an API page generated for every .gallery_info.json file.
3737
final api = <String, dynamic>{
@@ -63,13 +63,12 @@ class GallerySectionBuilder extends Builder {
6363
'apis': apis,
6464
};
6565

66-
final templateId = new AssetId('angular_gallery_section',
66+
final templateId = AssetId('angular_gallery_section',
6767
'lib/builder/template/gallery_section.dart.mustache');
68-
final mustacheTemplate = new Template(
69-
await buildStep.readAsString(templateId),
68+
final mustacheTemplate = Template(await buildStep.readAsString(templateId),
7069
htmlEscapeValues: false);
7170

72-
final newAssetId = new AssetId(inputId.package, 'lib/gallery_section.dart');
71+
final newAssetId = AssetId(inputId.package, 'lib/gallery_section.dart');
7372
buildStep.writeAsString(
7473
newAssetId, mustacheTemplate.renderString(mustacheContext));
7574
}

angular_gallery_section/lib/builder/gallery_section_summary_builder.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class GallerySectionSummaryBuilder extends Builder {
1919
@override
2020
Future build(BuildStep buildStep) async {
2121
final inputId = buildStep.inputId;
22-
final summaries = new List<Map<String, dynamic>>();
22+
final summaries = List<Map<String, dynamic>>();
2323

2424
// Extract details from @GallerySectionConfig annotations.
2525
await for (var assetId
26-
in buildStep.findAssets(new Glob('**/*.gallery_info.json'))) {
26+
in buildStep.findAssets(Glob('**/*.gallery_info.json'))) {
2727
final infoList =
2828
(jsonDecode(await buildStep.readAsString(assetId)) as List)
29-
.map((info) => new ResolvedConfig.fromJson(info));
29+
.map((info) => ResolvedConfig.fromJson(info));
3030

3131
if (infoList.isEmpty) continue;
3232

@@ -39,7 +39,7 @@ class GallerySectionSummaryBuilder extends Builder {
3939
}
4040

4141
final newAssetId =
42-
new AssetId(inputId.package, 'lib/gallery_section_summary.json');
42+
AssetId(inputId.package, 'lib/gallery_section_summary.json');
4343
buildStep.writeAsString(newAssetId, jsonEncode(summaries));
4444
}
4545

angular_gallery_section/lib/components/content/delayed_content.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import 'package:angular_components/material_progress/material_progress.dart';
2222
@Component(
2323
selector: 'delayed-content',
2424
templateUrl: 'delayed_content.html',
25-
styleUrls: const ['delayed_content.scss.css'],
26-
directives: const [MaterialProgressComponent, NgIf],
25+
styleUrls: ['delayed_content.scss.css'],
26+
directives: [MaterialProgressComponent, NgIf],
2727
// TODO(google): Change preserveWhitespace to false to improve codesize.
2828
preserveWhitespace: true,
2929
)
@@ -37,7 +37,7 @@ class DelayedContentComponent implements OnInit {
3737
void ngOnInit() {
3838
if (delay != null) {
3939
resolved = false;
40-
new Timer(new Duration(seconds: delay), _resolve);
40+
Timer(Duration(seconds: delay), _resolve);
4141
} else {
4242
resolved = true;
4343
}

0 commit comments

Comments
 (0)