Skip to content

Commit

Permalink
feat(url_resolver): Allow a developer to customize their package prefix
Browse files Browse the repository at this point in the history
Allow a developer to specify a package prefix where the 'package:' dart urls
will be resolved. By default this will be '/packages' keeping the current
behavior, but allows for flexibility of different environments where a
developer may not control their directory structure.

Closes #3794
  • Loading branch information
TedSander committed Aug 25, 2015
1 parent 894af28 commit 9cc1cd2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/angular2/src/services/url_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import 'package:angular2/di.dart' show Injectable;

@Injectable()
class UrlResolver {
/// This will be the location where 'package:' Urls will resolve. Default is
/// '/packages'
final String packagePrefix;

const UrlResolver() : packagePrefix = '/packages';

/// Creates a UrlResolver that will resolve 'package:' Urls to a different
/// prefixed location.
const UrlResolver.withUrlPrefix(this.packagePrefix);

/**
* Resolves the `url` given the `baseUrl`:
* - when the `url` is null, the `baseUrl` is returned,
Expand All @@ -20,7 +30,7 @@ class UrlResolver {
Uri uri = Uri.parse(url);

if (uri.scheme == 'package') {
return '/packages/${uri.path}';
return '$packagePrefix/${uri.path}';
}

if (uri.isAbsolute) return uri.toString();
Expand Down

0 comments on commit 9cc1cd2

Please sign in to comment.