Search in sources :

Example 11 with SanitizedContentKind

use of com.google.template.soy.base.internal.SanitizedContentKind in project closure-templates by google.

the class LazyClosureCompiler method asRawTextOnly.

private Optional<Expression> asRawTextOnly(RenderUnitNode renderUnit) {
    StringBuilder builder = null;
    for (StandaloneNode child : renderUnit.getChildren()) {
        if (child instanceof RawTextNode) {
            if (builder == null) {
                builder = new StringBuilder();
            }
            builder.append(((RawTextNode) child).getRawText());
        } else {
            return Optional.absent();
        }
    }
    // TODO(lukes): ideally this would be a static final StringData field rather than reboxing each
    // time, but we don't (yet) have a good mechanism for that.
    SanitizedContentKind kind = renderUnit.getContentKind();
    Expression constant = constant(builder == null ? "" : builder.toString(), parentVariables);
    if (kind == null) {
        return Optional.<Expression>of(MethodRef.STRING_DATA_FOR_VALUE.invoke(constant));
    } else {
        return Optional.<Expression>of(MethodRef.ORDAIN_AS_SAFE.invoke(constant, constantSanitizedContentKindAsContentKind(kind)));
    }
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) Statement.returnExpression(com.google.template.soy.jbcsrc.restricted.Statement.returnExpression) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression) SanitizedContentKind(com.google.template.soy.base.internal.SanitizedContentKind) RawTextNode(com.google.template.soy.soytree.RawTextNode)

Example 12 with SanitizedContentKind

use of com.google.template.soy.base.internal.SanitizedContentKind in project closure-templates by google.

the class HtmlContextVisitor method visitTemplateNode.

@Override
protected void visitTemplateNode(TemplateNode node) {
    checkState(stateStack.isEmpty());
    SanitizedContentKind contentKind = node.getContentKind();
    pushState(contextForKind(contentKind));
    visitChildren(node);
    popState();
    checkState(stateStack.isEmpty());
}
Also used : SanitizedContentKind(com.google.template.soy.base.internal.SanitizedContentKind)

Aggregations

SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)12 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)4 TemplateDelegateNode (com.google.template.soy.soytree.TemplateDelegateNode)2 SourceLocation (com.google.template.soy.base.SourceLocation)1 Identifier (com.google.template.soy.base.internal.Identifier)1 VarRefNode (com.google.template.soy.exprtree.VarRefNode)1 Expression (com.google.template.soy.jbcsrc.restricted.Expression)1 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)1 Statement.returnExpression (com.google.template.soy.jbcsrc.restricted.Statement.returnExpression)1 TemplateMetadata (com.google.template.soy.jbcsrc.shared.TemplateMetadata)1 AutoescapeMode (com.google.template.soy.soytree.AutoescapeMode)1 CallBasicNode (com.google.template.soy.soytree.CallBasicNode)1 CallDelegateNode (com.google.template.soy.soytree.CallDelegateNode)1 CallParamContentNode (com.google.template.soy.soytree.CallParamContentNode)1 CallParamNode (com.google.template.soy.soytree.CallParamNode)1 HtmlAttributeValueNode (com.google.template.soy.soytree.HtmlAttributeValueNode)1 RawTextNode (com.google.template.soy.soytree.RawTextNode)1 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)1 LinkedHashSet (java.util.LinkedHashSet)1 CheckReturnValue (javax.annotation.CheckReturnValue)1