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);
}
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");
}
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();
}
Aggregations