vweb: bring back @header

pull/5352/head
Alexander Medvednikov 2020-06-11 11:13:36 +02:00
parent 39c5c9b966
commit 8f3f27f286
1 changed files with 31 additions and 11 deletions

View File

@ -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 == '<style>' {
state = .css
} else if line == '</style>' {
@ -53,7 +67,8 @@ pub fn compile_template(content, fn_name string) string {
else if line == '</script>' {
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 {