Fixes several bugs in samples, quotes HTML properly, and pre-compiles snippet tool. (#24020)
When converting all of the samples to use the snippet tool, I encountered some bugs/shortcomings: 1. The document production took 90 minutes, since the snippet tool was being invoked from the command line each time. I fixed this by snapshotting the executable before running, so it's down to 7 minutes. 2. The sample code was not being properly escaped by the snippet tool, so generics were causing issues in the HTML output. It is now quoted. 3. Code examples that used languages other than Dart were not supported. Anything that highlight.js was compiled for dartdoc with is now supported. 4. The comment color for highlight.js was light grey on white, which was pretty unreadable. It's now dark green and bold.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:platform/platform.dart' show FakePlatform;
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
@@ -10,36 +10,32 @@ import 'package:snippets/configuration.dart';
|
||||
|
||||
void main() {
|
||||
group('Configuration', () {
|
||||
FakePlatform fakePlatform;
|
||||
Configuration config;
|
||||
|
||||
setUp(() {
|
||||
fakePlatform = FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
script: Uri.parse('file:///flutter/dev/snippets/lib/configuration_test.dart'));
|
||||
config = Configuration(platform: fakePlatform);
|
||||
config = Configuration(flutterRoot: Directory('/flutter sdk'));
|
||||
});
|
||||
test('config directory is correct', () async {
|
||||
expect(config.getConfigDirectory('foo').path,
|
||||
matches(RegExp(r'[/\\]flutter[/\\]dev[/\\]snippets[/\\]config[/\\]foo')));
|
||||
expect(config.configDirectory.path,
|
||||
matches(RegExp(r'[/\\]flutter sdk[/\\]dev[/\\]snippets[/\\]config')));
|
||||
});
|
||||
test('output directory is correct', () async {
|
||||
expect(config.outputDirectory.path,
|
||||
matches(RegExp(r'[/\\]flutter[/\\]dev[/\\]docs[/\\]doc[/\\]snippets')));
|
||||
matches(RegExp(r'[/\\]flutter sdk[/\\]dev[/\\]docs[/\\]doc[/\\]snippets')));
|
||||
});
|
||||
test('skeleton directory is correct', () async {
|
||||
expect(config.skeletonsDirectory.path,
|
||||
matches(RegExp(r'[/\\]flutter[/\\]dev[/\\]snippets[/\\]config[/\\]skeletons')));
|
||||
matches(RegExp(r'[/\\]flutter sdk[/\\]dev[/\\]snippets[/\\]config[/\\]skeletons')));
|
||||
});
|
||||
test('templates directory is correct', () async {
|
||||
expect(config.templatesDirectory.path,
|
||||
matches(RegExp(r'[/\\]flutter[/\\]dev[/\\]snippets[/\\]config[/\\]templates')));
|
||||
matches(RegExp(r'[/\\]flutter sdk[/\\]dev[/\\]snippets[/\\]config[/\\]templates')));
|
||||
});
|
||||
test('html skeleton file is correct', () async {
|
||||
expect(
|
||||
config.getHtmlSkeletonFile(SnippetType.application).path,
|
||||
matches(RegExp(
|
||||
r'[/\\]flutter[/\\]dev[/\\]snippets[/\\]config[/\\]skeletons[/\\]application.html')));
|
||||
r'[/\\]flutter sdk[/\\]dev[/\\]snippets[/\\]config[/\\]skeletons[/\\]application.html')));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,16 +5,13 @@
|
||||
import 'dart:io' hide Platform;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'package:platform/platform.dart' show FakePlatform;
|
||||
|
||||
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
import 'package:snippets/configuration.dart';
|
||||
import 'package:snippets/snippets.dart';
|
||||
|
||||
void main() {
|
||||
group('Generator', () {
|
||||
FakePlatform fakePlatform;
|
||||
Configuration configuration;
|
||||
SnippetGenerator generator;
|
||||
Directory tmpDir;
|
||||
@@ -22,10 +19,8 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
tmpDir = Directory.systemTemp.createTempSync('snippets_test');
|
||||
fakePlatform = FakePlatform(
|
||||
script: Uri.file(path.join(
|
||||
tmpDir.absolute.path, 'flutter', 'dev', 'snippets', 'lib', 'snippets_test.dart')));
|
||||
configuration = Configuration(platform: fakePlatform);
|
||||
configuration = Configuration(flutterRoot: Directory(path.join(
|
||||
tmpDir.absolute.path, 'flutter')));
|
||||
configuration.createOutputDirectory();
|
||||
configuration.templatesDirectory.createSync(recursive: true);
|
||||
configuration.skeletonsDirectory.createSync(recursive: true);
|
||||
@@ -67,7 +62,7 @@ A description of the snippet.
|
||||
|
||||
On several lines.
|
||||
|
||||
```dart preamble
|
||||
```my-dart_language my-preamble
|
||||
const String name = 'snippet';
|
||||
```
|
||||
|
||||
@@ -82,13 +77,13 @@ void main() {
|
||||
generator.generate(inputFile, SnippetType.application, template: 'template', id: 'id');
|
||||
expect(html, contains('<div>HTML Bits</div>'));
|
||||
expect(html, contains('<div>More HTML Bits</div>'));
|
||||
expect(html, contains("print('The actual \$name.');"));
|
||||
expect(html, contains('print('The actual \$name.');'));
|
||||
expect(html, contains('A description of the snippet.\n'));
|
||||
expect(
|
||||
html,
|
||||
contains('// A description of the snippet.\n'
|
||||
'//\n'
|
||||
'// On several lines.\n'));
|
||||
contains('// A description of the snippet.\n'
|
||||
'//\n'
|
||||
'// On several lines.\n'));
|
||||
expect(html, contains('void main() {'));
|
||||
});
|
||||
|
||||
@@ -110,7 +105,7 @@ void main() {
|
||||
final String html = generator.generate(inputFile, SnippetType.sample);
|
||||
expect(html, contains('<div>HTML Bits</div>'));
|
||||
expect(html, contains('<div>More HTML Bits</div>'));
|
||||
expect(html, contains("print('The actual \$name.');"));
|
||||
expect(html, contains(' print('The actual \$name.');'));
|
||||
expect(html, contains('A description of the snippet.\n\nOn several lines.\n'));
|
||||
expect(html, contains('main() {'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user