1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: add tmpl api to compile either file or a string

This commit is contained in:
Daniel Däschle 2020-06-04 22:30:25 +02:00 committed by GitHub
parent 13a7ce9e69
commit 6118875ee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,11 +11,17 @@ const (
str_end = "\' ) "
)
pub fn compile_template(path string) string {
// lines := os.read_lines(path)
// compile_file compiles the content of a file by the given path as a template
pub fn compile_file(path string) string {
mut html := os.read_file(path)or{
panic('html failed')
}
return compile_template(html)
}
pub fn compile_template(content string) string {
// lines := os.read_lines(path)
mut html := content
mut header := ''
if os.exists('header.html') && html.contains('@header') {
h := os.read_file('header.html')or{