From 8b63c60eb3dbc17451425dcb8236aba4f4492347 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Wed, 21 Feb 2018 10:07:12 +0100 Subject: [PATCH 1/5] Customization skeleton. --- app/lib/dartdoc/customization.dart | 29 ++ app/test/dartdoc/customization_test.dart | 49 +++ .../dartdoc/golden/pana_0.10.2_index.html | 105 ++++++ .../dartdoc/golden/pana_0.10.2_index.out.html | 105 ++++++ .../pana_0.10.2_license_file_class.html | 315 ++++++++++++++++++ .../pana_0.10.2_license_file_class.out.html | 315 ++++++++++++++++++ .../pana_0.10.2_license_file_constructor.html | 109 ++++++ ...a_0.10.2_license_file_constructor.out.html | 109 ++++++ .../pana_0.10.2_license_file_name_field.html | 110 ++++++ ...na_0.10.2_license_file_name_field.out.html | 110 ++++++ .../golden/pana_0.10.2_pretty_json.html | 159 +++++++++ .../golden/pana_0.10.2_pretty_json.out.html | 159 +++++++++ 12 files changed, 1674 insertions(+) create mode 100644 app/lib/dartdoc/customization.dart create mode 100644 app/test/dartdoc/customization_test.dart create mode 100644 app/test/dartdoc/golden/pana_0.10.2_index.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_index.out.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_class.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_pretty_json.html create mode 100644 app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html diff --git a/app/lib/dartdoc/customization.dart b/app/lib/dartdoc/customization.dart new file mode 100644 index 0000000000..2fcd4c704a --- /dev/null +++ b/app/lib/dartdoc/customization.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; + +class DartdocCustomizer { + final String packageName; + final String packageVersion; + + DartdocCustomizer(this.packageName, this.packageVersion); + + Future customizeFile(File file) async { + final String oldContent = await file.readAsString(); + final String newContent = customizeHtml(oldContent); + if (newContent != null && oldContent != newContent) { + await file.writeAsString(newContent); + return true; + } else { + return false; + } + } + + String customizeHtml(String html) { + return null; + } +} + diff --git a/app/test/dartdoc/customization_test.dart b/app/test/dartdoc/customization_test.dart new file mode 100644 index 0000000000..981e01b70b --- /dev/null +++ b/app/test/dartdoc/customization_test.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:io'; + +import 'package:html/parser.dart'; +import 'package:test/test.dart'; + +import 'package:pub_dartlang_org/dartdoc/customization.dart'; + +const String goldenDir = 'test/dartdoc/golden'; + +final _regenerateGoldens = false; + +void main() { + void expectGoldenFile(String content, String fileName) { + // Making sure it is valid HTML + final htmlParser = new HtmlParser(content, strict: true); + htmlParser.parse(); + + if (_regenerateGoldens) { + new File('$goldenDir/$fileName').writeAsStringSync(content); + fail('Set `_regenerateGoldens` to `false` to run tests.'); + } + final golden = new File('$goldenDir/$fileName').readAsStringSync(); + expect(content.split('\n'), golden.split('\n')); + } + + group('pana 0.10.2', () { + final customization = new DartdocCustomizer('pana', '0.10.2'); + + void expectMatch(String name) { + test(name, () { + final inputName = 'pana_0.10.2_$name.html'; + final outputName = 'pana_0.10.2_$name.out.html'; + final html = new File('$goldenDir/$inputName').readAsStringSync(); + final result = customization.customizeHtml(html) ?? html; + expectGoldenFile(result, outputName); + }); + } + + expectMatch('index'); + expectMatch('license_file_class'); + expectMatch('license_file_constructor'); + expectMatch('license_file_name_field'); + expectMatch('pretty_json'); + }); +} diff --git a/app/test/dartdoc/golden/pana_0.10.2_index.html b/app/test/dartdoc/golden/pana_0.10.2_index.html new file mode 100644 index 0000000000..8714ed3837 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_index.html @@ -0,0 +1,105 @@ + + + + + + + + + pana - Dart API docs + + + + + + + + + + + +
+ +
+ +
pana
+ +
+ +
+ + + +
+
+

Build Status

+

