mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: tmpl access to action method vars
This commit is contained in:
parent
cbcdc8434f
commit
70c18fc7b2
@ -1,5 +1,4 @@
|
|||||||
test <b>app</b>
|
Test <b>app</b>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
<h1>@hello</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -28,6 +28,7 @@ pub fn (mut app App) json_endpoint() {
|
|||||||
pub fn (mut app App) index() {
|
pub fn (mut app App) index() {
|
||||||
app.cnt++
|
app.cnt++
|
||||||
//app.vweb.text('Hello world from vweb')
|
//app.vweb.text('Hello world from vweb')
|
||||||
|
hello := 'Hello world from vweb'
|
||||||
$vweb.html()
|
$vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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{
|
return ast.ComptimeCall{
|
||||||
is_vweb: true
|
is_vweb: true
|
||||||
vweb_tmpl: file
|
vweb_tmpl: file
|
||||||
|
Loading…
Reference in New Issue
Block a user