vweb: bring back @header
parent
39c5c9b966
commit
8f3f27f286
|
@ -26,22 +26,36 @@ enum State {
|
||||||
//span // span.{
|
//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)
|
// lines := os.read_lines(path)
|
||||||
mut html := content
|
mut html := html_
|
||||||
lines := html.split_into_lines()
|
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)
|
mut s := strings.new_builder(1000)
|
||||||
// base := path.all_after_last('/').replace('.html', '')
|
// base := path.all_after_last('/').replace('.html', '')
|
||||||
s.writeln("
|
s.writeln("
|
||||||
import strings
|
import strings
|
||||||
// === vweb html template ===
|
// === vweb html template ===
|
||||||
fn vweb_tmpl_${fn_name}() {
|
fn vweb_tmpl_${fn_name}() {
|
||||||
mut sb := strings.new_builder(${lines.len * 30})\n")
|
mut sb := strings.new_builder(${lines.len * 30})\n
|
||||||
|
header := \' \' // TODO remove
|
||||||
|
_ = header
|
||||||
|
|
||||||
|
")
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
mut state := State.html
|
mut state := State.html
|
||||||
mut in_span := false
|
mut in_span := false
|
||||||
for _line in lines {
|
//for _line in lines {
|
||||||
line := _line.trim_space()
|
for i := 0; i < lines.len; i ++ {
|
||||||
|
line := lines[i].trim_space()
|
||||||
if line == '<style>' {
|
if line == '<style>' {
|
||||||
state = .css
|
state = .css
|
||||||
} else if line == '</style>' {
|
} else if line == '</style>' {
|
||||||
|
@ -53,7 +67,8 @@ pub fn compile_template(content, fn_name string) string {
|
||||||
else if line == '</script>' {
|
else if line == '</script>' {
|
||||||
state = .html
|
state = .html
|
||||||
}
|
}
|
||||||
if line.contains('@include ') {
|
// TODO
|
||||||
|
if line.contains('@include ') && false {
|
||||||
pos := line.index('@include ') or {
|
pos := line.index('@include ') or {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -63,7 +78,12 @@ pub fn compile_template(content, fn_name string) string {
|
||||||
panic('reading file $file_name failed')
|
panic('reading file $file_name failed')
|
||||||
}
|
}
|
||||||
file_content = file_content.replace("\'", '"')
|
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 ') {
|
} else if line.contains('@if ') {
|
||||||
s.writeln(str_end)
|
s.writeln(str_end)
|
||||||
pos := line.index('@if') or {
|
pos := line.index('@if') or {
|
||||||
|
|
Loading…
Reference in New Issue