templateFormatter: add cases() template function; Tags: add set/get tag functions to store/retrieve variables within tags
This commit is contained in:
parent
a8d274c054
commit
96b2d33423
2 changed files with 14 additions and 0 deletions
|
@ -196,9 +196,17 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig, ITagsPluginPer
|
|||
|
||||
// Format the string
|
||||
try {
|
||||
const dynamicVars = {};
|
||||
body = await renderTemplate(body, {
|
||||
args: tagArgs,
|
||||
...this.tagFunctions,
|
||||
set(name, val) {
|
||||
if (typeof name !== "string") return;
|
||||
dynamicVars[name] = val;
|
||||
},
|
||||
get(name) {
|
||||
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof TemplateParseError) {
|
||||
|
|
|
@ -342,6 +342,12 @@ const baseValues = {
|
|||
return result / parseFloat(arg);
|
||||
}, args[0]);
|
||||
},
|
||||
cases(mod, ...cases) {
|
||||
if (cases.length === 0) return "";
|
||||
if (isNaN(mod)) return "";
|
||||
mod = parseInt(mod, 10) - 1;
|
||||
return cases[Math.max(0, mod % cases.length)];
|
||||
},
|
||||
};
|
||||
|
||||
export async function renderTemplate(template: string, values = {}, includeBaseValues = true) {
|
||||
|
|
Loading…
Add table
Reference in a new issue