Skylar: render #1028

git-svn-id: svn://ultimatepp.org/upp/trunk@8411 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2015-05-04 11:25:19 +00:00
parent 7b0f760e88
commit bb25671ab2
2 changed files with 25 additions and 2 deletions

View file

@ -65,6 +65,23 @@ Value VariablesSet(const Vector<Value>&, const Renderer *r)
return Raw(html);
}
Value Render(const Vector<Value>& arg, const Renderer *r) {
if (arg.GetCount() < 1)
return "";
// create new Renderer, as we can not modify the one currently used
Renderer rr;
// copy variables so they are available in the rendered template too
for(int i = 1; i < r->Variables().GetCount(); i++) {
rr(r->Variables().GetKey(i), r->Variables()[i]);
}
// add arguments as variables
for(int i = 1; i < arg.GetCount(); i++) {
rr("_"+IntStr(i), arg[i]);
}
// render the template passed in first argument
return rr.Render(AsString(arg[0]));
}
INITBLOCK {
Compiler::Register("cycle", Cycle);
Compiler::Register("raw", RawFn);
@ -72,6 +89,7 @@ INITBLOCK {
Compiler::Register("post_identity", PostIdentity);
Compiler::Register("js_identity", JsIdentity);
Compiler::Register("set", VariablesSet);
Compiler::Register("render", Render);
};
};

View file

@ -248,7 +248,7 @@ element&]
[s0;3 &]
[ {{4495:5505h1;@(216) [s0; Function]
:: [s0; Description]
::^@2 [s0; [*C cycle(i, p0, p1, ..., pn)]]
::^@2 [s0; [*C cycle(i, p1, ..., pn)]]
:: [s0; Returns p`[i mod n`].]
:: [s0; [*C raw(text)]]
:: [s0; Returns argument as `"raw`" text that is not supposed to be
@ -264,5 +264,10 @@ CSRF attack prevention.]
AJAX POSTs.]
:: [s0; [*C set()]]
:: [s0; Returns html formatted list of current shared variables. Useful
for debugging.]}}&]
for debugging.]
:: [s0; [*C render(witz`_template, p1, ...)]]
:: [s0; Inserts another template into output. Current variables are
copied to new template, parameters p1... are copied as `$`_1,
`$`_2 etc. This is similar to using #include, but with it is
easier to pass arguments to included template this way.]}}&]
[s0; ]]