Skip to content

Commit

Permalink
Merge pull request #594 from HubSpot/fix-documentation
Browse files Browse the repository at this point in the history
Fix documentation for truncate function
  • Loading branch information
mattcoley committed Feb 8, 2021
2 parents 10fabb7 + 6227353 commit 30bc23b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
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

0 comments on commit 30bc23b

Please sign in to comment.