diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index 6012dcc9c5..b746d09125 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -26,22 +26,36 @@ enum State { //span // span.{ } -pub fn compile_template(content, fn_name string) string { +pub fn compile_template(html_, fn_name string) string { // lines := os.read_lines(path) - mut html := content - lines := html.split_into_lines() + mut html := html_ + 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.replace("\'", '"') + html = header + html +} + + mut lines := html.split_into_lines() mut s := strings.new_builder(1000) // base := path.all_after_last('/').replace('.html', '') s.writeln(" - import strings - // === vweb html template === - fn vweb_tmpl_${fn_name}() { - mut sb := strings.new_builder(${lines.len * 30})\n") +import strings +// === vweb html template === +fn vweb_tmpl_${fn_name}() { +mut sb := strings.new_builder(${lines.len * 30})\n +header := \' \' // TODO remove +_ = header + +") s.writeln(str_start) mut state := State.html mut in_span := false - for _line in lines { - line := _line.trim_space() + //for _line in lines { + for i := 0; i < lines.len; i ++ { + line := lines[i].trim_space() if line == '' { @@ -53,7 +67,8 @@ pub fn compile_template(content, fn_name string) string { else if line == '' { state = .html } - if line.contains('@include ') { + // TODO + if line.contains('@include ') && false { pos := line.index('@include ') or { continue } @@ -63,7 +78,12 @@ pub fn compile_template(content, fn_name string) string { panic('reading file $file_name failed') } file_content = file_content.replace("\'", '"') - s.writeln(file_content) + lines2 := file_content.split_into_lines() + for l in lines2 { + lines.insert(i+1, l) + } + continue + //s.writeln(file_content) } else if line.contains('@if ') { s.writeln(str_end) pos := line.index('@if') or {