mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tmpl: add a tmpl_all_in_one_folder.vv test; fix for static_vars_in_translated_mode.vv
This commit is contained in:
parent
e564269477
commit
4076e8eaa0
@ -1,6 +1,6 @@
|
||||
[unsafe]
|
||||
fn counter() int {
|
||||
static mut icounter := 0
|
||||
static icounter := 0
|
||||
icounter++
|
||||
return icounter
|
||||
}
|
||||
|
8
vlib/v/tests/inout/file.md
Normal file
8
vlib/v/tests/inout/file.md
Normal file
@ -0,0 +1,8 @@
|
||||
@include './header.md'
|
||||
|
||||
This is the main content:
|
||||
-------------------------
|
||||
@content
|
||||
-------------------------
|
||||
|
||||
@include './footer.md'
|
1
vlib/v/tests/inout/footer.md
Normal file
1
vlib/v/tests/inout/footer.md
Normal file
@ -0,0 +1 @@
|
||||
my footer
|
1
vlib/v/tests/inout/header.md
Normal file
1
vlib/v/tests/inout/header.md
Normal file
@ -0,0 +1 @@
|
||||
my header
|
8
vlib/v/tests/inout/tmpl_all_in_one_folder.out
Normal file
8
vlib/v/tests/inout/tmpl_all_in_one_folder.out
Normal file
@ -0,0 +1,8 @@
|
||||
my header
|
||||
|
||||
This is the main content:
|
||||
-------------------------
|
||||
some string
|
||||
-------------------------
|
||||
|
||||
my footer
|
8
vlib/v/tests/inout/tmpl_all_in_one_folder.vv
Normal file
8
vlib/v/tests/inout/tmpl_all_in_one_folder.vv
Normal file
@ -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
|
||||
pub fn compile_file(path string, fn_name string) string {
|
||||
basepath := os.dir(path)
|
||||
html := os.read_file(path) or { panic('html failed') }
|
||||
return compile_template(html, fn_name)
|
||||
return compile_template(basepath, html, fn_name)
|
||||
}
|
||||
|
||||
enum State {
|
||||
@ -24,7 +25,7 @@ enum State {
|
||||
// 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)
|
||||
mut html := html_.trim_space()
|
||||
mut header := ''
|
||||
@ -81,19 +82,19 @@ _ = footer
|
||||
file_ext = '.html'
|
||||
}
|
||||
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.starts_with('/') {
|
||||
// absolute path
|
||||
templates_folder = ''
|
||||
} else {
|
||||
// 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'))
|
||||
$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 {
|
||||
panic('Vweb: Reading file $file_name failed.')
|
||||
|
Loading…
Reference in New Issue
Block a user