Comments (3)
i use jinjava .1.0.9
from jinjava.
I could create Context c for one time , and create a child of c with event.
But another problem: complex template like "Hello, {%if name is defined %} {{name}} {% endif %}" will raise a Exception with null as the first parameter when create TokenParser.
Map<String, Object> bindings = new HashMap<>();
bindings.put("name", "Jared");
Jinjava jinjava = new Jinjava();
Context c = jinjava.getGlobalContext();
c.registerFilter(f);
String template = "Hello, {{name}} {% endif %}";
TokenParser t = new TokenParser(null, template);
Node parsedTemplate = TreeParser.parseTree(t);
long s = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
Context cc = new Context(c, bindings);
JinjavaInterpreter interpreter = new JinjavaInterpreter(jinjava,
cc, null);
// Node parsedTemplate = interpreter.parse(template);
String ss = interpreter.render(template);
}
System.out.println(System.currentTimeMillis() - s);
from jinjava.
So what you can do is similar to how we construct the JinjavaInterpreter
instances in the Jinjava
wrapper class, by creating children of the context and configs, respectively. That way, they can inherit defined filters and such without collecting unnecessary state.
Context context = new Context(globalContext, bindings);
JinjavaInterpreter parentInterpreter = JinjavaInterpreter.getCurrent();
if(parentInterpreter != null) {
renderConfig = parentInterpreter.getConfig();
}
JinjavaInterpreter interpreter = new JinjavaInterpreter(this, context, renderConfig);
JinjavaInterpreter.pushCurrent(interpreter);
from jinjava.
Related Issues (20)
- CVEs in current version: 2.7.0
- time for 2.7.1 / 2.8.0 ?
- Unexpected behavior comparing empty strings to 0
- Is the expression interpolation recursive? HOT 1
- Problem with using the function in nested interpretation HOT 2
- SnakeYAML 1.27 vulnerability in Jinjava 2.7.1 HOT 1
- Add {% hubl %} tag
- Maps in string representation in Сontext
- Support for "with" statement
- Resolve function with map like contructs HOT 1
- Mixing include and extends does not work
- Fix CVEs in version 2.7.1
- Inconsistent implementation with jinja2 HOT 1
- trouble with coercision in test
- Add support for java records HOT 1
- Rendering template with custom function in Scala throws NullPointerException HOT 4
- [question] receiving fixes flow // GHSA-h75v-3vvj-5mfj CVE-2024-34064 HOT 2
- upgrade commons-net to 3.10.0
- Fix eager execution handling of `{% print foo|render %}`
- Remove #jinja2 instructions from the output HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jinjava.