Skip to content

Commit

Permalink
Calls new render limit method from filter
Browse files Browse the repository at this point in the history
  • Loading branch information
asegal-hs committed Nov 7, 2023
1 parent baae46e commit 0a82efb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
public class JinjavaInterpreter implements PyishSerializable {
public static final String IGNORED_OUTPUT_FROM_EXTENDS_NOTE =
"ignored_output_from_extends";
public static final long NO_LIMIT = -1;

private final Multimap<String, BlockInfo> blocks = ArrayListMultimap.create();
private final LinkedList<Node> extendParentRoots = new LinkedList<>();
private final Map<String, RevertibleObject> revertibleObjects = new HashMap<>();
Expand All @@ -94,7 +96,6 @@ public class JinjavaInterpreter implements PyishSerializable {
private final Set<Integer> errorSet = new HashSet<>();

private static final int MAX_ERROR_SIZE = 100;
private static final long NO_LIMIT = -1;

public JinjavaInterpreter(
Jinjava application,
Expand Down Expand Up @@ -260,7 +261,11 @@ public String renderFlat(String template) {
* @return rendered result
*/
public String render(String template) {
return render(parse(template), true);
return render(template, NO_LIMIT);
}

public String render(String template, long renderLimit) {
return render(parse(template), true, renderLimit);
}

/**
Expand All @@ -287,7 +292,7 @@ public String render(Node root, boolean processExtendRoots) {
}

/**
* Rendee the given root node to a certain limit, processing extend parents.
* Render the given root node to a certain limit, processing extend parents.
* @param root
* node to render
* @param renderLimit
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/hubspot/jinjava/lib/filter/RenderFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import java.util.Objects;
import org.apache.commons.lang3.math.NumberUtils;

@JinjavaDoc(
value = "Renders a template string early to be used by other filters and functions",
Expand All @@ -25,11 +26,11 @@ public String getName() {
@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
if (args.length > 0) {
/*
This means a render limit length has been provided.
Here we begin a left to right render where we add to an HTML string until the length reaches a certain limit.
*/
return interpreter.render(Objects.toString(var));
String firstArg = args[0];
return interpreter.render(
Objects.toString(var),
NumberUtils.toLong(firstArg, JinjavaInterpreter.NO_LIMIT)
);
}
return interpreter.render(Objects.toString(var));
}
Expand Down

0 comments on commit 0a82efb

Please sign in to comment.