mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: @include tempaltes
This commit is contained in:
parent
56ae3797dd
commit
6b06184ef4
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user