A library for analyzing Dart packages.

  • Validates the code using Dart Analyzer.
  • Checks code formatting.
  • Checks for outdated dependencies.
  • Infers supported platforms: Flutter, web, and/or server.
+

Used by the Dart Package site.

+

Use as an executable

+

Installation

+
> pub global activate pana
+
+

Usage

+

You can specify either a package (+ version) or a local directory to analyze:

+
Usage: pana [<options>] <package> [<version>]
+       pana [<options>] --source path <directory>
+
+Options:
+  -j, --json            Output log items as JSON.
+  -s, --source          The source used to find the package.
+                        [hosted (default), path]
+  
+      --hosted-url      The server that hosts <package>.
+                        (defaults to "https://pub.dartlang.org")
+  
+      --[no-]warning    Shows the warning message before potentially destructive operation.
+                        (defaults to on)
+
+
+ + +
+

Libraries

+
+
+ pana +
+
+ +
+
+
+ +
+ +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_index.out.html b/app/test/dartdoc/golden/pana_0.10.2_index.out.html new file mode 100644 index 0000000000..8714ed3837 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_index.out.html @@ -0,0 +1,105 @@ + + + + + + + + + pana - Dart API docs + + + + + + + + + + + +
+ +
+ +
pana
+ +
+ +
+ + + +
+
+

Build Status

+

A library for analyzing Dart packages.

  • Validates the code using Dart Analyzer.
  • Checks code formatting.
  • Checks for outdated dependencies.
  • Infers supported platforms: Flutter, web, and/or server.
+

Used by the Dart Package site.

+

Use as an executable

+

Installation

+
> pub global activate pana
+
+

Usage

+

You can specify either a package (+ version) or a local directory to analyze:

+
Usage: pana [<options>] <package> [<version>]
+       pana [<options>] --source path <directory>
+
+Options:
+  -j, --json            Output log items as JSON.
+  -s, --source          The source used to find the package.
+                        [hosted (default), path]
+  
+      --hosted-url      The server that hosts <package>.
+                        (defaults to "https://pub.dartlang.org")
+  
+      --[no-]warning    Shows the warning message before potentially destructive operation.
+                        (defaults to on)
+
+
+ + +
+

Libraries

+
+
+ pana +
+
+ +
+
+
+ +
+ +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_class.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.html new file mode 100644 index 0000000000..f872a1b2f7 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.html @@ -0,0 +1,315 @@ + + + + + + + + LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
LicenseFile
+ +
+ +
+ + + +
+

LicenseFile class

+ + +
+
+ + + + +
Annotations
+
    +
  • @JsonSerializable()
  • +
+
+
+ +
+

Constructors

+ +
+
+ LicenseFile(String path, String name, { String version, String url }) +
+
+ +
+
+ LicenseFile.fromJson(Map<String, dynamic> json) +
+
+ +
factory
+
+
+
+ +
+

Properties

+ +
+
+ hashCode + → int +
+
+ The hash code for this object. [...] +
read-only
+
+
+ name + → String +
+
+ +
final
+
+
+ path + → String +
+
+ +
final
+
+
+ shortFormatted + → String +
+
+ +
read-only
+
+
+ url + → String +
+
+ +
@JsonKey(includeIfNull: false), final
+
+
+ version + → String +
+
+ +
@JsonKey(includeIfNull: false), final
+
+
+ runtimeType + → Type +
+
+ A representation of the runtime type of the object. +
read-only, inherited
+
+
+
+ +
+

Methods

+
+
+ change({String url }) + LicenseFile + +
+
+ + +
+
+ toString() + → String + +
+
+ Returns a string representation of this object. + +
+
+ noSuchMethod(Invocation invocation) + → dynamic + +
+
+ Invoked when a non-existent method or property is accessed. [...] +
inherited
+
+
+ toJson() + → Map<String, dynamic> + +
+
+ +
inherited
+
+
+
+ +
+

Operators

+
+
+ operator ==(Object other) + → bool + +
+
+ The equality operator. [...] + +
+
+
+ + + + +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html new file mode 100644 index 0000000000..f872a1b2f7 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html @@ -0,0 +1,315 @@ + + + + + + + + LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
LicenseFile
+ +
+ +
+ + + +
+

LicenseFile class

