fix(url_resolver): in Dart make package urls relative to AppRootUrl

This commit is contained in:
yjbanov
2015-07-24 14:49:16 -07:00
parent c2bbda02a1
commit 469afda53e
18 changed files with 58 additions and 33 deletions

View File

@ -1,9 +1,15 @@
library angular2.src.services.url_resolver;
import 'package:angular2/di.dart' show Injectable;
import 'package:angular2/src/services/app_root_url.dart' show AppRootUrl;
@Injectable()
class UrlResolver {
final AppRootUrl _appRootUrl;
UrlResolver(this._appRootUrl);
/**
* Resolves the `url` given the `baseUrl`:
* - when the `url` is null, the `baseUrl` is returned,
@ -20,7 +26,8 @@ class UrlResolver {
Uri uri = Uri.parse(url);
if (uri.scheme == 'package') {
return '/packages/${uri.path}';
var maybeSlash = _appRootUrl.value.endsWith('/') ? '' : '/';
return '${_appRootUrl.value}${maybeSlash}packages/${uri.path}';
}
if (uri.isAbsolute) return uri.toString();

View File

@ -7,6 +7,7 @@ import {
normalizeBlank
} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
import {AppRootUrl} from 'angular2/src/services/app_root_url';
/**
* Used by the {@link Compiler} when resolving HTML and CSS template URLs.
@ -17,6 +18,8 @@ import {ListWrapper} from 'angular2/src/facade/collection';
*/
@Injectable()
export class UrlResolver {
constructor(_: AppRootUrl) {}
/**
* Resolves the `url` given the `baseUrl`:
* - when the `url` is null, the `baseUrl` is returned,

View File

@ -12,6 +12,7 @@ import 'package:angular2/src/render/dom/compiler/style_url_resolver.dart';
import 'package:angular2/src/render/dom/compiler/view_loader.dart';
import 'package:angular2/src/render/xhr.dart' show XHR;
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/services/app_root_url.dart';
import 'package:angular2/src/services/url_resolver.dart';
import 'package:angular2/src/transform/common/asset_reader.dart';
import 'package:angular2/src/transform/common/xhr_impl.dart';
@ -85,7 +86,7 @@ class _TemplateExtractor {
_TemplateExtractor(XHR xhr)
: _factory = new CompileStepFactory(new ng.Parser(new ng.Lexer())) {
var urlResolver = new UrlResolver();
var urlResolver = new UrlResolver(new AppRootUrl(''));
var styleUrlResolver = new StyleUrlResolver(urlResolver);
var styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);