Skip to content

Commit 842093b

Browse files
authored
Fix dartdoc customization issues. (#3890)
1 parent 0b959c1 commit 842093b

File tree

6 files changed

+365
-32
lines changed

6 files changed

+365
-32
lines changed

app/lib/dartdoc/customization.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ class DartdocCustomizer {
164164
final pubPackageText = '$packageName package';
165165
if (breadcrumbs.children.length == 1) {
166166
// we are on the index page
167-
final firstLink = breadcrumbs.querySelector('a');
168-
firstLink.attributes['href'] = pubPackageLink;
169-
firstLink.text = pubPackageText;
167+
final newItem = Element.tag('li');
168+
newItem.append(Element.tag('a')
169+
..attributes['href'] = pubPackageLink
170+
..text = pubPackageText);
171+
breadcrumbs.children.first.replaceWith(newItem);
170172

171173
final docitem = Element.tag('li')
172174
..className = 'self-crumb'

app/lib/dartdoc/dartdoc_runner.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,16 @@ class DartdocJobProcessor extends JobProcessor {
204204
}
205205

206206
if (hasContent) {
207-
await DartdocCustomizer(
208-
job.packageName, job.packageVersion, job.isLatestStable)
209-
.customizeDir(outputDir);
210-
logFileOutput.write('Content customization completed.\n\n');
207+
try {
208+
await DartdocCustomizer(
209+
job.packageName, job.packageVersion, job.isLatestStable)
210+
.customizeDir(outputDir);
211+
logFileOutput.write('Content customization completed.\n\n');
212+
} catch (e, st) {
213+
// Do not block on customization failure.
214+
_logger.severe('Dartdoc customization failed ($job).', e, st);
215+
logFileOutput.write('Content customization failed.\n\n');
216+
}
211217

212218
await _tar(tempDirPath, tarDir, outputDir, logFileOutput);
213219
} else {

app/test/dartdoc/customization_test.dart

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,37 @@ void main() {
4747
golden.split('\n').where((s) => s.isNotEmpty));
4848
}
4949

50-
group('pana 0.10.2', () {
51-
final prevCustomizer = DartdocCustomizer('pana', '0.12.2', false);
52-
final latestCustomizer = DartdocCustomizer('pana', '0.12.2', true);
53-
54-
void expectMatch(String name) {
55-
test(name, () {
56-
final inputName = 'pana_0.12.2_$name.html';
57-
final outputName = 'pana_0.12.2_$name.out.html';
58-
final diffName = 'pana_0.12.2_$name.latest.diff';
59-
final html = File('$goldenDir/$inputName').readAsStringSync();
60-
final prevResult = prevCustomizer.customizeHtml(html) ?? html;
61-
final latestResult = latestCustomizer.customizeHtml(html) ?? html;
62-
expectGoldenFile(prevResult, outputName);
63-
expectGoldenFile(_miniDiff(prevResult, latestResult), diffName);
64-
65-
if (_regenerateGoldens) {
66-
fail('Set `_regenerateGoldens` to `false` to run tests.');
67-
}
68-
});
69-
}
50+
void expectMatch(String package, String version, String name) {
51+
test('Match $package $version $name', () {
52+
final prevCustomizer = DartdocCustomizer(package, version, false);
53+
final latestCustomizer = DartdocCustomizer(package, version, true);
54+
55+
final path = '${package}_${version}_$name';
56+
final inputName = '$path.html';
57+
final outputName = '$path.out.html';
58+
final diffName = '$path.latest.diff';
59+
final html = File('$goldenDir/$inputName').readAsStringSync();
60+
final prevResult = prevCustomizer.customizeHtml(html) ?? html;
61+
final latestResult = latestCustomizer.customizeHtml(html) ?? html;
62+
expectGoldenFile(prevResult, outputName);
63+
expectGoldenFile(_miniDiff(prevResult, latestResult), diffName);
64+
65+
if (_regenerateGoldens) {
66+
fail('Set `_regenerateGoldens` to `false` to run tests.');
67+
}
68+
});
69+
}
70+
71+
group('pana 0.12.2', () {
72+
expectMatch('pana', '0.12.2', 'index');
73+
expectMatch('pana', '0.12.2', 'license_file_class');
74+
expectMatch('pana', '0.12.2', 'license_file_constructor');
75+
expectMatch('pana', '0.12.2', 'license_file_name_field');
76+
expectMatch('pana', '0.12.2', 'pretty_json');
77+
});
7078

71-
expectMatch('index');
72-
expectMatch('license_file_class');
73-
expectMatch('license_file_constructor');
74-
expectMatch('license_file_name_field');
75-
expectMatch('pretty_json');
79+
group('Misc packages', () {
80+
expectMatch('dygraph', '0.1.1', 'index');
7681
});
7782
}
7883

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
7+
<meta name="generator" content="made with love by dartdoc 0.32.1">
8+
<meta name="description" content="dygraph API docs, for the Dart programming language.">
9+
<title>dygraph - Dart API docs</title>
10+
11+
12+
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
13+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
14+
<link rel="stylesheet" href="static-assets/github.css">
15+
<link rel="stylesheet" href="static-assets/styles.css">
16+
<link rel="icon" href="static-assets/favicon.png">
17+
18+
</head>
19+
20+
<body data-base-href=""
21+
data-using-base-href="false">
22+
23+
<div id="overlay-under-drawer"></div>
24+
25+
<header id="title">
26+
<button id="sidenav-left-toggle" type="button">&nbsp;</button>
27+
<ol class="breadcrumbs gt-separated dark hidden-xs">
28+
<li class="self-crumb">dygraph package</li>
29+
</ol>
30+
<div class="self-name">dygraph</div>
31+
<form class="search navbar-right" role="search">
32+
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
33+
</form>
34+
</header>
35+
36+
<main>
37+
38+
<div id="dartdoc-sidebar-left" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
39+
<header id="header-search-sidebar" class="hidden-l">
40+
<form class="search-sidebar" role="search">
41+
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
42+
</form>
43+
</header>
44+
45+
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
46+
<li class="self-crumb">dygraph package</li>
47+
</ol>
48+
49+
<h5 class="hidden-xs"><span class="package-name">dygraph</span> <span class="package-kind">package</span></h5>
50+
<ol>
51+
<li class="section-title">Libraries</li>
52+
<li><a href="dygraph/dygraph-library.html">dygraph</a></li>
53+
</ol>
54+
</div>
55+
56+
<div id="dartdoc-main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
57+
<section class="desc markdown">
58+
<h1 id="dygraph-dart">Dygraph (Dart)</h1>
59+
<p>Dart JS interop for <a href="https://github.com/danvk/dygraphs">Dygraph v2+</a> - fast, flexible open source JavaScript charting library.</p>
60+
<h2 id="usage">Usage</h2>
61+
<ol>
62+
<li>
63+
<p>Register the Dart package in your <code>pubspec.yaml</code>:</p>
64+
<pre class="language-yaml"><code class="language-yaml"> dependencies:
65+
dygraph: ^0.1.0
66+
</code></pre>
67+
</li>
68+
<li>
69+
<p>Load the latest Dygraph source (js and css) in your html layout:</p>
70+
<pre class="language-html"><code class="language-html"> &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.min.css"&gt;
71+
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.min.js"&gt;&lt;/script&gt;
72+
</code></pre>
73+
</li>
74+
<li>
75+
<p>Create a <code>Dygraph</code> instance:</p>
76+
<pre class="language-dart"><code class="language-dart"> import 'dart:html';
77+
78+
import 'package:dygraph/dygraph.dart';
79+
80+
void main() {
81+
final el = document.getElementById('chart_container');
82+
83+
final options = DygraphOptions(
84+
labels: ['Index', 'X', 'Y'],
85+
colors: ['blue', 'red'],
86+
);
87+
88+
final data = [
89+
[1, 10, 100],
90+
[2, 20, 80],
91+
[3, 50, 60],
92+
[4, 70, 80],
93+
];
94+
95+
Dygraph(el, data, options);
96+
}
97+
</code></pre>
98+
</li>
99+
</ol>
100+
<blockquote>
101+
<p><strong>Note 1:</strong> Dart DateTime objects need to be converted to native js dates by using <code>dart:html_common</code> and <code>convertDartToNative_DateTime()</code>.</p>
102+
</blockquote>
103+
<blockquote>
104+
<p><strong>Note 2:</strong> When passing a Dart function as a callback, make sure to wrap it with <code>allowInterop()</code> or <code>allowInteropCaptureThis()</code>.</p>
105+
</blockquote>
106+
<p>Check the <a href="https://pub.dev/documentation/dygraph/latest/">API reference</a> for detailed documentation.</p>
107+
<p>To view the example, run <code>pub global run webdev serve example</code> from the root directory of this project.</p>
108+
</section>
109+
110+
<section class="summary">
111+
<h2>Libraries</h2>
112+
<dl>
113+
<dt id="dygraph">
114+
<span class="name"><a href="dygraph/dygraph-library.html">dygraph</a></span>
115+
</dt>
116+
<dd>
117+
The JS interop library itself.
118+
</dd>
119+
</dl>
120+
</section>
121+
122+
</div> <!-- /.main-content -->
123+
124+
<div id="dartdoc-sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
125+
</div>
126+
127+
</main>
128+
129+
<footer>
130+
<span class="no-break">
131+
dygraph
132+
0.1.1
133+
</span>
134+
135+
</footer>
136+
137+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
138+
<script src="static-assets/typeahead.bundle.min.js"></script>
139+
<script src="static-assets/highlight.pack.js"></script>
140+
<script src="static-assets/URI.js"></script>
141+
<script src="static-assets/script.js"></script>
142+
143+
144+
</body>
145+
146+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- <meta name="robots" content="noindex"/>
2+
- <link rel="alternate" href="/documentation/dygraph/latest/"/>
3+
- <a href="/packages/dygraph/versions/0.1.1">dygraph package</a>
4+
+ <a href="/packages/dygraph">dygraph package</a>
5+
- <a href="/packages/dygraph/versions/0.1.1">dygraph package</a>
6+
+ <a href="/packages/dygraph">dygraph package</a>

0 commit comments

Comments
 (0)