vweb: tmpl access to action method vars

pull/5260/head
joe-conigliaro 2020-06-07 21:26:47 +10:00
parent cbcdc8434f
commit 70c18fc7b2
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
3 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,4 @@
test <b>app</b>
Test <b>app</b>
<br>
<h1>@hello</h1>
<hr>

View File

@ -28,6 +28,7 @@ pub fn (mut app App) json_endpoint() {
pub fn (mut app App) index() {
app.cnt++
//app.vweb.text('Hello world from vweb')
hello := 'Hello world from vweb'
$vweb.html()
}

View File

@ -113,6 +113,22 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
}
}
*/
// copy vars from current fn scope into vweb_tmpl scope
for stmt in file.stmts {
if stmt is ast.FnDecl {
fn_decl := stmt as ast.FnDecl
if fn_decl.name == 'vweb_tmpl' {
body_scope := file.scope.innermost(fn_decl.body_pos.pos)
for _, obj in p.scope.objects {
if obj is ast.Var {
v := obj as ast.Var
body_scope.register(v.name, *v)
}
}
break
}
}
}
return ast.ComptimeCall{
is_vweb: true
vweb_tmpl: file