Skip to content

Commit 53c22cf

Browse files
committed
Provide better compatibility with old version
1 parent f338479 commit 53c22cf

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/main/java/de/neuland/pug4j/Pug4J.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package de.neuland.pug4j;
22

33
import de.neuland.pug4j.exceptions.PugCompilerException;
4-
import de.neuland.pug4j.model.PugModel;
5-
import de.neuland.pug4j.parser.Parser;
6-
import de.neuland.pug4j.parser.node.Node;
74
import de.neuland.pug4j.template.FileTemplateLoader;
85
import de.neuland.pug4j.template.PugTemplate;
96
import de.neuland.pug4j.template.ReaderTemplateLoader;

src/main/java/de/neuland/pug4j/PugConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ public PugConfiguration() {
8888
/**
8989
* Gets or creates the PugEngine instance. This method lazily initializes the engine
9090
* on first use and returns the cached instance on subsequent calls.
91-
*
91+
*
9292
* @return the PugEngine instance
9393
*/
94-
private PugEngine getOrCreateEngine() {
94+
public PugEngine getOrCreateEngine() {
9595
if (engine == null) {
9696
engine = PugEngine.builder()
9797
.templateLoader(templateLoader)

src/main/java/de/neuland/pug4j/template/PugTemplate.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package de.neuland.pug4j.template;
22

33
import de.neuland.pug4j.Pug4J.Mode;
4+
import de.neuland.pug4j.PugConfiguration;
5+
import de.neuland.pug4j.PugEngine;
6+
import de.neuland.pug4j.RenderContext;
7+
import de.neuland.pug4j.compiler.Compiler;
8+
import de.neuland.pug4j.exceptions.PugCompilerException;
9+
import de.neuland.pug4j.model.PugModel;
410
import de.neuland.pug4j.parser.node.DoctypeNode;
511
import de.neuland.pug4j.parser.node.Node;
12+
import java.io.Writer;
613

14+
@SuppressWarnings({"deprecation", "removal"})
715
public class PugTemplate {
816

917
private Node rootNode;
@@ -46,4 +54,27 @@ private void setDoctype(String name) {
4654
this.terse = "html".equals(name);
4755
this.xml = "xml".equals(name);
4856
}
57+
58+
/**
59+
* Deprecated in favor of rendering via PugEngine/RenderContext.
60+
*
61+
* @deprecated Since 3.0.0, forRemoval = true. Use PugEngine#render instead.
62+
*/
63+
@Deprecated(since = "3.0.0", forRemoval = true)
64+
@SuppressWarnings("deprecation")
65+
public void process(PugModel model, Writer writer, PugConfiguration pugConfiguration)
66+
throws PugCompilerException {
67+
// Bridge deprecated PugConfiguration to the new rendering pipeline
68+
PugEngine engine = pugConfiguration.getOrCreateEngine();
69+
70+
RenderContext context =
71+
RenderContext.builder()
72+
.prettyPrint(pugConfiguration.isPrettyPrint())
73+
.defaultMode(pugConfiguration.getMode())
74+
.globalVariables(pugConfiguration.getSharedVariables())
75+
.build();
76+
77+
Compiler compiler = new Compiler(this, context, engine);
78+
compiler.compile(model, writer);
79+
}
4980
}

0 commit comments

Comments
 (0)