vweb: @include tempaltes

pull/5364/head
Daniel Däschle 2020-06-12 14:30:07 +02:00 committed by GitHub
parent 56ae3797dd
commit 6b06184ef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 15 deletions

View File

@ -29,15 +29,6 @@ enum State {
pub fn compile_template(html_, fn_name string) string { pub fn compile_template(html_, fn_name string) string {
// lines := os.read_lines(path) // lines := os.read_lines(path)
mut html := html_.trim_space() 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 lines := html.split_into_lines()
mut s := strings.new_builder(1000) mut s := strings.new_builder(1000)
// base := path.all_after_last('/').replace('.html', '') // base := path.all_after_last('/').replace('.html', '')
@ -67,7 +58,7 @@ _ = header
else if line == '</script>' { else if line == '</script>' {
state = .html state = .html
} }
if line.contains('@include ') && false { if line.contains('@include ') {
// TODO // TODO
pos := line.index('@include ') or { pos := line.index('@include ') or {
continue continue
@ -78,12 +69,14 @@ _ = header
panic('reading file $file_name failed') panic('reading file $file_name failed')
} }
file_content = file_content.replace("\'", '"') file_content = file_content.replace("\'", '"')
lines2 := file_content.split_into_lines() include_file_lines := file_content.split_into_lines()
for l in lines2 { lines_before := lines[0 .. i].clone()
lines.insert(i+1, l) lines_after := lines[i + 1 .. lines.len].clone()
} lines = lines_before
lines << include_file_lines
lines << lines_after
i--
continue continue
//s.writeln(file_content)
} else if line.contains('@js ') { } else if line.contains('@js ') {
pos := line.index('@js') or { pos := line.index('@js') or {
continue continue