From 62c51a3c2d9f46f41bb6f40e794a7f0055946444 Mon Sep 17 00:00:00 2001 From: Ted Sander Date: Tue, 10 Mar 2015 01:59:27 -0700 Subject: [PATCH] feat(relative_url_resolver): Allow configurable package root. Allow the package root to be configurable per application allowing apps that cannot server from /packages/. --- lib/core_dom/resource_url_resolver.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/core_dom/resource_url_resolver.dart b/lib/core_dom/resource_url_resolver.dart index 00a6a1fa5..42436a9bc 100755 --- a/lib/core_dom/resource_url_resolver.dart +++ b/lib/core_dom/resource_url_resolver.dart @@ -160,9 +160,9 @@ class ResourceUrlResolver { // If it's not absolute, then resolve it first Uri resolved = baseUri.resolve(uri); - // If it's package-relative, tack on '/packages/' + // If it's package-relative, tack on [packageRoot]. if (resolved.scheme == 'package') { - return '/packages/${resolved.path}'; + return '${_config.packageRoot}${resolved.path}'; } else if (resolved.isAbsolute && resolved.toString().startsWith(_baseUri)) { return resolved.path; } else { @@ -181,9 +181,13 @@ class ResourceUrlResolver { @Injectable() class ResourceResolverConfig { + static const String DEFAULT_PACKAGE_ROOT = '/packages/'; bool useRelativeUrls; + String packageRoot; - ResourceResolverConfig(): useRelativeUrls = true; + ResourceResolverConfig(): useRelativeUrls = true, + packageRoot = DEFAULT_PACKAGE_ROOT; - ResourceResolverConfig.resolveRelativeUrls(this.useRelativeUrls); + ResourceResolverConfig.resolveRelativeUrls(this.useRelativeUrls, + {this.packageRoot: DEFAULT_PACKAGE_ROOT}); }