From a0cbe48977f311d90036bf7b1d98600334ba5f82 Mon Sep 17 00:00:00 2001 From: Lathanao Date: Thu, 4 Feb 2021 23:07:04 +0700 Subject: [PATCH] vweb: fix @include (#8535) --- vlib/vweb/tmpl/tmpl.v | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index eb45e502a1..290b4f3c8c 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -73,21 +73,18 @@ _ = footer } else if line == '' { state = .html } - if line.contains('@include ') && false { - // TODO - pos := line.index('@include ') or { continue } - file_name := line[pos + 9..] + if line.contains('@include ') { + lines.delete(i) + file_name := line.split("'")[1] file_path := os.join_path('templates', '${file_name}.html') - mut file_content := os.read_file(file_path) or { - panic('reading file $file_name failed') + file_content := os.read_file(file_path) or { + panic('Vweb: Reading file $file_name failed.') } - file_content = file_content.replace("'", '"') - lines2 := file_content.split_into_lines() - for l in lines2 { - lines.insert(i + 1, l) + file_splitted := file_content.split_into_lines().reverse() + for f in file_splitted { + lines.insert(i, f) } - continue - // s.writeln(file_content) + i-- } else if line.contains('@js ') { pos := line.index('@js') or { continue } s.write('