mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
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
|
// Format the string
|
||||||
try {
|
try {
|
||||||
|
const dynamicVars = {};
|
||||||
body = await renderTemplate(body, {
|
body = await renderTemplate(body, {
|
||||||
args: tagArgs,
|
args: tagArgs,
|
||||||
...this.tagFunctions,
|
...this.tagFunctions,
|
||||||
|
set(name, val) {
|
||||||
|
if (typeof name !== "string") return;
|
||||||
|
dynamicVars[name] = val;
|
||||||
|
},
|
||||||
|
get(name) {
|
||||||
|
return dynamicVars[name] == null ? "" : dynamicVars[name];
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
if (e instanceof TemplateParseError) {
|
||||||
|
|
|
@ -342,6 +342,12 @@ const baseValues = {
|
||||||
return result / parseFloat(arg);
|
return result / parseFloat(arg);
|
||||||
}, args[0]);
|
}, 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) {
|
export async function renderTemplate(template: string, values = {}, includeBaseValues = true) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue