vweb: tmpl fixes
parent
95d76993c9
commit
8a7ddd102e
|
@ -77,6 +77,9 @@ fn (p mut Parser) comp_time() {
|
||||||
// that returns an html string
|
// that returns an html string
|
||||||
else if p.tok == .name && p.lit == 'vweb' {
|
else if p.tok == .name && p.lit == 'vweb' {
|
||||||
path := p.cur_fn.name + '.html'
|
path := p.cur_fn.name + '.html'
|
||||||
|
if p.pref.is_debug {
|
||||||
|
println('compiling tmpl $path')
|
||||||
|
}
|
||||||
if !os.file_exists(path) {
|
if !os.file_exists(path) {
|
||||||
p.error('vweb HTML template "$path" not found')
|
p.error('vweb HTML template "$path" not found')
|
||||||
}
|
}
|
||||||
|
@ -86,13 +89,18 @@ fn (p mut Parser) comp_time() {
|
||||||
p.check(.lpar)
|
p.check(.lpar)
|
||||||
p.check(.rpar)
|
p.check(.rpar)
|
||||||
v_code := tmpl.compile_template(path)
|
v_code := tmpl.compile_template(path)
|
||||||
|
if os.file_exists('.vwebtmpl.v') {
|
||||||
|
os.rm('.vwebtmpl.v')
|
||||||
|
}
|
||||||
os.write_file('.vwebtmpl.v', v_code.clone()) // TODO don't need clone, compiler bug
|
os.write_file('.vwebtmpl.v', v_code.clone()) // TODO don't need clone, compiler bug
|
||||||
p.genln('')
|
p.genln('')
|
||||||
// Parse the function and embed resulting C code in current function so that
|
// Parse the function and embed resulting C code in current function so that
|
||||||
// all variables are available.
|
// all variables are available.
|
||||||
pos := p.cgen.lines.len - 1
|
pos := p.cgen.lines.len - 1
|
||||||
mut pp := p.v.new_parser('.vwebtmpl.v', Pass.main)
|
mut pp := p.v.new_parser('.vwebtmpl.v', Pass.main)
|
||||||
os.rm('.vwebtmpl.v')
|
if !p.pref.is_debug {
|
||||||
|
os.rm('.vwebtmpl.v')
|
||||||
|
}
|
||||||
pp.is_vweb = true
|
pp.is_vweb = true
|
||||||
pp.cur_fn = p.cur_fn // give access too all variables in current function
|
pp.cur_fn = p.cur_fn // give access too all variables in current function
|
||||||
pp.parse()
|
pp.parse()
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub fn compile_template(path string) string {
|
||||||
panic('html failed')
|
panic('html failed')
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
header = h
|
header = h//.replace('\'', '"')
|
||||||
}
|
}
|
||||||
lines := html.split_into_lines()
|
lines := html.split_into_lines()
|
||||||
mut s := strings.new_builder(1000)
|
mut s := strings.new_builder(1000)
|
||||||
|
|
Loading…
Reference in New Issue