-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ControlRendererFactory.java
38 lines (31 loc) · 1.17 KB
/
ControlRendererFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package nu.marginalia.control;
import com.google.inject.Inject;
import lombok.SneakyThrows;
import nu.marginalia.nodecfg.NodeConfigurationService;
import nu.marginalia.renderer.RendererFactory;
import java.util.Map;
/** Wrapper for the renderer factory that adds global context
* with the nodes listing
*/
public class ControlRendererFactory {
private final RendererFactory rendererFactory;
private final NodeConfigurationService nodeConfigurationService;
@Inject
public ControlRendererFactory(RendererFactory rendererFactory,
NodeConfigurationService nodeConfigurationService)
{
this.rendererFactory = rendererFactory;
this.nodeConfigurationService = nodeConfigurationService;
}
@SneakyThrows
public Renderer renderer(String template) {
Map<String, Object> globalContext = Map.of(
"nodes", nodeConfigurationService.getAll()
);
var baseRenderer = rendererFactory.renderer(template);
return (context) -> baseRenderer.render(context, Map.of("global-context", globalContext));
}
public interface Renderer {
String render(Object context);
}
}