revert: feat(core): provide support for relative assets for components

This commit is contained in:
Matias Niemelä
2015-12-09 16:26:42 -08:00
parent f4d937ad8d
commit 5f0ce30ee6
23 changed files with 24 additions and 328 deletions

View File

@ -24,7 +24,7 @@ import {Compiler} from 'angular2/src/core/linker/compiler';
import {RuntimeCompiler} from 'angular2/src/compiler/runtime_compiler';
import {ElementSchemaRegistry} from 'angular2/src/compiler/schema/element_schema_registry';
import {DomElementSchemaRegistry} from 'angular2/src/compiler/schema/dom_element_schema_registry';
import {UrlResolver, DEFAULT_PACKAGE_URL_PROVIDER} from 'angular2/src/compiler/url_resolver';
import {UrlResolver} from 'angular2/src/compiler/url_resolver';
import {AppRootUrl} from 'angular2/src/compiler/app_root_url';
import {AnchorBasedAppRootUrl} from 'angular2/src/compiler/anchor_based_app_root_url';
import {Parser, Lexer} from 'angular2/src/core/change_detection/change_detection';
@ -40,7 +40,6 @@ export const COMPILER_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
TemplateParser,
TemplateNormalizer,
RuntimeMetadataResolver,
DEFAULT_PACKAGE_URL_PROVIDER,
StyleCompiler,
CommandCompiler,
ChangeDetectionCompiler,

View File

@ -19,7 +19,6 @@ import {reflector} from 'angular2/src/core/reflection/reflection';
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
import {PLATFORM_DIRECTIVES} from 'angular2/src/core/platform_directives_and_pipes';
import {MODULE_SUFFIX} from './util';
import {getUrlScheme} from 'angular2/src/compiler/url_resolver';
@Injectable()
export class RuntimeMetadataResolver {
@ -108,11 +107,8 @@ function isValidDirective(value: Type): boolean {
}
function calcModuleUrl(type: Type, dirMeta: md.DirectiveMetadata): string {
var moduleId = dirMeta.moduleId;
if (isPresent(moduleId)) {
var scheme = getUrlScheme(moduleId);
return isPresent(scheme) && scheme.length > 0 ? moduleId :
`package:${moduleId}${MODULE_SUFFIX}`;
if (isPresent(dirMeta.moduleId)) {
return `package:${dirMeta.moduleId}${MODULE_SUFFIX}`;
} else {
return reflector.importUri(type);
}

View File

@ -1,27 +1,22 @@
library angular2.src.services.url_resolver;
import 'package:angular2/src/core/di.dart' show Injectable, Inject, Provider;
import 'package:angular2/src/facade/lang.dart' show isPresent, StringWrapper;
import 'package:angular2/src/core/application_tokens.dart' show PACKAGE_ROOT_URL;
import 'package:angular2/src/core/di.dart' show Injectable, Provider;
UrlResolver createWithoutPackagePrefix() {
return new UrlResolver.withUrlPrefix(null);
}
const DEFAULT_PACKAGE_URL_PROVIDER = const Provider(PACKAGE_ROOT_URL, useValue: "/packages");
@Injectable()
class UrlResolver {
/// This will be the location where 'package:' Urls will resolve. Default is
/// '/packages'
final String _packagePrefix;
UrlResolver([@Inject(PACKAGE_ROOT_URL) packagePrefix]) :
this._packagePrefix = isPresent(packagePrefix) ? StringWrapper.stripRight(packagePrefix, '/') : null;
const UrlResolver() : _packagePrefix = '/packages';
/// Creates a UrlResolver that will resolve 'package:' Urls to a different
/// prefixed location.
UrlResolver.withUrlPrefix(this._packagePrefix);
const UrlResolver.withUrlPrefix(this._packagePrefix);
/**
* Resolves the `url` given the `baseUrl`:
@ -37,21 +32,15 @@ class UrlResolver {
*/
String resolve(String baseUrl, String url) {
Uri uri = Uri.parse(url);
if (isPresent(baseUrl) && baseUrl.length > 0) {
if (!uri.isAbsolute) {
Uri baseUri = Uri.parse(baseUrl);
uri = baseUri.resolveUri(uri);
}
if (_packagePrefix != null && uri.scheme == 'package') {
var path = StringWrapper.stripLeft(uri.path, '/');
return '$_packagePrefix/${path}';
return '$_packagePrefix/${uri.path}';
} else {
return uri.toString();
}
}
}
String getUrlScheme(String url) {
return Uri.parse(url).scheme;
}

View File

@ -1,21 +1,12 @@
import {Injectable, Inject} from 'angular2/src/core/di';
import {
StringWrapper,
isPresent,
isBlank,
RegExpWrapper,
normalizeBlank
} from 'angular2/src/facade/lang';
import {Injectable} from 'angular2/src/core/di';
import {isPresent, isBlank, RegExpWrapper, normalizeBlank} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
import {ListWrapper} from 'angular2/src/facade/collection';
import {PACKAGE_ROOT_URL} from 'angular2/src/core/application_tokens';
import {Provider} from 'angular2/src/core/di';
export function createWithoutPackagePrefix(): UrlResolver {
return new UrlResolver();
}
export var DEFAULT_PACKAGE_URL_PROVIDER = new Provider(PACKAGE_ROOT_URL, {useValue: "/"});
/**
* Used by the {@link Compiler} when resolving HTML and CSS template URLs.
@ -26,14 +17,6 @@ export var DEFAULT_PACKAGE_URL_PROVIDER = new Provider(PACKAGE_ROOT_URL, {useVal
*/
@Injectable()
export class UrlResolver {
private _packagePrefix: string;
constructor(@Inject(PACKAGE_ROOT_URL) packagePrefix: string = null) {
if (isPresent(packagePrefix)) {
this._packagePrefix = StringWrapper.stripRight(packagePrefix, "/") + "/";
}
}
/**
* Resolves the `url` given the `baseUrl`:
* - when the `url` is null, the `baseUrl` is returned,
@ -46,21 +29,7 @@ export class UrlResolver {
* @param {string} url
* @returns {string} the resolved URL
*/
resolve(baseUrl: string, url: string): string {
var resolvedUrl = url;
if (isPresent(baseUrl) && baseUrl.length > 0) {
resolvedUrl = _resolveUrl(baseUrl, resolvedUrl);
}
if (isPresent(this._packagePrefix) && getUrlScheme(resolvedUrl) == "package") {
resolvedUrl = resolvedUrl.replace("package:", this._packagePrefix);
}
return resolvedUrl;
}
}
export function getUrlScheme(url: string): string {
var match = _split(url);
return (match && match[_ComponentIndex.Scheme]) || "";
resolve(baseUrl: string, url: string): string { return _resolveUrl(baseUrl, url); }
}
// The code below is adapted from Traceur: