From 3bb1d24dad504c0d8dfe5730d82c9b893780ca26 Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Wed, 8 Jul 2020 08:12:57 +0200 Subject: [PATCH] parser: add template path by fn name for vweb (#5737) --- vlib/v/parser/comptime.v | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index ee4458d74f..2f0d3e793d 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -88,15 +88,21 @@ fn (mut p Parser) vweb() ast.ComptimeCall { 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. - html_name := '${p.cur_fn_name}.html' + + fn_path := p.cur_fn_name.split('_') + html_name := '${fn_path.last()}.html' + + // Looking next to the vweb program dir := os.dir(p.scanner.file_path) - mut path := os.join_path(dir, html_name) + mut path := os.join_path(dir, fn_path.join('/')) + path += '.html' if !os.exists(path) { // can be in `templates/` - path = os.join_path(dir, 'templates', html_name) + path = os.join_path(dir, 'templates', fn_path.join('/')) + path += '.html' if !os.exists(path) { - p.error('vweb HTML template "$html_name" not found') + p.error('vweb HTML template "$path" not found') } // println('path is now "$path"') }