+ + +
+
+ + + + +
Annotations
+
    +
  • @JsonSerializable()
  • +
+
+
+ +
+

Constructors

+ +
+
+ LicenseFile(String path, String name, { String version, String url }) +
+
+ +
+
+ LicenseFile.fromJson(Map<String, dynamic> json) +
+
+ +
factory
+
+
+
+ +
+

Properties

+ +
+
+ hashCode + → int +
+
+ The hash code for this object. [...] +
read-only
+
+
+ name + → String +
+
+ +
final
+
+
+ path + → String +
+
+ +
final
+
+
+ shortFormatted + → String +
+
+ +
read-only
+
+
+ url + → String +
+
+ +
@JsonKey(includeIfNull: false), final
+
+
+ version + → String +
+
+ +
@JsonKey(includeIfNull: false), final
+
+
+ runtimeType + → Type +
+
+ A representation of the runtime type of the object. +
read-only, inherited
+
+
+
+ +
+

Methods

+
+
+ change({String url }) + LicenseFile + +
+
+ + +
+
+ toString() + → String + +
+
+ Returns a string representation of this object. + +
+
+ noSuchMethod(Invocation invocation) + → dynamic + +
+
+ Invoked when a non-existent method or property is accessed. [...] +
inherited
+
+
+ toJson() + → Map<String, dynamic> + +
+
+ +
inherited
+
+
+
+ +
+

Operators

+
+
+ operator ==(Object other) + → bool + +
+
+ The equality operator. [...] + +
+
+
+ + + + +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.html new file mode 100644 index 0000000000..4c6f18cc4f --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.html @@ -0,0 +1,109 @@ + + + + + + + + LicenseFile constructor - LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
LicenseFile
+ +
+ +
+ + + +
+

LicenseFile constructor

+ +
+ + LicenseFile(String path, String name, { String version, String url }) +
+ + +
+

Implementation

+
LicenseFile(this.path, this.name, {this.version, this.url});
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html new file mode 100644 index 0000000000..4c6f18cc4f --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html @@ -0,0 +1,109 @@ + + + + + + + + LicenseFile constructor - LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
LicenseFile
+ +
+ +
+ + + +
+

LicenseFile constructor

+ +
+ + LicenseFile(String path, String name, { String version, String url }) +
+ + +
+

Implementation

+
LicenseFile(this.path, this.name, {this.version, this.url});
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.html new file mode 100644 index 0000000000..ad6b8223bb --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.html @@ -0,0 +1,110 @@ + + + + + + + + name property - LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
name
+ +
+ +
+ + + +
+

name property

+ +
+ String + name +
final
+
+
+

Implementation

+
final String name
+
+
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html new file mode 100644 index 0000000000..ad6b8223bb --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html @@ -0,0 +1,110 @@ + + + + + + + + name property - LicenseFile class - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
name
+ +
+ +
+ + + +
+

name property

+ +
+ String + name +
final
+
+
+

Implementation

+
final String name
+
+
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_pretty_json.html b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.html new file mode 100644 index 0000000000..2d5bb2f133 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.html @@ -0,0 +1,159 @@ + + + + + + + + prettyJson function - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
prettyJson
+ +
+ +
+ + + +
+

prettyJson function

+ +
+ String + prettyJson +(obj) +
+ +
+

Implementation

+
String prettyJson(obj) {
+  try {
+    return const JsonEncoder.withIndent(' ').convert(obj);
+  } on JsonUnsupportedObjectError catch (e) {
+    var error = e;
+
+    while (error is JsonUnsupportedObjectError) {
+      stderr.writeln([
+        error,
+        "${error.unsupportedObject} - (${error.unsupportedObject.runtimeType})",
+        error.cause == null ? null : "Nested cause: ${error.cause}",
+        error.stackTrace
+      ].where((i) => i != null).join('\n'));
+
+      error = error.cause;
+    }
+    rethrow;
+  }
+}
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + diff --git a/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html new file mode 100644 index 0000000000..2d5bb2f133 --- /dev/null +++ b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html @@ -0,0 +1,159 @@ + + + + + + + + prettyJson function - pana library - Dart API + + + + + + + + + + + + + +
+ +
+ + +
prettyJson
+ +
+ +
+ + + +
+

