Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation for truncate function #594

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main/java/com/hubspot/jinjava/lib/fn/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,29 @@ public static PyishDate stringToTime(String datetimeString, String datetimeForma
@JinjavaDoc(
value = "truncates a given string to a specified length",
params = {
@JinjavaParam("s"),
@JinjavaParam(value = "length", type = "number", defaultValue = "255"),
@JinjavaParam(value = "end", defaultValue = "...")
@JinjavaParam(
value = "string",
type = "string",
desc = "String to be truncated",
required = true
),
@JinjavaParam(
value = "length",
type = "number",
defaultValue = "255",
desc = "Specifies the length at which to truncate the text (includes HTML characters)"
),
@JinjavaParam(
value = "killwords",
type = "boolean",
defaultValue = "False",
desc = "If true, the string will cut text at length"
),
@JinjavaParam(
value = "end",
defaultValue = "...",
desc = "The characters that will be added to indicate where the text was truncated"
)
}
)
public static Object truncate(Object var, Object... arg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.hubspot.jinjava.Jinjava;
import com.hubspot.jinjava.JinjavaConfig;
Expand Down Expand Up @@ -106,6 +107,11 @@ public String getBarFoo() {
public String getBarFoo1() {
return bar;
}

@JsonIgnore
public String getBarHidden() {
return bar;
}
}

@Test
Expand All @@ -128,6 +134,11 @@ public void multiWordNumberSnakeCase() {
assertThat(interpreter.resolveProperty(new Foo("a"), "bar_foo_1")).isEqualTo("a");
}

@Test
public void jsonIgnore() {
assertThat(interpreter.resolveProperty(new Foo("a"), "barHidden")).isEqualTo("a");
}

@Test
public void triesBeanMethodFirst() {
assertThat(
Expand Down