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

No public description #2008

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
8 changes: 7 additions & 1 deletion java/src/com/google/template/soy/jbcsrc/api/SoySauce.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.template.soy.data.SanitizedContent;
import com.google.template.soy.data.SanitizedContent.ContentKind;
import com.google.template.soy.data.SoyInjector;
import com.google.template.soy.data.SoyTemplate;
import com.google.template.soy.data.SoyTemplateData;
Expand Down Expand Up @@ -147,6 +146,13 @@ default Renderer setIj(SoyTemplateData data) {
@CanIgnoreReturnValue
Renderer setPluginInstances(Map<String, ? extends Supplier<Object>> pluginInstances);

/**
* Overrides plugin instances associated with the SoySauce instance for a given renderer, useful
* in cases where you want separate instance of a soy plugin for different soy renderers.
*/
@CanIgnoreReturnValue
Renderer overridePluginInstances(Map<String, ? extends Supplier<Object>> newPluginInstances);

/** Configures the {@code {css ..}} renaming map. */
@CanIgnoreReturnValue
Renderer setCssRenamingMap(SoyCssRenamingMap cssRenamingMap);
Expand Down
10 changes: 10 additions & 0 deletions java/src/com/google/template/soy/jbcsrc/api/SoySauceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.template.soy.data.SoyValueProvider;
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
import com.google.template.soy.data.internal.ParamStore;
import com.google.template.soy.jbcsrc.api.SoySauce.WriteContinuation;
import com.google.template.soy.jbcsrc.shared.CompiledTemplate;
import com.google.template.soy.jbcsrc.shared.CompiledTemplates;
import com.google.template.soy.jbcsrc.shared.RenderContext;
Expand Down Expand Up @@ -213,6 +214,15 @@ public RendererImpl setPluginInstances(
return this;
}

@CanIgnoreReturnValue
@Override
public RendererImpl overridePluginInstances(
Map<String, ? extends Supplier<Object>> newPluginInstances) {
this.pluginInstances =
SoySauceImpl.this.pluginInstances.combineOrOverride(newPluginInstances);
return this;
}

@CanIgnoreReturnValue
@Override
public RendererImpl setData(Map<String, ?> record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

Expand Down Expand Up @@ -56,4 +57,12 @@ public PluginInstances combine(Map<String, ? extends Supplier<Object>> morePlugi
.putAll(morePlugins)
.build());
}

public PluginInstances combineOrOverride(
Map<String, ? extends Supplier<Object>> newPluginInstances) {
Map<String, Supplier<Object>> overriddenPluginInstances = new HashMap<>();
overriddenPluginInstances.putAll(newPluginInstances);
this.pluginInstances.forEach(overriddenPluginInstances::putIfAbsent);
return new PluginInstances(ImmutableMap.copyOf(overriddenPluginInstances));
}
}
Loading