prettyJson function

+ +
+ String + prettyJson +(obj) +
+ +
+

Implementation

+
String prettyJson(obj) {
+  try {
+    return const JsonEncoder.withIndent(' ').convert(obj);
+  } on JsonUnsupportedObjectError catch (e) {
+    var error = e;
+
+    while (error is JsonUnsupportedObjectError) {
+      stderr.writeln([
+        error,
+        "${error.unsupportedObject} - (${error.unsupportedObject.runtimeType})",
+        error.cause == null ? null : "Nested cause: ${error.cause}",
+        error.stackTrace
+      ].where((i) => i != null).join('\n'));
+
+      error = error.cause;
+    }
+    rethrow;
+  }
+}
+
+ +
+ + + +
+ +
+ + pana 0.10.2 + + +
+ + + + + + + + + + + From 4acd66348d9ded460d4e89a8c4f908ffa4e16663 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Wed, 21 Feb 2018 10:25:45 +0100 Subject: [PATCH 2/5] Use html parsing in customization. --- app/lib/dartdoc/customization.dart | 6 +++- .../dartdoc/golden/pana_0.10.2_index.out.html | 11 +++--- .../pana_0.10.2_license_file_class.out.html | 35 +++++++++---------- ...a_0.10.2_license_file_constructor.out.html | 11 +++--- ...na_0.10.2_license_file_name_field.out.html | 11 +++--- .../golden/pana_0.10.2_pretty_json.out.html | 19 +++++----- 6 files changed, 46 insertions(+), 47 deletions(-) diff --git a/app/lib/dartdoc/customization.dart b/app/lib/dartdoc/customization.dart index 2fcd4c704a..091a535db2 100644 --- a/app/lib/dartdoc/customization.dart +++ b/app/lib/dartdoc/customization.dart @@ -5,6 +5,9 @@ import 'dart:async'; import 'dart:io'; +import 'package:html/dom.dart'; +import 'package:html/parser.dart' as html_parser; + class DartdocCustomizer { final String packageName; final String packageVersion; @@ -23,7 +26,8 @@ class DartdocCustomizer { } String customizeHtml(String html) { - return null; + final doc = html_parser.parse(html); + return doc.outerHtml; } } diff --git a/app/test/dartdoc/golden/pana_0.10.2_index.out.html b/app/test/dartdoc/golden/pana_0.10.2_index.out.html index 8714ed3837..9d54881eaa 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_index.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_index.out.html @@ -1,6 +1,4 @@ - - - + @@ -26,7 +24,7 @@
pana
@@ -100,6 +98,7 @@

Libraries

- - + + + \ No newline at end of file diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html index f872a1b2f7..391b015148 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_class.out.html @@ -1,6 +1,4 @@ - - - + @@ -30,7 +28,7 @@
LicenseFile
@@ -144,7 +142,7 @@

Properties

hashCode - → int + → int
The hash code for this object. [...] @@ -152,7 +150,7 @@

Properties

name - → String + → String
@@ -160,7 +158,7 @@

Properties

path - → String + → String
@@ -168,7 +166,7 @@

Properties

shortFormatted - → String + → String
@@ -176,7 +174,7 @@

Properties

url - → String + → String
@@ -184,7 +182,7 @@

Properties

version - → String + → String
@@ -192,7 +190,7 @@

Properties

runtimeType - → Type + → Type
A representation of the runtime type of the object. @@ -206,7 +204,7 @@

Methods

change({String url }) - LicenseFile + LicenseFile
@@ -215,7 +213,7 @@

Methods

toString() - → String + → String
@@ -224,7 +222,7 @@

Methods

noSuchMethod(Invocation invocation) - → dynamic + → dynamic
@@ -233,7 +231,7 @@

Methods

toJson() - → Map<String, dynamic> + → Map<String, dynamic>
@@ -248,7 +246,7 @@

Operators

operator ==(Object other) - → bool + → bool
@@ -310,6 +308,7 @@

Operators

- - + + + \ No newline at end of file diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html index 4c6f18cc4f..27a865f5d2 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_constructor.out.html @@ -1,6 +1,4 @@ - - - + @@ -31,7 +29,7 @@
LicenseFile
@@ -104,6 +102,7 @@

