Skip to content

Commit

Permalink
add tag list.sub_lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 18, 2020
1 parent 983fa4a commit 7d875d3
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,34 @@ public static void registerTags() {
return output;
});

// <--[tag]
// @attribute <ListTag.sub_lists[<#>]>
// @returns ListTag(ListTag)
// @description
// returns a list containing sublists of this list capped to a specific length.
// For example, a list of a|b|c|d|e|f .sub_lists[2] will return a list containing lists "a|b", "c|d", and "e|f".
// -->
registerTag("sub_lists", (attribute, object) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("list.sub_lists[...] tag must have an input.");
return null;
}
int subListLength = Math.max(1, attribute.getIntContext(1));
ListTag output = new ListTag();
ListTag building = new ListTag();
for (int i = 0; i < object.size(); i++) {
building.addObject(object.getObject(i));
if (building.size() == subListLength) {
output.addObject(building);
building = new ListTag();
}
}
if (!building.isEmpty()) {
output.addObject(building);
}
return output;
});

// <--[tag]
// @attribute <ListTag.space_separated>
// @returns ElementTag
Expand Down Expand Up @@ -603,7 +631,6 @@ public static void registerTags() {
// character, make note that it is CASE SENSITIVE.
// For example: .get_sub_items[1].split_by[-] on a list of "one-alpha|two-beta" will return "one|two".
// -->

String split = "/";
if (attribute.startsWith("split_by", 2)) {
if (attribute.hasContext(2) && attribute.getContext(2).length() > 0) {
Expand Down Expand Up @@ -1652,8 +1679,7 @@ else if (res > 0) {
ListTag newlist = new ListTag();
try {
for (ObjectTag obj : object.objectForms) {
Attribute tempAttrib = new Attribute(tag,
attribute.getScriptEntry(), attribute.context);
Attribute tempAttrib = new Attribute(tag, attribute.getScriptEntry(), attribute.context);
tempAttrib.setHadAlternative(true);
ObjectTag objs = CoreUtilities.autoAttribTyped(obj, tempAttrib);
if ((objs == null) ? defaultValue : CoreUtilities.equalsIgnoreCase(objs.toString(), "true")) {
Expand Down Expand Up @@ -1700,8 +1726,7 @@ else if (marks == 0 && c == '|' && tag.charAt(i + 1) == '|') {
}
try {
for (ObjectTag obj : object.objectForms) {
Attribute tempAttrib = new Attribute(tag,
attribute.getScriptEntry(), attribute.context);
Attribute tempAttrib = new Attribute(tag, attribute.getScriptEntry(), attribute.context);
tempAttrib.setHadAlternative(attribute.hasAlternative() || fallback);
ObjectTag objs = CoreUtilities.autoAttribTyped(obj, tempAttrib);
if (objs == null) {
Expand Down

0 comments on commit 7d875d3

Please sign in to comment.