tmpl: add a tmpl_all_in_one_folder.vv test; fix for static_vars_in_translated_mode.vv
parent
e564269477
commit
4076e8eaa0
|
@ -1,6 +1,6 @@
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn counter() int {
|
fn counter() int {
|
||||||
static mut icounter := 0
|
static icounter := 0
|
||||||
icounter++
|
icounter++
|
||||||
return icounter
|
return icounter
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
@include './header.md'
|
||||||
|
|
||||||
|
This is the main content:
|
||||||
|
-------------------------
|
||||||
|
@content
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
@include './footer.md'
|
|
@ -0,0 +1 @@
|
||||||
|
my footer
|
|
@ -0,0 +1 @@
|
||||||
|
my header
|
|
@ -0,0 +1,8 @@
|
||||||
|
my header
|
||||||
|
|
||||||
|
This is the main content:
|
||||||
|
-------------------------
|
||||||
|
some string
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
my footer
|
|
@ -0,0 +1,8 @@
|
||||||
|
fn abc() string {
|
||||||
|
content := 'some string'
|
||||||
|
return $tmpl('file.md')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
print(abc())
|
||||||
|
}
|
|
@ -13,8 +13,9 @@ const (
|
||||||
|
|
||||||
// compile_file compiles the content of a file by the given path as a template
|
// compile_file compiles the content of a file by the given path as a template
|
||||||
pub fn compile_file(path string, fn_name string) string {
|
pub fn compile_file(path string, fn_name string) string {
|
||||||
|
basepath := os.dir(path)
|
||||||
html := os.read_file(path) or { panic('html failed') }
|
html := os.read_file(path) or { panic('html failed') }
|
||||||
return compile_template(html, fn_name)
|
return compile_template(basepath, html, fn_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
|
@ -24,7 +25,7 @@ enum State {
|
||||||
// span // span.{
|
// span // span.{
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_template(html_ string, fn_name string) string {
|
pub fn compile_template(basepath string, html_ string, 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 := ''
|
mut header := ''
|
||||||
|
@ -81,19 +82,19 @@ _ = footer
|
||||||
file_ext = '.html'
|
file_ext = '.html'
|
||||||
}
|
}
|
||||||
file_name = file_name.replace(file_ext, '')
|
file_name = file_name.replace(file_ext, '')
|
||||||
mut templates_folder := 'templates'
|
mut templates_folder := os.join_path(basepath, 'templates')
|
||||||
if file_name.contains('/') {
|
if file_name.contains('/') {
|
||||||
if file_name.starts_with('/') {
|
if file_name.starts_with('/') {
|
||||||
// absolute path
|
// absolute path
|
||||||
templates_folder = ''
|
templates_folder = ''
|
||||||
} else {
|
} else {
|
||||||
// relative path, starting with the current folder
|
// relative path, starting with the current folder
|
||||||
templates_folder = './'
|
templates_folder = os.real_path(basepath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_path := os.real_path(os.join_path(templates_folder, '$file_name$file_ext'))
|
file_path := os.real_path(os.join_path(templates_folder, '$file_name$file_ext'))
|
||||||
$if trace_tmpl ? {
|
$if trace_tmpl ? {
|
||||||
eprintln('>>> @include line: "$line" , file_name: "$file_name" , file_ext: "$file_ext" , templates_folder: "$templates_folder" , file_path: "$file_path"')
|
eprintln('>>> basepath: "$basepath" , fn_name: "$fn_name" , @include line: "$line" , file_name: "$file_name" , file_ext: "$file_ext" , templates_folder: "$templates_folder" , file_path: "$file_path"')
|
||||||
}
|
}
|
||||||
file_content := os.read_file(file_path) or {
|
file_content := os.read_file(file_path) or {
|
||||||
panic('Vweb: Reading file $file_name failed.')
|
panic('Vweb: Reading file $file_name failed.')
|
||||||
|
|
Loading…
Reference in New Issue