refactor(TemplateLoader): rename to ViewLoader
This commit is contained in:
parent
b89c0672e6
commit
356c927d12
|
@ -5,7 +5,7 @@
|
||||||
* This module provides advanced support for extending dom strategy.
|
* This module provides advanced support for extending dom strategy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './src/render/dom/compiler/template_loader';
|
export * from './src/render/dom/compiler/view_loader';
|
||||||
export * from './src/render/dom/shadow_dom/shadow_dom_strategy';
|
export * from './src/render/dom/shadow_dom/shadow_dom_strategy';
|
||||||
export * from './src/render/dom/shadow_dom/native_shadow_dom_strategy';
|
export * from './src/render/dom/shadow_dom/native_shadow_dom_strategy';
|
||||||
export * from './src/render/dom/shadow_dom/emulated_scoped_shadow_dom_strategy';
|
export * from './src/render/dom/shadow_dom/emulated_scoped_shadow_dom_strategy';
|
||||||
|
|
|
@ -24,7 +24,7 @@ import {
|
||||||
defaultPipeRegistry
|
defaultPipeRegistry
|
||||||
} from 'angular2/change_detection';
|
} from 'angular2/change_detection';
|
||||||
import {ExceptionHandler} from './exception_handler';
|
import {ExceptionHandler} from './exception_handler';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver';
|
import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver';
|
||||||
import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner';
|
import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner';
|
||||||
import {TemplateResolver} from './compiler/template_resolver';
|
import {TemplateResolver} from './compiler/template_resolver';
|
||||||
|
@ -121,7 +121,7 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
|
||||||
TemplateResolver,
|
TemplateResolver,
|
||||||
bind(PipeRegistry).toValue(defaultPipeRegistry),
|
bind(PipeRegistry).toValue(defaultPipeRegistry),
|
||||||
bind(ChangeDetection).toClass(bestChangeDetection),
|
bind(ChangeDetection).toClass(bestChangeDetection),
|
||||||
TemplateLoader,
|
ViewLoader,
|
||||||
DirectiveResolver,
|
DirectiveResolver,
|
||||||
Parser,
|
Parser,
|
||||||
Lexer,
|
Lexer,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
RenderProtoViewRef
|
RenderProtoViewRef
|
||||||
} from '../../api';
|
} from '../../api';
|
||||||
import {CompilePipeline} from './compile_pipeline';
|
import {CompilePipeline} from './compile_pipeline';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory';
|
import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory';
|
||||||
import {Parser} from 'angular2/change_detection';
|
import {Parser} from 'angular2/change_detection';
|
||||||
import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy';
|
import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy';
|
||||||
|
@ -24,12 +24,10 @@ import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy';
|
||||||
* the CompilePipeline and the CompileSteps.
|
* the CompilePipeline and the CompileSteps.
|
||||||
*/
|
*/
|
||||||
export class DomCompiler extends RenderCompiler {
|
export class DomCompiler extends RenderCompiler {
|
||||||
constructor(public _stepFactory: CompileStepFactory, public _templateLoader: TemplateLoader) {
|
constructor(public _stepFactory: CompileStepFactory, public _viewLoader: ViewLoader) { super(); }
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
compile(view: ViewDefinition): Promise<ProtoViewDto> {
|
compile(view: ViewDefinition): Promise<ProtoViewDto> {
|
||||||
var tplPromise = this._templateLoader.load(view);
|
var tplPromise = this._viewLoader.load(view);
|
||||||
return PromiseWrapper.then(
|
return PromiseWrapper.then(
|
||||||
tplPromise, (el) => this._compileTemplate(view, el, ViewType.COMPONENT), (e) => {
|
tplPromise, (el) => this._compileTemplate(view, el, ViewType.COMPONENT), (e) => {
|
||||||
throw new BaseException(`Failed to load the template for "${view.componentId}" : ${e}`);
|
throw new BaseException(`Failed to load the template for "${view.componentId}" : ${e}`);
|
||||||
|
@ -59,8 +57,7 @@ export class DomCompiler extends RenderCompiler {
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DefaultDomCompiler extends DomCompiler {
|
export class DefaultDomCompiler extends DomCompiler {
|
||||||
constructor(parser: Parser, shadowDomStrategy: ShadowDomStrategy,
|
constructor(parser: Parser, shadowDomStrategy: ShadowDomStrategy, viewLoader: ViewLoader) {
|
||||||
templateLoader: TemplateLoader) {
|
super(new DefaultStepFactory(parser, shadowDomStrategy), viewLoader);
|
||||||
super(new DefaultStepFactory(parser, shadowDomStrategy), templateLoader);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {StyleUrlResolver} from './style_url_resolver';
|
||||||
* TODO: Make public API once we are more confident in this approach.
|
* TODO: Make public API once we are more confident in this approach.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TemplateLoader {
|
export class ViewLoader {
|
||||||
_cache: Map<string, Promise<string>> = new Map();
|
_cache: Map<string, Promise<string>> = new Map();
|
||||||
|
|
||||||
constructor(private _xhr: XHR, private _styleInliner: StyleInliner,
|
constructor(private _xhr: XHR, private _styleInliner: StyleInliner,
|
|
@ -11,7 +11,7 @@ import {
|
||||||
defaultPipeRegistry
|
defaultPipeRegistry
|
||||||
} from 'angular2/change_detection';
|
} from 'angular2/change_detection';
|
||||||
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
||||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||||
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||||
|
@ -104,7 +104,7 @@ function _getAppBindings() {
|
||||||
bind(TemplateResolver).toClass(MockTemplateResolver),
|
bind(TemplateResolver).toClass(MockTemplateResolver),
|
||||||
bind(PipeRegistry).toValue(defaultPipeRegistry),
|
bind(PipeRegistry).toValue(defaultPipeRegistry),
|
||||||
bind(ChangeDetection).toClass(DynamicChangeDetection),
|
bind(ChangeDetection).toClass(DynamicChangeDetection),
|
||||||
TemplateLoader,
|
ViewLoader,
|
||||||
DynamicComponentLoader,
|
DynamicComponentLoader,
|
||||||
DirectiveResolver,
|
DirectiveResolver,
|
||||||
Parser,
|
Parser,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import 'package:angular2/src/render/api.dart';
|
||||||
import 'package:angular2/src/render/dom/compiler/compile_pipeline.dart';
|
import 'package:angular2/src/render/dom/compiler/compile_pipeline.dart';
|
||||||
import 'package:angular2/src/render/dom/compiler/style_inliner.dart';
|
import 'package:angular2/src/render/dom/compiler/style_inliner.dart';
|
||||||
import 'package:angular2/src/render/dom/compiler/style_url_resolver.dart';
|
import 'package:angular2/src/render/dom/compiler/style_url_resolver.dart';
|
||||||
import 'package:angular2/src/render/dom/compiler/template_loader.dart';
|
import 'package:angular2/src/render/dom/compiler/view_loader.dart';
|
||||||
import 'package:angular2/src/render/xhr.dart' show XHR;
|
import 'package:angular2/src/render/xhr.dart' show XHR;
|
||||||
import 'package:angular2/src/reflection/reflection.dart';
|
import 'package:angular2/src/reflection/reflection.dart';
|
||||||
import 'package:angular2/src/services/url_resolver.dart';
|
import 'package:angular2/src/services/url_resolver.dart';
|
||||||
|
@ -81,7 +81,7 @@ Future<String> processTemplates(AssetReader reader, AssetId entryPoint,
|
||||||
/// reflectively accessed from that template.
|
/// reflectively accessed from that template.
|
||||||
class _TemplateExtractor {
|
class _TemplateExtractor {
|
||||||
final CompileStepFactory _factory;
|
final CompileStepFactory _factory;
|
||||||
TemplateLoader _loader;
|
ViewLoader _loader;
|
||||||
|
|
||||||
_TemplateExtractor(XHR xhr)
|
_TemplateExtractor(XHR xhr)
|
||||||
: _factory = new CompileStepFactory(new ng.Parser(new ng.Lexer())) {
|
: _factory = new CompileStepFactory(new ng.Parser(new ng.Lexer())) {
|
||||||
|
@ -90,7 +90,7 @@ class _TemplateExtractor {
|
||||||
var styleUrlResolver = new StyleUrlResolver(urlResolver);
|
var styleUrlResolver = new StyleUrlResolver(urlResolver);
|
||||||
var styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
var styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
||||||
|
|
||||||
_loader = new TemplateLoader(xhr, styleInliner, styleUrlResolver);
|
_loader = new ViewLoader(xhr, styleInliner, styleUrlResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<_ExtractResult> extractTemplates(ViewDefinition viewDef) async {
|
Future<_ExtractResult> extractTemplates(ViewDefinition viewDef) async {
|
||||||
|
|
|
@ -133,8 +133,7 @@ export function main() {
|
||||||
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
||||||
captureTemplate(new viewAnn.View({templateUrl: 'tpl/main.html'}))
|
captureTemplate(new viewAnn.View({templateUrl: 'tpl/main.html'}))
|
||||||
.then((renderTpl) => {
|
.then((renderTpl) => {
|
||||||
expect(renderTpl.templateAbsUrl)
|
expect(renderTpl.templateAbsUrl).toEqual('http://www.app.com/cmp/tpl/main.html');
|
||||||
.toEqual('http://www.app.com/cmp/tpl/main.html');
|
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@ -144,10 +143,8 @@ export function main() {
|
||||||
captureTemplate(new viewAnn.View({styleUrls: ['css/1.css', 'css/2.css']}))
|
captureTemplate(new viewAnn.View({styleUrls: ['css/1.css', 'css/2.css']}))
|
||||||
.then((renderTpl) => {
|
.then((renderTpl) => {
|
||||||
expect(renderTpl.styleAbsUrls)
|
expect(renderTpl.styleAbsUrls)
|
||||||
.toEqual([
|
.toEqual(
|
||||||
'http://www.app.com/cmp/css/1.css',
|
['http://www.app.com/cmp/css/1.css', 'http://www.app.com/cmp/css/2.css']);
|
||||||
'http://www.app.com/cmp/css/2.css'
|
|
||||||
]);
|
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -22,7 +22,7 @@ import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
|
||||||
import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
|
import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
|
||||||
import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory';
|
import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory';
|
||||||
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
|
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
|
|
||||||
import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view';
|
import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view';
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export function runCompilerCommonTests() {
|
||||||
if (isBlank(urlData)) {
|
if (isBlank(urlData)) {
|
||||||
urlData = new Map();
|
urlData = new Map();
|
||||||
}
|
}
|
||||||
var tplLoader = new FakeTemplateLoader(urlData);
|
var tplLoader = new FakeViewLoader(urlData);
|
||||||
mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
|
mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
|
||||||
return new DomCompiler(mockStepFactory, tplLoader);
|
return new DomCompiler(mockStepFactory, tplLoader);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ var EMPTY_STEP = (parent, current, control) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeTemplateLoader extends TemplateLoader {
|
class FakeViewLoader extends ViewLoader {
|
||||||
_urlData: Map<string, string>;
|
_urlData: Map<string, string>;
|
||||||
constructor(urlData) {
|
constructor(urlData) {
|
||||||
super(null, null, null);
|
super(null, null, null);
|
||||||
|
|
|
@ -7,9 +7,7 @@ export function main() {
|
||||||
describe('StyleUrlResolver', () => {
|
describe('StyleUrlResolver', () => {
|
||||||
let styleUrlResolver;
|
let styleUrlResolver;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => { styleUrlResolver = new StyleUrlResolver(new UrlResolver()); });
|
||||||
styleUrlResolver = new StyleUrlResolver(new UrlResolver());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should resolve "url()" urls', () => {
|
it('should resolve "url()" urls', () => {
|
||||||
var css = `
|
var css = `
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
xit,
|
xit,
|
||||||
} from 'angular2/test_lib';
|
} from 'angular2/test_lib';
|
||||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner';
|
import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner';
|
||||||
import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver';
|
import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver';
|
||||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||||
|
@ -23,7 +23,7 @@ import {XHR} from 'angular2/src/render/xhr';
|
||||||
import {MockXHR} from 'angular2/src/render/xhr_mock';
|
import {MockXHR} from 'angular2/src/render/xhr_mock';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('TemplateLoader', () => {
|
describe('ViewLoader', () => {
|
||||||
var loader, xhr, styleUrlResolver, urlResolver;
|
var loader, xhr, styleUrlResolver, urlResolver;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -31,7 +31,7 @@ export function main() {
|
||||||
urlResolver = new UrlResolver();
|
urlResolver = new UrlResolver();
|
||||||
styleUrlResolver = new StyleUrlResolver(urlResolver);
|
styleUrlResolver = new StyleUrlResolver(urlResolver);
|
||||||
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
||||||
loader = new TemplateLoader(xhr, styleInliner, styleUrlResolver);
|
loader = new ViewLoader(xhr, styleInliner, styleUrlResolver);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('html', () => {
|
describe('html', () => {
|
||||||
|
@ -71,7 +71,7 @@ export function main() {
|
||||||
xhr.reply('http://ng.io/foo.css', '/* foo.css */');
|
xhr.reply('http://ng.io/foo.css', '/* foo.css */');
|
||||||
|
|
||||||
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
||||||
let loader = new TemplateLoader(xhr, styleInliner, styleUrlResolver);
|
let loader = new ViewLoader(xhr, styleInliner, styleUrlResolver);
|
||||||
|
|
||||||
var view = new ViewDefinition({templateAbsUrl: 'http://ng.io/foo.html'});
|
var view = new ViewDefinition({templateAbsUrl: 'http://ng.io/foo.html'});
|
||||||
loader.load(view).then((el) => {
|
loader.load(view).then((el) => {
|
||||||
|
@ -168,7 +168,7 @@ export function main() {
|
||||||
xhr.reply('http://ng.io/foo.css', '/* foo.css */');
|
xhr.reply('http://ng.io/foo.css', '/* foo.css */');
|
||||||
|
|
||||||
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
let styleInliner = new StyleInliner(xhr, styleUrlResolver, urlResolver);
|
||||||
let loader = new TemplateLoader(xhr, styleInliner, styleUrlResolver);
|
let loader = new ViewLoader(xhr, styleInliner, styleUrlResolver);
|
||||||
|
|
||||||
var view = new ViewDefinition(
|
var view = new ViewDefinition(
|
||||||
{templateAbsUrl: 'http://ng.io/foo.html', styles: ['@import "foo.css";']});
|
{templateAbsUrl: 'http://ng.io/foo.html', styles: ['@import "foo.css";']});
|
|
@ -13,7 +13,7 @@ import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||||
|
|
||||||
import * as viewModule from 'angular2/src/core/annotations_impl/view';
|
import * as viewModule from 'angular2/src/core/annotations_impl/view';
|
||||||
import {Component, Directive, View} from 'angular2/angular2';
|
import {Component, Directive, View} from 'angular2/angular2';
|
||||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
|
||||||
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
||||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||||
import {AppRootUrl} from 'angular2/src/services/app_root_url';
|
import {AppRootUrl} from 'angular2/src/services/app_root_url';
|
||||||
|
@ -38,7 +38,7 @@ export function main() {
|
||||||
var urlResolver = new UrlResolver();
|
var urlResolver = new UrlResolver();
|
||||||
var shadowDomStrategy = new NativeShadowDomStrategy();
|
var shadowDomStrategy = new NativeShadowDomStrategy();
|
||||||
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
|
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
|
||||||
new TemplateLoader(null, null, null));
|
new ViewLoader(null, null, null));
|
||||||
var compiler = new Compiler(
|
var compiler = new Compiler(
|
||||||
reader, cache, templateResolver, new ComponentUrlMapper(), urlResolver, renderCompiler,
|
reader, cache, templateResolver, new ComponentUrlMapper(), urlResolver, renderCompiler,
|
||||||
new ProtoViewFactory(new DynamicChangeDetection(null)), new FakeAppRootUrl());
|
new ProtoViewFactory(new DynamicChangeDetection(null)), new FakeAppRootUrl());
|
||||||
|
|
Loading…
Reference in New Issue