@@ -12,7 +12,9 @@ import 'package:dartdoc/src/warnings.dart';
12
12
import 'package:path/path.dart' as path;
13
13
import 'package:pub_semver/pub_semver.dart' ;
14
14
15
- final RegExp substituteNameVersion = RegExp (r'%([bnv])%' );
15
+ @Deprecated ('Public variable intended to be private; will be removed as early '
16
+ 'as Dartdoc 1.0.0' )
17
+ RegExp get substituteNameVersion => Package ._substituteNameVersion;
16
18
17
19
// All hrefs are emitted as relative paths from the output root. We are unable
18
20
// to compute them from the page we are generating, and many properties computed
@@ -224,51 +226,56 @@ class Package extends LibraryContainer
224
226
String _baseHref;
225
227
226
228
String get baseHref {
227
- if (_baseHref == null ) {
228
- if (documentedWhere == DocumentLocation .remote) {
229
- _baseHref =
230
- config.linkToUrl.replaceAllMapped (substituteNameVersion, (m) {
231
- switch (m.group (1 )) {
232
- // Return the prerelease tag of the release if a prerelease,
233
- // or 'stable' otherwise. Mostly coded around
234
- // the Dart SDK's use of dev/stable, but theoretically applicable
235
- // elsewhere.
236
- case 'b' :
237
- {
238
- var version = Version .parse (packageMeta.version);
239
- var tag = 'stable' ;
240
- if (version.isPreRelease) {
241
- // version.preRelease is a List<dynamic> with a mix of
242
- // integers and strings. Given this, handle
243
- // 2.8.0-dev.1.0, 2.9.0-1.0.dev, and similar
244
- // variations.
245
- tag = version.preRelease.whereType <String >().first;
246
- // Who knows about non-SDK packages, but assert that SDKs
247
- // must conform to the known format.
248
- assert (
249
- packageMeta.isSdk == false || int .tryParse (tag) == null ,
250
- 'Got an integer as string instead of the expected "dev" tag' );
251
- }
252
- return tag;
253
- }
254
- case 'n' :
255
- return name;
256
- // The full version string of the package.
257
- case 'v' :
258
- return packageMeta.version;
259
- default :
260
- assert (false , 'Unsupported case: ${m .group (1 )}' );
261
- return null ;
262
- }
263
- });
264
- if (! _baseHref.endsWith ('/' )) _baseHref = '${_baseHref }/' ;
265
- } else {
266
- _baseHref = config.useBaseHref ? '' : HTMLBASE_PLACEHOLDER ;
267
- }
229
+ if (_baseHref != null ) {
230
+ return _baseHref;
268
231
}
232
+
233
+ if (documentedWhere == DocumentLocation .remote) {
234
+ _baseHref = _remoteBaseHref;
235
+ if (! _baseHref.endsWith ('/' )) _baseHref = '${_baseHref }/' ;
236
+ } else {
237
+ _baseHref = config.useBaseHref ? '' : HTMLBASE_PLACEHOLDER ;
238
+ }
239
+
269
240
return _baseHref;
270
241
}
271
242
243
+ String get _remoteBaseHref {
244
+ return config.linkToUrl.replaceAllMapped (_substituteNameVersion, (m) {
245
+ switch (m.group (1 )) {
246
+ // Return the prerelease tag of the release if a prerelease, or 'stable'
247
+ // otherwise. Mostly coded around the Dart SDK's use of dev/stable, but
248
+ // theoretically applicable elsewhere.
249
+ case 'b' :
250
+ {
251
+ var version = Version .parse (packageMeta.version);
252
+ var tag = 'stable' ;
253
+ if (version.isPreRelease) {
254
+ // `version.preRelease` is a `List<dynamic>` with a mix of
255
+ // integers and strings. Given this, handle
256
+ // "2.8.0-dev.1.0, 2.9.0-1.0.dev", and similar variations.
257
+ tag = version.preRelease.whereType <String >().first;
258
+ // Who knows about non-SDK packages, but SDKs must conform to the
259
+ // known format.
260
+ assert (packageMeta.isSdk == false || int .tryParse (tag) == null ,
261
+ 'Got an integer as string instead of the expected "dev" tag' );
262
+ }
263
+ return tag;
264
+ }
265
+ case 'n' :
266
+ return name;
267
+ // The full version string of the package.
268
+ case 'v' :
269
+ return packageMeta.version;
270
+ default :
271
+ assert (false , 'Unsupported case: ${m .group (1 )}' );
272
+ return null ;
273
+ }
274
+ });
275
+ }
276
+
277
+ static final _substituteNameVersion = RegExp (r'%([bnv])%' );
278
+
272
279
@override
273
280
String get href => '$baseHref $filePath ' ;
274
281
0 commit comments