tmpl: minor fixes and optimizations

master
Alexander Medvednikov 2022-04-23 16:01:39 +03:00
parent 3388caa6c5
commit 9355048b6c
1 changed files with 6 additions and 9 deletions

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