use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class SanitizersTest method testFilterNoAutoescapeStreamingNoContentKind.
@Test
public void testFilterNoAutoescapeStreamingNoContentKind() throws IOException {
BufferingAppendable buffer = LoggingAdvisingAppendable.buffering();
LoggingAdvisingAppendable escapingBuffer = Sanitizers.filterNoAutoescapeStreaming(buffer);
escapingBuffer.append("foo");
assertThat(buffer.getAndClearBuffer()).isEqualTo("foo");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class SanitizersTest method testFilterNoAutoescapeStreamingHtml.
@Test
public void testFilterNoAutoescapeStreamingHtml() throws IOException {
BufferingAppendable buffer = LoggingAdvisingAppendable.buffering();
LoggingAdvisingAppendable escapingBuffer = Sanitizers.filterNoAutoescapeStreaming(buffer);
escapingBuffer.setSanitizedContentKind(ContentKind.HTML);
escapingBuffer.append("foo");
assertThat(buffer.getAndClearBuffer()).isEqualTo("foo");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class DetachStateTest method testDetachOnUnResolvedProvider.
@Test
public void testDetachOnUnResolvedProvider() throws IOException {
SettableFuture<String> future = SettableFuture.create();
CompiledTemplates templates = TemplateTester.compileTemplateBody("{@param foo : string}", "prefix{sp}{$foo}{sp}suffix");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
CompiledTemplate template = factory.create(asRecord(ImmutableMap.of("foo", future)), EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
RenderResult result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isEqualTo(future);
assertThat(output.toString()).isEqualTo("prefix ");
// No progress is made, our caller is an idiot and didn't wait for the future
result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isEqualTo(future);
assertThat(output.toString()).isEqualTo("prefix ");
future.set("future");
result = template.render(output, context);
assertThat(result).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("prefix future suffix");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class DetachStateTest method testDetachOnParamTransclusion.
@Test
public void testDetachOnParamTransclusion() throws IOException {
CompiledTemplates templates = TemplateTester.compileFile("{namespace ns}", "", "/** */", "{template .caller}", " {@param callerParam : string}", " {call .callee}", " {param calleeParam kind=\"text\"}", " prefix {$callerParam} suffix", " {/param}", " {/call}", "{/template}", "", "/** */", "{template .callee}", " {@param calleeParam : string}", " {$calleeParam}", "{/template}", "");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.caller");
RenderContext context = getDefaultContext(templates);
SettableFuture<String> param = SettableFuture.create();
SoyRecord params = asRecord(ImmutableMap.of("callerParam", param));
CompiledTemplate template = factory.create(params, EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
assertThat(template.render(output, context)).isEqualTo(RenderResult.continueAfter(param));
assertThat(output.toString()).isEqualTo("prefix ");
param.set("foo");
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("prefix foo suffix");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class ProtoSupportTest method render.
private String render(CompiledTemplates templates, String name, SoyRecord params) {
CompiledTemplate caller = templates.getTemplateFactory(name).create(params, EMPTY_DICT);
BufferingAppendable sb = LoggingAdvisingAppendable.buffering();
try {
assertThat(caller.render(sb, getDefaultContext(templates))).isEqualTo(RenderResult.done());
} catch (IOException e) {
throw new RuntimeException(e);
}
return sb.toString();
}
Aggregations