feat(dart/transform): Inline templateUrl
values
Modify DirectiveProcessor to inline `templateUrl` values to avoid making additional browser requests. Closes #1035
This commit is contained in:
@ -3,10 +3,10 @@ library angular2.test.transform.directive_processor.all_tests;
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/transform/directive_processor/rewriter.dart';
|
||||
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
||||
import '../common/read_file.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../common/read_file.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
@ -36,6 +36,9 @@ void allTests() {
|
||||
customDescriptors: [
|
||||
const AnnotationDescriptor('Soup', 'package:soup/soup.dart', 'Component'),
|
||||
]);
|
||||
|
||||
_testNgDeps(
|
||||
'should inline `templateUrl` values.', 'url_expression_files/hello.dart');
|
||||
}
|
||||
|
||||
void _testNgDeps(String name, String inputPath,
|
||||
@ -43,11 +46,13 @@ void _testNgDeps(String name, String inputPath,
|
||||
it(name, () async {
|
||||
var inputId = _assetIdForPath(inputPath);
|
||||
var reader = new TestAssetReader();
|
||||
var input = await reader.readAsString(inputId);
|
||||
if (assetId != null) {
|
||||
reader.addAsset(assetId, await reader.readAsString(inputId));
|
||||
inputId = assetId;
|
||||
}
|
||||
var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors);
|
||||
var proxyInputId = assetId != null ? assetId : inputId;
|
||||
var output =
|
||||
formatter.format(createNgDeps(input, proxyInputId, annotationMatcher));
|
||||
var output = formatter
|
||||
.format(await createNgDeps(reader, inputId, annotationMatcher));
|
||||
var expectedPath = path.join(path.dirname(inputPath), 'expected',
|
||||
path.basename(inputPath).replaceFirst('.dart', '.ng_deps.dart'));
|
||||
var expectedId = _assetIdForPath(expectedPath);
|
||||
|
@ -0,0 +1,20 @@
|
||||
library examples.src.hello_world.index_common_dart.ng_deps.dart;
|
||||
|
||||
import 'hello.dart';
|
||||
import 'package:angular2/angular2.dart'
|
||||
show bootstrap, Component, Directive, View, NgElement;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(HelloCmp, {
|
||||
'factory': () => new HelloCmp(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Component(selector: 'hello-app'),
|
||||
const View(template: r'''{{greeting}}''')
|
||||
]
|
||||
});
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
library examples.src.hello_world.index_common_dart;
|
||||
|
||||
import 'package:angular2/angular2.dart'
|
||||
show bootstrap, Component, Directive, View, NgElement;
|
||||
|
||||
@Component(selector: 'hello-app')
|
||||
@View(templateUrl: 'template.html')
|
||||
class HelloCmp {}
|
@ -0,0 +1 @@
|
||||
{{greeting}}
|
Reference in New Issue
Block a user