Implementation

- - + + + \ No newline at end of file diff --git a/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html index ad6b8223bb..9c0ec9afba 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_license_file_name_field.out.html @@ -1,6 +1,4 @@ - - - + @@ -31,7 +29,7 @@
name
@@ -105,6 +103,7 @@

Implementation

- - + + + \ No newline at end of file diff --git a/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html index 2d5bb2f133..1362ba5fdb 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_pretty_json.out.html @@ -1,6 +1,4 @@ - - - + @@ -30,7 +28,7 @@
prettyJson
@@ -114,17 +112,17 @@

prettyJson function

Implementation

String prettyJson(obj) {
   try {
-    return const JsonEncoder.withIndent(' ').convert(obj);
+    return const JsonEncoder.withIndent(' ').convert(obj);
   } on JsonUnsupportedObjectError catch (e) {
     var error = e;
 
     while (error is JsonUnsupportedObjectError) {
       stderr.writeln([
         error,
-        "${error.unsupportedObject} - (${error.unsupportedObject.runtimeType})",
-        error.cause == null ? null : "Nested cause: ${error.cause}",
+        "${error.unsupportedObject} - (${error.unsupportedObject.runtimeType})",
+        error.cause == null ? null : "Nested cause: ${error.cause}",
         error.stackTrace
-      ].where((i) => i != null).join('\n'));
+      ].where((i) => i != null).join('\n'));
 
       error = error.cause;
     }
@@ -154,6 +152,7 @@ 

Implementation

- - + + + \ No newline at end of file From 06d85f48fa480b05e2e4e175edfd300d2c930708 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Wed, 21 Feb 2018 10:44:22 +0100 Subject: [PATCH 3/5] Rewrite breadcrumbs: always include a link to the pub package page. --- app/lib/dartdoc/customization.dart | 30 ++++++++++++++++++- .../dartdoc/golden/pana_0.10.2_index.out.html | 2 +- .../pana_0.10.2_license_file_class.out.html | 3 +- ...a_0.10.2_license_file_constructor.out.html | 3 +- ...na_0.10.2_license_file_name_field.out.html | 3 +- .../golden/pana_0.10.2_pretty_json.out.html | 3 +- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/lib/dartdoc/customization.dart b/app/lib/dartdoc/customization.dart index 091a535db2..9a60d23371 100644 --- a/app/lib/dartdoc/customization.dart +++ b/app/lib/dartdoc/customization.dart @@ -27,7 +27,35 @@ class DartdocCustomizer { String customizeHtml(String html) { final doc = html_parser.parse(html); + final breadcrumbs = doc.body.querySelector('.breadcrumbs'); + if (breadcrumbs != null) { + _addPubPackageLink(breadcrumbs); + } return doc.outerHtml; } -} + void _addPubPackageLink(Element breadcrumbs) { + final pubPackageLink = + 'https://pub.dartlang.org/packages/$packageName/versions/$packageVersion'; + final pubPackageText = '$packageName package'; + if (breadcrumbs.children.length == 1) { + // we are on the index page + final firstLink = breadcrumbs.querySelector('a'); + firstLink.attributes['href'] = pubPackageLink; + firstLink.text = pubPackageText; + } else if (breadcrumbs.children.isNotEmpty) { + // we are inside + final firstLink = breadcrumbs.querySelector('a'); + firstLink.text = 'documentation'; + + final lead = new Element.tag('li'); + final leadLink = new Element.tag('a'); + leadLink.attributes['href'] = pubPackageLink; + leadLink.text = pubPackageText; + lead.append(leadLink); + + breadcrumbs.insertBefore(lead, breadcrumbs.firstChild); + breadcrumbs.insertBefore(new Text('\n '), breadcrumbs.firstChild); + } + } +} diff --git a/app/test/dartdoc/golden/pana_0.10.2_index.out.html b/app/test/dartdoc/golden/pana_0.10.2_index.out.html index 9d54881eaa..19c602585f 100644 --- a/app/test/dartdoc/golden/pana_0.10.2_index.out.html +++ b/app/test/dartdoc/golden/pana_0.10.2_index.out.html @@ -20,7 +20,7 @@
pana