mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: minor tmpl fixes
This commit is contained in:
@@ -44,12 +44,12 @@ pub fn compile_template(content string) string {
|
|||||||
")
|
")
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
mut in_css := false // false
|
mut in_css := false // false
|
||||||
|
mut in_span := false
|
||||||
for _line in lines {
|
for _line in lines {
|
||||||
line := _line.trim_space()
|
line := _line.trim_space()
|
||||||
if line == '<style>' {
|
if line == '<style>' {
|
||||||
in_css = true
|
in_css = true
|
||||||
}
|
} else if line == '</style>' {
|
||||||
else if line == '</style>' {
|
|
||||||
// in_css = false
|
// in_css = false
|
||||||
}
|
}
|
||||||
if line.contains('@if ') {
|
if line.contains('@if ') {
|
||||||
@@ -59,35 +59,43 @@ pub fn compile_template(content string) string {
|
|||||||
}
|
}
|
||||||
s.writeln('if ' + line[pos + 4..] + '{')
|
s.writeln('if ' + line[pos + 4..] + '{')
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
}
|
} else if line.contains('@end') {
|
||||||
else if line.contains('@end') {
|
|
||||||
s.writeln(str_end)
|
s.writeln(str_end)
|
||||||
s.writeln('}')
|
s.writeln('}')
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
}
|
} else if line.contains('@else') {
|
||||||
else if line.contains('@else') {
|
|
||||||
s.writeln(str_end)
|
s.writeln(str_end)
|
||||||
s.writeln(' } else { ')
|
s.writeln(' } else { ')
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
}
|
} else if line.contains('@for') {
|
||||||
else if line.contains('@for') {
|
|
||||||
s.writeln(str_end)
|
s.writeln(str_end)
|
||||||
pos := line.index('@for') or {
|
pos := line.index('@for') or {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.writeln('for ' + line[pos + 4..] + '{')
|
s.writeln('for ' + line[pos + 4..] + '{')
|
||||||
s.writeln(str_start)
|
s.writeln(str_start)
|
||||||
}
|
} else if !in_css && line.contains('span.') && line.ends_with('{') {
|
||||||
else if !in_css && line.contains('.') && line.ends_with('{') {
|
// `span.header {` => `<span class='header'>`
|
||||||
|
class := line.find_between('span.', '{').trim_space()
|
||||||
|
s.writeln('<span class="$class">')
|
||||||
|
in_span = true
|
||||||
|
} else if !in_css && line.contains('.') && line.ends_with('{') {
|
||||||
// `.header {` => `<div class='header'>`
|
// `.header {` => `<div class='header'>`
|
||||||
class := line.find_between('.', '{')
|
class := line.find_between('.', '{').trim_space()
|
||||||
s.writeln('<div class="$class">')
|
s.writeln('<div class="$class">')
|
||||||
}
|
} else if !in_css && line.contains('#') && line.ends_with('{') {
|
||||||
else if !in_css && line == '}' {
|
// `#header {` => `<div id='header'>`
|
||||||
|
class := line.find_between('#', '{').trim_space()
|
||||||
|
s.writeln('<div id="$class">')
|
||||||
|
} else if !in_css && line == '}' {
|
||||||
|
if in_span {
|
||||||
|
s.writeln('</span>')
|
||||||
|
in_span = false
|
||||||
|
} else {
|
||||||
s.writeln('</div>')
|
s.writeln('</div>')
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// HTML, may include `@var`
|
// HTML, may include `@var`
|
||||||
else {
|
|
||||||
s.writeln(line.replace('@', '\x24').replace("'", '"'))
|
s.writeln(line.replace('@', '\x24').replace("'", '"'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user