fmt: handle $tmpl
parent
5efd393af2
commit
5e59718970
|
@ -807,7 +807,11 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
|||
}
|
||||
ast.ComptimeCall {
|
||||
if node.is_vweb {
|
||||
f.write('$' + 'vweb.html()')
|
||||
if node.method_name == 'html' {
|
||||
f.write('\$vweb.html()')
|
||||
} else {
|
||||
f.write("\$tmpl('$node.args_var')")
|
||||
}
|
||||
} else {
|
||||
f.write('${node.left}.\$${node.method_name}($node.args_var)')
|
||||
}
|
||||
|
|
|
@ -64,7 +64,6 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
|||
if !is_html {
|
||||
p.check(.string)
|
||||
}
|
||||
println('SSSS "$s"')
|
||||
p.check(.rpar)
|
||||
// Compile vweb html template to V code, parse that V code and embed the resulting V function
|
||||
// that returns an html string.
|
||||
|
@ -92,12 +91,11 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
|||
}
|
||||
// println('path is now "$path"')
|
||||
}
|
||||
if true || p.pref.is_verbose {
|
||||
if p.pref.is_verbose {
|
||||
println('>>> compiling comptime template file "$path"')
|
||||
}
|
||||
tmp_fn_name := p.cur_fn_name.replace('.', '__')
|
||||
v_code := tmpl.compile_file(path, tmp_fn_name)
|
||||
println('done')
|
||||
$if print_vweb_template_expansions ? {
|
||||
lines := v_code.split('\n')
|
||||
for i, line in lines {
|
||||
|
@ -108,7 +106,7 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
|||
start_pos: 0
|
||||
parent: p.global_scope
|
||||
}
|
||||
if true || p.pref.is_verbose {
|
||||
if p.pref.is_verbose {
|
||||
println('\n\n')
|
||||
println('>>> vweb template for $path:')
|
||||
println(v_code)
|
||||
|
@ -143,6 +141,7 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
|||
is_vweb: true
|
||||
vweb_tmpl: file
|
||||
method_name: n
|
||||
args_var: s
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ fn one() string {
|
|||
name := 'Peter'
|
||||
age := 25
|
||||
numbers := [1, 2, 3]
|
||||
return $tmpl('tmpl/1.txt')
|
||||
return $tmpl('vlib/v/tests/tmpl/1.txt')
|
||||
}
|
||||
|
||||
fn test_tmpl() {
|
||||
|
|
Loading…
Reference in New Issue