From ecc87286432e9ad62e018a0311085565d5de8208 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 21 Sep 2019 01:17:52 +0300 Subject: [PATCH] vweb: allow running vweb apps from a different directory --- compiler/comptime.v | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/comptime.v b/compiler/comptime.v index fe32c1a4c1..96c4cb73fc 100644 --- a/compiler/comptime.v +++ b/compiler/comptime.v @@ -89,12 +89,18 @@ fn (p mut Parser) comp_time() { // Compile vweb html template to V code, parse that V code and embed the resulting V functions // that returns an html string else if p.tok == .name && p.lit == 'vweb' { - path := p.cur_fn.name + '.html' + mut path := p.cur_fn.name + '.html' if p.pref.is_debug { println('compiling tmpl $path') } if !os.file_exists(path) { - p.error('vweb HTML template "$path" not found') + // Can't find the template file in current directory, + // try looking next to the vweb program, in case it's run with + // v path/to/vweb_app.v + path = os.dir(p.scanner.file_path) + '/' + path + if !os.file_exists(path) { + p.error('vweb HTML template "$path" not found') + } } p.check(.name) // skip `vweb.html()` TODO p.check(.dot)