From 5e5971897065082c8758323ef4fbbe5869c506cc Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Nov 2020 18:53:38 +0100 Subject: [PATCH] fmt: handle $tmpl --- vlib/v/fmt/fmt.v | 6 +++++- vlib/v/parser/comptime.v | 7 +++---- vlib/v/tests/tmpl_test.v | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 2775cdba54..6c98253471 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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)') } diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index de3c61af4d..ca2660e448 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -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 } } diff --git a/vlib/v/tests/tmpl_test.v b/vlib/v/tests/tmpl_test.v index 0a6711ce13..13f87636a0 100644 --- a/vlib/v/tests/tmpl_test.v +++ b/vlib/v/tests/tmpl_test.v @@ -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() {