feat(CssProcessor): add support for CssTransformers

Closes #860
This commit is contained in:
Victor Berchet
2015-03-03 11:32:19 +01:00
committed by Misko Hevery
parent 9982520a23
commit 03793d0714
15 changed files with 71 additions and 20 deletions

View File

@ -99,7 +99,7 @@ function _injectorBindings(appComponentType): List<Binding> {
UrlResolver,
StyleUrlResolver,
StyleInliner,
CssProcessor,
bind(CssProcessor).toFactory(() => new CssProcessor(null), []),
];
}

View File

@ -1,6 +1,7 @@
import {DOM} from 'angular2/src/dom/dom_adapter';
import {isPresent} from 'angular2/src/facade/lang';
import {List} from 'angular2/src/facade/collection';
import {CompileStep} from './pipeline/compile_step';
import {CompileElement} from './pipeline/compile_element';
@ -10,9 +11,16 @@ import {ShadowDomStrategy} from './shadow_dom_strategy';
import {DirectiveMetadata} from './directive_metadata';
/**
* Processes the <style> tags during the compilation.
* Processes the <style> tags during the compilation:
* - Apply any given transformers,
* - Apply the shadow DOM strategy style step.
*/
export class CssProcessor {
_transformers: List<CssTransformer>;
constructor(transformers: List<CssTransformer>) {
this._transformers = transformers;
}
/**
* Returns a compile step to be added to the compiler pipeline.
@ -24,22 +32,35 @@ export class CssProcessor {
getCompileStep(cmpMetadata: DirectiveMetadata, shadowDomStrategy: ShadowDomStrategy,
templateUrl: string) {
var strategyStep = shadowDomStrategy.getStyleCompileStep(cmpMetadata, templateUrl);
return new _CssProcessorStep(strategyStep);
return new _CssProcessorStep(strategyStep, this._transformers);
}
}
export class CssTransformer {
transform(styleElement) {};
}
class _CssProcessorStep extends CompileStep {
_strategyStep: CompileStep;
_transformers: List<CssTransformer>;
constructor(strategyStep: CompileStep) {
constructor(strategyStep: CompileStep, transformers: List<CssTransformer>) {
super();
this._strategyStep = strategyStep;
this._transformers = transformers;
}
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
if (DOM.tagName(current.element) == 'STYLE') {
current.ignoreBindings = true;
if (isPresent(this._transformers)) {
var styleEl = current.element;
for (var i = 0; i < this._transformers.length; i++) {
this._transformers[i].transform(styleEl);
}
}
if (isPresent(this._strategyStep)) {
this._strategyStep.process(parent, current, control);
}