Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 24, 2024
1 parent 5bcccf4 commit 4fa4854
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
14 changes: 3 additions & 11 deletions vlib/v/parser/tmpl.v
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ fn vweb_tmpl_${fn_name}() string {
mut end_of_line_pos := 0
mut start_of_line_pos := 0
mut tline_number := -1 // keep the original line numbers, even after insert/delete ops on lines; `i` changes
mut in_write := false // continuing string write code
for i := 0; i < lines.len; i++ {
line := lines[i]
tline_number++
Expand Down Expand Up @@ -329,13 +328,12 @@ fn vweb_tmpl_${fn_name}() string {
pos := line.index('@if') or { continue }
source.writeln('if ' + line[pos + 4..] + '{')
source.write_string(tmpl_str_start)
in_write = true
continue
}
if line.contains('@end') {
source.writeln(tmpl_str_end)
source.writeln('}')
source.writeln(tmpl_str_start)
source.write_string(tmpl_str_start)
continue
}
if line.contains('@else') {
Expand All @@ -344,7 +342,6 @@ fn vweb_tmpl_${fn_name}() string {
source.writeln('}' + line[pos + 1..] + '{')
// source.writeln(' } else { ')
source.write_string(tmpl_str_start)
in_write = true
continue
}
if line.contains('@for') {
Expand All @@ -356,15 +353,10 @@ fn vweb_tmpl_${fn_name}() string {
}
if state == .simple {
// by default, just copy 1:1
if in_write {
source.write_string(insert_template_code(fn_name, tmpl_str_start, line))
} else {
source.writeln(insert_template_code(fn_name, tmpl_str_start, line))
}
in_write = false
source.writeln(insert_template_code(fn_name, tmpl_str_start, line))
continue
}
in_write = false
//in_write = false
// The .simple mode ends here. The rest handles .html/.css/.js state transitions.

if state != .simple {
Expand Down
19 changes: 0 additions & 19 deletions vlib/v/tests/tmpl_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ numbers: [1, 2, 3]
2
3
0 - 0
2 - 1
4 - 2
Expand All @@ -44,11 +43,9 @@ numbers: [1, 2, 3]
16 - 8
18 - 9
vlang/ui, downloaded 3201 times.
vlang/vtl, downloaded 123 times.
this is not ignored
so, it's basically true"
Expand All @@ -73,7 +70,6 @@ numbers: [1, 2, 3]
2
3
0 - 0
2 - 1
4 - 2
Expand All @@ -85,11 +81,9 @@ numbers: [1, 2, 3]
16 - 8
18 - 9
vlang/ui, downloaded 3201 times.
vlang/vtl, downloaded 123 times.
this is not ignored
so, it's basically true"
Expand Down Expand Up @@ -146,16 +140,3 @@ fn test_tmpl_include_grandchild() {
child_tmpl := $tmpl('tmpl/nested/nested_deeper/grandchild.html')
assert child_tmpl.contains(expected)
}

fn test_tmpl_if_cond() {
cond := true
processed := $tmpl('tmpl/if_cond.txt')
assert processed == 'aaa
bbb
ccc
aaa
bbb
ccc
'
}

0 comments on commit 4fa4854

Please sign in to comment.