Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT SUBMIT - this is just a prototye #2002

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions java/src/com/google/template/soy/jbcsrc/api/SoySauce.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.template.soy.data.LoggingAdvisingAppendable;
import com.google.template.soy.data.SanitizedContent;
import com.google.template.soy.data.SanitizedContent.ContentKind;
import com.google.template.soy.data.SoyInjector;
Expand Down Expand Up @@ -225,6 +226,19 @@ default WriteContinuation renderHtml(Appendable out) throws IOException {
return renderHtml(asAdvisingAppendable(out));
}

/**
* Renders the configured html template to the given appendable, returning a continuation. If
* captureLogs is true, logs are writtent to the {@link LoggingAdvisingAppendable}.
*
* <p>Verifies that the content type is {@link ContentKind.HTML} (corresponding to kind="html"
* in the template).
*
* <p>See {@link #renderHtml(AdvisingAppendable out)} for more details).
*/
@CheckReturnValue
WriteContinuation renderHtml(LoggingAdvisingAppendable out, boolean captureLogs)
throws IOException;

/**
* Renders the configured html template to a {@link SanitizedContent}. Verifies that the content
* type is {@link ContentKind.HTML} (corresponding to kind="html" in the template).
Expand Down
34 changes: 27 additions & 7 deletions java/src/com/google/template/soy/jbcsrc/api/SoySauceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.template.soy.data.LoggingAdvisingAppendable;
import com.google.template.soy.data.RecordProperty;
import com.google.template.soy.data.SanitizedContent;
import com.google.template.soy.data.SanitizedContent.ContentKind;
Expand Down Expand Up @@ -278,6 +279,12 @@ public WriteContinuation renderHtml(AdvisingAppendable out) throws IOException {
return startRender(out, ContentKind.HTML);
}

@Override
public WriteContinuation renderHtml(LoggingAdvisingAppendable out, boolean captureLogs)
throws IOException {
return startRender(out, ContentKind.HTML, captureLogs);
}

@Override
public Continuation<SanitizedContent> renderHtml() {
return startRenderToSanitizedContent(ContentKind.HTML);
Expand Down Expand Up @@ -359,11 +366,21 @@ Continuation<T> startRenderToValue(ContentKind contentKind) {

private WriteContinuation startRender(AdvisingAppendable out, ContentKind contentKind)
throws IOException {
return startRender(out, contentKind, /* captureLogs= */ false);
}

private WriteContinuation startRender(
AdvisingAppendable out, ContentKind contentKind, boolean captureLogs) throws IOException {
enforceContentKind(contentKind);

ParamStore params = data == null ? ParamStore.EMPTY_INSTANCE : data;
RenderContext context = makeContext();
OutputAppendable output = OutputAppendable.create(out, context.getLogger());
LoggingAdvisingAppendable output;
if (captureLogs && out instanceof LoggingAdvisingAppendable) {
output = (LoggingAdvisingAppendable) out;
} else {
output = OutputAppendable.create(out, context.getLogger());
}
return doRender(template, params, output, context);
}

Expand All @@ -386,7 +403,10 @@ private void enforceContentKind(ContentKind expectedContentKind) {
}

private static WriteContinuation doRender(
CompiledTemplate template, ParamStore params, OutputAppendable output, RenderContext context)
CompiledTemplate template,
ParamStore params,
LoggingAdvisingAppendable output,
RenderContext context)
throws IOException {
RenderResult result;
try {
Expand Down Expand Up @@ -420,7 +440,7 @@ abstract static class ContinuationImpl {
// ThreadSafety guaranteed by the guarded write on hasContinueBeenCalled
final CompiledTemplate template;
final ParamStore params;
final OutputAppendable output;
final LoggingAdvisingAppendable output;
final RenderContext context;

boolean hasContinueBeenCalled;
Expand All @@ -433,7 +453,7 @@ public RenderResult result() {
RenderResult result,
CompiledTemplate template,
ParamStore params,
OutputAppendable output,
LoggingAdvisingAppendable output,
RenderContext context) {
checkArgument(!result.isDone());
this.result = checkNotNull(result);
Expand All @@ -457,7 +477,7 @@ private static final class WriteContinuationImpl extends ContinuationImpl
RenderResult result,
CompiledTemplate template,
ParamStore params,
OutputAppendable output,
LoggingAdvisingAppendable output,
RenderContext context) {
super(result, template, params, output, context);
}
Expand All @@ -475,7 +495,7 @@ Continuation<T> doRenderToValue(
StringBuilder underlying,
CompiledTemplate template,
ParamStore params,
OutputAppendable output,
LoggingAdvisingAppendable output,
RenderContext context) {
RenderResult result;
try {
Expand Down Expand Up @@ -519,7 +539,7 @@ private static final class ValueContinuationImpl<
RenderResult result,
CompiledTemplate template,
ParamStore params,
OutputAppendable output,
LoggingAdvisingAppendable output,
RenderContext context) {
super(result, template, params, output, context);
this.targetKind = checkNotNull(targetKind);
Expand Down
Loading