1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: add template path by fn name for vweb (#5737)

This commit is contained in:
Louis Schmieder 2020-07-08 08:12:57 +02:00 committed by GitHub
parent bd16dd9fdf
commit 3bb1d24dad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"')
}