From 6118875ee34ad83f9b14693154e2a99ea8552d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 4 Jun 2020 22:30:25 +0200 Subject: [PATCH] vweb: add tmpl api to compile either file or a string --- vlib/vweb/tmpl/tmpl.v | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index 23f2ddc021..ac3a776efa 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -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{