Search in sources :

Example 16 with SoyPrintDirective

use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.

the class SoyNodeCompiler method getEscapingDirectivesList.

private Expression getEscapingDirectivesList(CallNode node) {
    ImmutableList<SoyPrintDirective> escapingDirectives = node.getEscapingDirectives();
    List<Expression> directiveExprs = new ArrayList<>(escapingDirectives.size());
    for (SoyPrintDirective directive : escapingDirectives) {
        directiveExprs.add(parameterLookup.getRenderContext().getPrintDirective(directive.getName()));
    }
    return BytecodeUtils.asImmutableList(directiveExprs);
}
Also used : SoyPrintDirective(com.google.template.soy.shared.restricted.SoyPrintDirective) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression) ArrayList(java.util.ArrayList)

Example 17 with SoyPrintDirective

use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.

the class SharedModuleTest method testStreamingPrintDirectives.

// This test serves to document exactly which escaping directives do and do not support streaming
// in jbcsrc.  If someone adds a new one, they will need to update this test and document why
// it doesn't support streaming.
@Test
public void testStreamingPrintDirectives() throws Exception {
    ImmutableSet.Builder<String> streamingPrintDirectives = ImmutableSet.builder();
    ImmutableSet.Builder<String> nonStreamingPrintDirectives = ImmutableSet.builder();
    for (SoyPrintDirective directive : injector.getInstance(new Key<Set<SoyPrintDirective>>() {
    })) {
        if (directive instanceof SoyJbcSrcPrintDirective.Streamable) {
            streamingPrintDirectives.add(directive.getName());
        } else {
            nonStreamingPrintDirectives.add(directive.getName());
        }
    }
    assertThat(streamingPrintDirectives.build()).containsExactly("|escapeHtml", "|blessStringAsTrustedResourceUrlForLegacy", "|id", "|escapeCssString", "|normalizeHtml", "|escapeJsString", "|escapeHtmlRcdata", "|escapeJsRegex", "|text", "|noAutoescape", "|normalizeUri", "|changeNewlineToBr", "|bidiSpanWrap", "|bidiUnicodeWrap", "|insertWordBreaks", "|truncate", "|cleanHtml", "|filterHtmlAttributes");
    assertThat(nonStreamingPrintDirectives.build()).containsExactly(// statements.
    "|escapeUri", "|formatNum", // buffer.
    "|filterHtmlElementName", "|filterCssValue", "|escapeJsValue", "|filterNormalizeUri", "|filterNormalizeMediaUri", "|filterTrustedResourceUri", "|filterImageDataUri", "|filterSipUri", "|filterTelUri", // Sanitizers.stripHtmlTags method but it is probably a good idea.
    "|escapeHtmlAttribute", "|escapeHtmlAttributeNospace");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) SoyPrintDirective(com.google.template.soy.shared.restricted.SoyPrintDirective) Test(org.junit.Test)

Example 18 with SoyPrintDirective

use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.

the class GenCallCodeUtilsTest method getCallExprTextHelper.

private static String getCallExprTextHelper(String callSource, ImmutableList<String> escapingDirectives) {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(callSource).parse().fileSet();
    CallNode callNode = (CallNode) SharedTestUtils.getNode(soyTree, 0);
    // Manually setting the escaping directives.
    ImmutableMap<String, ? extends SoyPrintDirective> directives = INJECTOR.getInstance(new Key<ImmutableMap<String, ? extends SoyPrintDirective>>() {
    });
    callNode.setEscapingDirectives(escapingDirectives.stream().map(directives::get).collect(toImmutableList()));
    GenCallCodeUtils genCallCodeUtils = JsSrcTestUtils.createGenCallCodeUtils();
    UniqueNameGenerator nameGenerator = JsSrcNameGenerators.forLocalVariables();
    CodeChunk call = genCallCodeUtils.gen(callNode, AliasUtils.IDENTITY_ALIASES, TranslationContext.of(SoyToJsVariableMappings.forNewTemplate(), CodeChunk.Generator.create(nameGenerator), nameGenerator), ErrorReporter.exploding());
    return call.getCode();
}
Also used : SoyPrintDirective(com.google.template.soy.shared.restricted.SoyPrintDirective) CodeChunk(com.google.template.soy.jssrc.dsl.CodeChunk) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) CallNode(com.google.template.soy.soytree.CallNode) UniqueNameGenerator(com.google.template.soy.base.internal.UniqueNameGenerator) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)18 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)4 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)3 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)3 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)3 SoyPySrcPrintDirective (com.google.template.soy.pysrc.restricted.SoyPySrcPrintDirective)3 PrintDirectiveNode (com.google.template.soy.soytree.PrintDirectiveNode)3 ArrayList (java.util.ArrayList)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 SoyValue (com.google.template.soy.data.SoyValue)2 Expression (com.google.template.soy.jbcsrc.restricted.Expression)2 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)2 Statement (com.google.template.soy.jbcsrc.restricted.Statement)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)1 UniqueNameGenerator (com.google.template.soy.base.internal.UniqueNameGenerator)1