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

tmpl: minor fixes and optimizations

This commit is contained in:
Alexander Medvednikov 2022-04-23 16:01:39 +03:00
parent 3388caa6c5
commit 9355048b6c

View File

@ -256,30 +256,27 @@ fn vweb_tmpl_${fn_name}() string {
match state {
.html {
if line.starts_with('span.') && line.ends_with('{') {
line_t := line.trim_space()
if line_t.starts_with('span.') && line.ends_with('{') {
// `span.header {` => `<span class='header'>`
class := line.find_between('span.', '{').trim_space()
source.writeln('<span class="$class">')
in_span = true
continue
}
if line.trim_space().starts_with('.') && line.ends_with('{') {
} else if line_t.starts_with('.') && line.ends_with('{') {
// `.header {` => `<div class='header'>`
class := line.find_between('.', '{').trim_space()
trimmed := line.trim_space()
source.write_string(strings.repeat(`\t`, line.len - trimmed.len)) // add the necessary indent to keep <div><div><div> code clean
source.writeln('<div class="$class">')
continue
}
if line.starts_with('#') && line.ends_with('{') {
} else if line_t.starts_with('#') && line.ends_with('{') {
// `#header {` => `<div id='header'>`
class := line.find_between('#', '{').trim_space()
source.writeln('<div id="$class">')
continue
}
if line.trim_space() == '}' {
trimmed := line.trim_space()
source.write_string(strings.repeat(`\t`, line.len - trimmed.len)) // add the necessary indent to keep <div><div><div> code clean
} else if line_t == '}' {
source.write_string(strings.repeat(`\t`, line.len - line_t.len)) // add the necessary indent to keep <div><div><div> code clean
if in_span {
source.writeln('</span>')
in_span = false