Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 633877328
  • Loading branch information
Soy Authors authored and copybara-github committed May 16, 2024
1 parent 4e715f3 commit f833225
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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));
}
}

0 comments on commit f833225

Please sign in to comment.