🌐 Added language support for pages
Some checks failed
/ docker (push) Failing after 44s

This commit is contained in:
Maxim Lebedev 2023-11-08 03:16:12 +06:00
parent 23c7b18315
commit 2c705e6142
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
5 changed files with 263 additions and 142 deletions

View File

@ -62,6 +62,7 @@ func main() {
w.Header().Set(common.HeaderContentType, common.MIMETextHTMLCharsetUTF8)
template.WriteTemplate(w, template.NewPage(
template.NewBaseOf(lang),
language.English,
[]byte(`hello, world!`),
`toby3d`,
))

View File

@ -7,6 +7,7 @@
Body()
T(format message.Reference, v ...any)
Title()
Lang()
} %}
{% code
@ -34,9 +35,15 @@ func NewBaseOf(lang language.Tag) BaseOf {
{% func (b BaseOf) Body() %}{% endfunc %}
{% func (b BaseOf) Lang() %}
{% if b.language != language.Und %}
{%s b.language.String() %}
{% endif %}
{% endfunc %}
{% func Template(p Pager) %}
<!DOCTYPE html>
<html lang="en">
<html lang="{%= p.Lang() %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View File

@ -43,10 +43,16 @@ type Pager interface {
StreamTitle(qw422016 *qt422016.Writer)
//line web/template/baseof.qtpl:6
WriteTitle(qq422016 qtio422016.Writer)
//line web/template/baseof.qtpl:6
Lang() string
//line web/template/baseof.qtpl:6
StreamLang(qw422016 *qt422016.Writer)
//line web/template/baseof.qtpl:6
WriteLang(qq422016 qtio422016.Writer)
//line web/template/baseof.qtpl:6
}
//line web/template/baseof.qtpl:13
//line web/template/baseof.qtpl:14
type BaseOf struct {
language language.Tag
printer *message.Printer
@ -59,140 +65,181 @@ func NewBaseOf(lang language.Tag) BaseOf {
}
}
//line web/template/baseof.qtpl:27
//line web/template/baseof.qtpl:28
func (b BaseOf) StreamTitle(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:27
//line web/template/baseof.qtpl:28
qw422016.N().S(`toby3d`)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
}
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
func (b BaseOf) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
b.StreamTitle(qw422016)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
}
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
func (b BaseOf) Title() string {
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
b.WriteTitle(qb422016)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
return qs422016
//line web/template/baseof.qtpl:29
//line web/template/baseof.qtpl:30
}
//line web/template/baseof.qtpl:31
func (b BaseOf) StreamT(qw422016 *qt422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:32
func (b BaseOf) StreamT(qw422016 *qt422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:33
qw422016.E().S(b.printer.Sprintf(format, v...))
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
}
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
func (b BaseOf) WriteT(qq422016 qtio422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
b.StreamT(qw422016, format, v...)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
}
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
func (b BaseOf) T(format message.Reference, v ...any) string {
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
b.WriteT(qb422016, format, v...)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
return qs422016
//line web/template/baseof.qtpl:33
//line web/template/baseof.qtpl:34
}
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
func (b BaseOf) StreamBody(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
}
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
func (b BaseOf) WriteBody(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
b.StreamBody(qw422016)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
}
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
func (b BaseOf) Body() string {
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
b.WriteBody(qb422016)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
return qs422016
//line web/template/baseof.qtpl:35
//line web/template/baseof.qtpl:36
}
//line web/template/baseof.qtpl:37
func StreamTemplate(qw422016 *qt422016.Writer, p Pager) {
//line web/template/baseof.qtpl:37
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>`)
//line web/template/baseof.qtpl:44
p.StreamTitle(qw422016)
//line web/template/baseof.qtpl:44
qw422016.N().S(`</title></head><body>`)
//line web/template/baseof.qtpl:48
p.StreamBody(qw422016)
//line web/template/baseof.qtpl:48
qw422016.N().S(`</body></html>`)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:38
func (b BaseOf) StreamLang(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:39
if b.language != language.Und {
//line web/template/baseof.qtpl:40
qw422016.E().S(b.language.String())
//line web/template/baseof.qtpl:41
}
//line web/template/baseof.qtpl:42
}
//line web/template/baseof.qtpl:51
func WriteTemplate(qq422016 qtio422016.Writer, p Pager) {
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
func (b BaseOf) WriteLang(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:42
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:51
StreamTemplate(qw422016, p)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
b.StreamLang(qw422016)
//line web/template/baseof.qtpl:42
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
}
//line web/template/baseof.qtpl:51
func Template(p Pager) string {
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
func (b BaseOf) Lang() string {
//line web/template/baseof.qtpl:42
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:51
WriteTemplate(qb422016, p)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
b.WriteLang(qb422016)
//line web/template/baseof.qtpl:42
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
return qs422016
//line web/template/baseof.qtpl:51
//line web/template/baseof.qtpl:42
}
//line web/template/baseof.qtpl:44
func StreamTemplate(qw422016 *qt422016.Writer, p Pager) {
//line web/template/baseof.qtpl:44
qw422016.N().S(`<!DOCTYPE html><html lang="`)
//line web/template/baseof.qtpl:46
p.StreamLang(qw422016)
//line web/template/baseof.qtpl:46
qw422016.N().S(`"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>`)
//line web/template/baseof.qtpl:51
p.StreamTitle(qw422016)
//line web/template/baseof.qtpl:51
qw422016.N().S(`</title></head><body>`)
//line web/template/baseof.qtpl:55
p.StreamBody(qw422016)
//line web/template/baseof.qtpl:55
qw422016.N().S(`</body></html>`)
//line web/template/baseof.qtpl:58
}
//line web/template/baseof.qtpl:58
func WriteTemplate(qq422016 qtio422016.Writer, p Pager) {
//line web/template/baseof.qtpl:58
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:58
StreamTemplate(qw422016, p)
//line web/template/baseof.qtpl:58
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:58
}
//line web/template/baseof.qtpl:58
func Template(p Pager) string {
//line web/template/baseof.qtpl:58
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:58
WriteTemplate(qb422016, p)
//line web/template/baseof.qtpl:58
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:58
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:58
return qs422016
//line web/template/baseof.qtpl:58
}

View File

@ -1,13 +1,19 @@
{% import (
"golang.org/x/text/language"
) %}
{% code
type Page struct {
BaseOf
language language.Tag
title string
content []byte
}
func NewPage(base BaseOf, content []byte, title string) Page {
func NewPage(base BaseOf, lang language.Tag, content []byte, title string) Page {
return Page{
BaseOf: base,
language: lang,
title: title,
content: content,
}
@ -23,7 +29,15 @@ func NewPage(base BaseOf, content []byte, title string) Page {
{% endif %}
{% endfunc %}
{% func (p Page) Lang() %}
{% if p.language != language.Und %}
{%s p.language.String() %}
{% else %}
{%= p.BaseOf.Lang() %}
{% endif %}
{% endfunc %}
{% func (p Page) Body() %}
{%z p.content %}
<p>{%z p.content %}</p>
{% endfunc %}
{% endstripspace %}

View File

@ -5,103 +5,155 @@
package template
//line web/template/page.qtpl:1
import (
"golang.org/x/text/language"
)
//line web/template/page.qtpl:5
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line web/template/page.qtpl:1
//line web/template/page.qtpl:5
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line web/template/page.qtpl:2
//line web/template/page.qtpl:6
type Page struct {
BaseOf
title string
content []byte
language language.Tag
title string
content []byte
}
func NewPage(base BaseOf, content []byte, title string) Page {
func NewPage(base BaseOf, lang language.Tag, content []byte, title string) Page {
return Page{
BaseOf: base,
title: title,
content: content,
BaseOf: base,
language: lang,
title: title,
content: content,
}
}
//line web/template/page.qtpl:18
//line web/template/page.qtpl:24
func (p Page) StreamTitle(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:19
//line web/template/page.qtpl:25
if p.title != "" {
//line web/template/page.qtpl:20
qw422016.E().S(p.title)
//line web/template/page.qtpl:21
} else {
//line web/template/page.qtpl:22
p.BaseOf.StreamTitle(qw422016)
//line web/template/page.qtpl:23
}
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:24
func (p Page) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:24
p.StreamTitle(qw422016)
//line web/template/page.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:24
func (p Page) Title() string {
//line web/template/page.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:24
p.WriteTitle(qb422016)
//line web/template/page.qtpl:24
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:24
return qs422016
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:26
func (p Page) StreamBody(qw422016 *qt422016.Writer) {
qw422016.E().S(p.title)
//line web/template/page.qtpl:27
qw422016.E().Z(p.content)
} else {
//line web/template/page.qtpl:28
p.BaseOf.StreamTitle(qw422016)
//line web/template/page.qtpl:29
}
//line web/template/page.qtpl:30
}
//line web/template/page.qtpl:28
func (p Page) WriteBody(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
func (p Page) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:30
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:28
p.StreamBody(qw422016)
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
p.StreamTitle(qw422016)
//line web/template/page.qtpl:30
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
}
//line web/template/page.qtpl:28
func (p Page) Body() string {
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
func (p Page) Title() string {
//line web/template/page.qtpl:30
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:28
p.WriteBody(qb422016)
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
p.WriteTitle(qb422016)
//line web/template/page.qtpl:30
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
return qs422016
//line web/template/page.qtpl:28
//line web/template/page.qtpl:30
}
//line web/template/page.qtpl:32
func (p Page) StreamLang(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:33
if p.language != language.Und {
//line web/template/page.qtpl:34
qw422016.E().S(p.language.String())
//line web/template/page.qtpl:35
} else {
//line web/template/page.qtpl:36
p.BaseOf.StreamLang(qw422016)
//line web/template/page.qtpl:37
}
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:38
func (p Page) WriteLang(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:38
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:38
p.StreamLang(qw422016)
//line web/template/page.qtpl:38
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:38
func (p Page) Lang() string {
//line web/template/page.qtpl:38
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:38
p.WriteLang(qb422016)
//line web/template/page.qtpl:38
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:38
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:38
return qs422016
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:40
func (p Page) StreamBody(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:40
qw422016.N().S(`<p>`)
//line web/template/page.qtpl:41
qw422016.E().Z(p.content)
//line web/template/page.qtpl:41
qw422016.N().S(`</p>`)
//line web/template/page.qtpl:42
}
//line web/template/page.qtpl:42
func (p Page) WriteBody(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:42
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:42
p.StreamBody(qw422016)
//line web/template/page.qtpl:42
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:42
}
//line web/template/page.qtpl:42
func (p Page) Body() string {
//line web/template/page.qtpl:42
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:42
p.WriteBody(qb422016)
//line web/template/page.qtpl:42
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:42
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:42
return qs422016
//line web/template/page.qtpl:42
}