mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: include directive
This commit is contained in:
parent
a2d7bc6e6f
commit
123d788d0d
@ -29,14 +29,6 @@ enum State {
|
||||
pub fn compile_template(content, fn_name string) string {
|
||||
// lines := os.read_lines(path)
|
||||
mut html := content
|
||||
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
|
||||
}
|
||||
lines := html.split_into_lines()
|
||||
mut s := strings.new_builder(1000)
|
||||
// base := path.all_after_last('/').replace('.html', '')
|
||||
@ -44,11 +36,7 @@ pub fn compile_template(content, fn_name string) string {
|
||||
import strings
|
||||
// === vweb html template ===
|
||||
fn vweb_tmpl_${fn_name}() {
|
||||
mut sb := strings.new_builder(${lines.len * 30})
|
||||
header := \' \' // TODO remove
|
||||
_ = header
|
||||
//footer := \'footer\'
|
||||
")
|
||||
mut sb := strings.new_builder(${lines.len * 30})\n")
|
||||
s.writeln(str_start)
|
||||
mut state := State.html
|
||||
mut in_span := false
|
||||
@ -65,7 +53,18 @@ pub fn compile_template(content, fn_name string) string {
|
||||
else if line == '</script>' {
|
||||
state = .html
|
||||
}
|
||||
if line.contains('@if ') {
|
||||
if line.contains('@include ') {
|
||||
pos := line.index('@include ') or {
|
||||
continue
|
||||
}
|
||||
mut file_name := line[pos + 9..]
|
||||
file_path := os.join_path('templates', '${file_name}.html')
|
||||
mut file_content := os.read_file(file_path) or {
|
||||
panic('reading file $file_name failed')
|
||||
}
|
||||
file_content = file_content.replace("\'", '"')
|
||||
s.writeln(file_content)
|
||||
} else if line.contains('@if ') {
|
||||
s.writeln(str_end)
|
||||
pos := line.index('@if') or {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user