@@ -94,6 +94,7 @@ public class JinjavaInterpreter implements PyishSerializable {
9494 private final Set <Integer > errorSet = new HashSet <>();
9595
9696 private static final int MAX_ERROR_SIZE = 100 ;
97+ private static final long NO_LIMIT = -1 ;
9798
9899 public JinjavaInterpreter (
99100 Jinjava application ,
@@ -263,14 +264,38 @@ public String render(String template) {
263264 }
264265
265266 /**
266- * Render the given root node, processing extend parents. Equivalent to render(root, true)
267+ * Render the given root node, processing extend parents. Equivalent to render(root, true, -1 )
267268 *
268269 * @param root
269270 * node to render
270271 * @return rendered result
271272 */
272273 public String render (Node root ) {
273- return render (root , true );
274+ return render (root , true , NO_LIMIT );
275+ }
276+
277+ /**
278+ * Render the given root node with an option to process extend parents.
279+ * Equivalent to render(root, processExtendRoots, -1).
280+ * @param root
281+ * node to render
282+ * @param processExtendRoots
283+ * @return
284+ */
285+ public String render (Node root , boolean processExtendRoots ) {
286+ return render (root , processExtendRoots , NO_LIMIT );
287+ }
288+
289+ /**
290+ * Rendee the given root node to a certain limit, processing extend parents.
291+ * @param root
292+ * node to render
293+ * @param renderLimit
294+ * the number of characters in response text
295+ * @return
296+ */
297+ public String render (Node root , long renderLimit ) {
298+ return render (root , true , renderLimit );
274299 }
275300
276301 /**
@@ -280,10 +305,15 @@ public String render(Node root) {
280305 * node to render
281306 * @param processExtendRoots
282307 * if true, also render all extend parents
308+ * @param renderLimit
309+ * the number of characters the result may contain
283310 * @return rendered result
284311 */
285- public String render (Node root , boolean processExtendRoots ) {
286- OutputList output = new OutputList (config .getMaxOutputSize ());
312+ public String render (Node root , boolean processExtendRoots , long renderLimit ) {
313+ long maxOutput = (renderLimit == NO_LIMIT )
314+ ? config .getMaxOutputSize ()
315+ : (Math .min (renderLimit , config .getMaxOutputSize ()));
316+ OutputList output = new OutputList (maxOutput );
287317
288318 for (Node node : root .getChildren ()) {
289319 lineNumber = node .getLineNumber ();
0 commit comments