Skip to content

Commit 4d6ef04

Browse files
authored
Merge pull request #5934 from Baaaaaz/feature/5906-new-json-html-functions
json.toHtmlTable function
2 parents 4dfbaac + a5b7c52 commit 4d6ef04

3 files changed

Lines changed: 978 additions & 1 deletion

File tree

src/main/java/net/rptools/maptool/client/functions/json/JSONMacroFunctions.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public class JSONMacroFunctions extends AbstractFunction {
5757
/** Class used for Json Object related functions */
5858
private final JsonObjectFunctions jsonObjectFunctions;
5959

60+
/** Class used for Json Html related functions */
61+
private final JsonHtmlFunctions jsonHtmlFunctions;
62+
6063
/** The default delimiter to use for MT String lists. */
6164
private static final String DEFAULT_STRING_LIST_DELIM = ",";
6265

@@ -134,11 +137,13 @@ private JSONMacroFunctions() {
134137
"json.isSubset",
135138
"json.removeFirst",
136139
"json.rolls",
137-
"json.objrolls");
140+
"json.objrolls",
141+
"json.toHtmlTable");
138142

139143
typeConversion = new JsonMTSTypeConversion();
140144
jsonArrayFunctions = new JsonArrayFunctions(typeConversion);
141145
jsonObjectFunctions = new JsonObjectFunctions(typeConversion);
146+
jsonHtmlFunctions = new JsonHtmlFunctions(typeConversion);
142147
}
143148

144149
@Override
@@ -528,6 +533,24 @@ public Object childEvaluate(
528533
return jsonObjRolls(names, stats, rollString);
529534
}
530535
}
536+
case "json.toHtmlTable":
537+
{
538+
FunctionUtil.experimentalWarning(parser, resolver, functionName);
539+
FunctionUtil.checkNumberParam(functionName, args, 1, 2);
540+
541+
FunctionUtil.blockUntrustedMacro(functionName);
542+
JsonElement json = FunctionUtil.paramConvertedToJson(functionName, args, 0);
543+
544+
// 2nd arg options, 3rd arg options delimiter
545+
JsonObject options = new JsonObject();
546+
if (args.size() > 1) {
547+
options =
548+
FunctionUtil.jsonWithLowerCaseKeys(
549+
FunctionUtil.paramAsJsonObject(functionName, args, 1));
550+
}
551+
552+
return jsonHtmlFunctions.jsonToHtmlTable(functionName, json, options);
553+
}
531554
}
532555
throw new ParserException(I18N.getText("macro.function.general.unknownFunction", functionName));
533556
}

0 commit comments

Comments
 (0)