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

pull/5700/head
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
1 changed files with 10 additions and 4 deletions

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