From 6b06184ef4851ec689619a56f76843c86ecc4d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Fri, 12 Jun 2020 14:30:07 +0200 Subject: [PATCH] vweb: @include tempaltes --- vlib/vweb/tmpl/tmpl.v | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index 32cca5d82c..66a28ad2e4 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -29,15 +29,6 @@ enum State { pub fn compile_template(html_, fn_name string) string { // lines := os.read_lines(path) mut html := html_.trim_space() - mut header := '' - if os.exists('templates/header.html') && html.contains('@header') { - h := os.read_file('templates/header.html') or { - panic('reading file templates/header.html failed') - } - header = h.trim_space().replace("\'", '"') - html = header + html - } - mut lines := html.split_into_lines() mut s := strings.new_builder(1000) // base := path.all_after_last('/').replace('.html', '') @@ -67,7 +58,7 @@ _ = header else if line == '' { state = .html } - if line.contains('@include ') && false { + if line.contains('@include ') { // TODO pos := line.index('@include ') or { continue @@ -78,12 +69,14 @@ _ = header panic('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) - } + include_file_lines := file_content.split_into_lines() + lines_before := lines[0 .. i].clone() + lines_after := lines[i + 1 .. lines.len].clone() + lines = lines_before + lines << include_file_lines + lines << lines_after + i-- continue - //s.writeln(file_content) } else if line.contains('@js ') { pos := line.index('@js') or { continue