2015-03-20 15:37:09 -07:00
|
|
|
library angular2.transform.template_compiler.transformer;
|
2015-03-13 13:55:49 -07:00
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
2015-03-25 15:54:12 -07:00
|
|
|
import 'package:angular2/src/dom/html_adapter.dart';
|
2015-03-13 13:55:49 -07:00
|
|
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
|
|
|
|
import 'package:angular2/src/transform/common/formatter.dart';
|
|
|
|
|
import 'package:angular2/src/transform/common/logging.dart' as log;
|
|
|
|
|
import 'package:angular2/src/transform/common/names.dart';
|
|
|
|
|
import 'package:angular2/src/transform/common/options.dart';
|
|
|
|
|
import 'package:barback/barback.dart';
|
|
|
|
|
|
|
|
|
|
import 'generator.dart';
|
|
|
|
|
|
2015-04-17 13:01:07 -07:00
|
|
|
/// {@link Transformer} responsible for detecting and processing Angular 2 templates.
|
2015-03-13 13:55:49 -07:00
|
|
|
///
|
2015-04-17 13:01:07 -07:00
|
|
|
/// {@link TemplateCompiler} uses the Angular 2 `Compiler` to process the templates,
|
2015-03-13 13:55:49 -07:00
|
|
|
/// extracting information about what reflection is necessary to render and
|
|
|
|
|
/// use that template. It then generates code in place of those reflective
|
|
|
|
|
/// accesses.
|
2015-04-03 12:33:10 -07:00
|
|
|
class TemplateCompiler extends Transformer {
|
2015-03-13 13:55:49 -07:00
|
|
|
final TransformerOptions options;
|
|
|
|
|
|
2015-04-03 12:33:10 -07:00
|
|
|
TemplateCompiler(this.options);
|
2015-03-13 13:55:49 -07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future apply(Transform transform) async {
|
|
|
|
|
log.init(transform);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Html5LibDomAdapter.makeCurrent();
|
|
|
|
|
var id = transform.primaryInput.id;
|
|
|
|
|
var reader = new AssetReader.fromTransform(transform);
|
2015-05-29 16:34:51 -07:00
|
|
|
var transformedCode = formatter.format(await processTemplates(reader, id,
|
|
|
|
|
generateChangeDetectors: options.generateChangeDetectors));
|
2015-03-13 13:55:49 -07:00
|
|
|
transform.addOutput(new Asset.fromString(id, transformedCode));
|
|
|
|
|
} catch (ex, stackTrace) {
|
|
|
|
|
log.logger.error('Parsing ng templates failed.\n'
|
|
|
|
|
'Exception: $ex\n'
|
|
|
|
|
'Stack Trace: $stackTrace');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|