Skip to content

Commit 2d5e584

Browse files
authored
Merge branch 'main' into add_go_expressions_in_script_elements
2 parents b7009c3 + 19362bd commit 2d5e584

File tree

12 files changed

+167
-10
lines changed

12 files changed

+167
-10
lines changed

.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.839
1+
0.3.841
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"position": 15,
3+
"label": "Component Libraries"
4+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Component Libraries
2+
3+
Component libraries in the templ ecosystem provide ready-to-use UI elements.
4+
5+
## templUI
6+
7+
![templUI Banner](/img/ecosystem/templui.png)
8+
9+
### About
10+
11+
templUI is the premier UI component library built specifically for templ. It combines the type-safety of Go with the interactivity of Alpine.js and the styling power of Tailwind CSS to create beautiful, responsive web applications.
12+
13+
### Features
14+
15+
- **30+ Ready-made Components**: Buttons, cards, modals, charts, and more
16+
- **Enterprise-Ready**: Built for production with security in mind
17+
- **CSP Compliant**: Works seamlessly with Content Security Policy
18+
- **Type-Safe**: Full Go type system integration and checking
19+
- **Customizable**: Easily adapt to match your brand identity
20+
21+
### Example
22+
23+
```go
24+
import "github.com/axzilla/templui/components"
25+
26+
templ ExamplePage() {
27+
@components.Button(components.ButtonProps{
28+
Text: "Click me",
29+
IconRight: icons.ArrowRight(icons.IconProps{Size: "16"}),
30+
})
31+
}
32+
```
33+
34+
### Links
35+
36+
- [Documentation](https://templui.io)
37+
- [GitHub](https://github.com/axzilla/templui)
38+
- [Quick Start Template](https://github.com/axzilla/templui-quickstart)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"position": 15,
2+
"position": 16,
33
"label": "FAQ"
44
}
File renamed without changes.

docs/static/img/ecosystem/templui.png

361 KB
Loading

generator/generator.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,17 @@ func (g *generator) writeWhitespaceTrailer(indentLevel int, n parser.TrailingSpa
674674
}
675675

676676
func (g *generator) writeDocType(indentLevel int, n parser.DocType) (err error) {
677-
if _, err = g.w.WriteStringLiteral(indentLevel, fmt.Sprintf("<!doctype %s>", n.Value)); err != nil {
677+
if _, err = g.w.WriteStringLiteral(indentLevel, fmt.Sprintf("<!doctype %s>", escapeQuotes(n.Value))); err != nil {
678678
return err
679679
}
680680
return nil
681681
}
682682

683+
func escapeQuotes(s string) string {
684+
quoted := strconv.Quote(s)
685+
return quoted[1 : len(quoted)-1]
686+
}
687+
683688
func (g *generator) writeIfExpression(indentLevel int, n parser.IfExpression, nextNode parser.Node) (err error) {
684689
var r parser.Range
685690
// if
@@ -1132,8 +1137,7 @@ func (g *generator) writeBoolConstantAttribute(indentLevel int, attr parser.Bool
11321137
func (g *generator) writeConstantAttribute(indentLevel int, attr parser.ConstantAttribute) (err error) {
11331138
name := html.EscapeString(attr.Name)
11341139
value := html.EscapeString(attr.Value)
1135-
value = strconv.Quote(value)
1136-
value = value[1 : len(value)-1]
1140+
value = escapeQuotes(value)
11371141
if _, err = g.w.WriteStringLiteral(indentLevel, fmt.Sprintf(` %s=\"%s\"`, name, value)); err != nil {
11381142
return err
11391143
}
@@ -1612,8 +1616,7 @@ func (g *generator) writeWhitespace(indentLevel int, n parser.Whitespace) (err e
16121616
}
16131617

16141618
func (g *generator) writeText(indentLevel int, n parser.Text) (err error) {
1615-
quoted := strconv.Quote(n.Value)
1616-
_, err = g.w.WriteStringLiteral(indentLevel, quoted[1:len(quoted)-1])
1619+
_, err = g.w.WriteStringLiteral(indentLevel, escapeQuotes(n.Value))
16171620
return err
16181621
}
16191622

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>title</title>
8+
</head>
9+
<body>content</body>
10+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package testdoctype
2+
3+
import (
4+
_ "embed"
5+
"testing"
6+
7+
"github.com/a-h/templ/generator/htmldiff"
8+
)
9+
10+
//go:embed expected.html
11+
var expected string
12+
13+
func Test(t *testing.T) {
14+
component := Layout("title", "content")
15+
16+
diff, err := htmldiff.Diff(component, expected)
17+
if err != nil {
18+
t.Fatal(err)
19+
}
20+
if diff != "" {
21+
t.Error(diff)
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package testdoctype
2+
3+
templ Layout(title, content string) {
4+
<!DOCTYPE HTML PUBLIC "http://www.w3.org/TR/html4/loose.dtd">
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8"/>
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
10+
<title>{ title }</title>
11+
</head>
12+
<body>{ content }</body>
13+
</html>
14+
}

generator/test-doctype-html4/template_templ.go

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storybook/storybook.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (sh *Storybook) Build(ctx context.Context) (err error) {
109109
if err != nil {
110110
return
111111
}
112-
if ctx.Err() != nil {
112+
if err = ctx.Err(); err != nil {
113113
return
114114
}
115115

@@ -119,7 +119,7 @@ func (sh *Storybook) Build(ctx context.Context) (err error) {
119119
if err != nil {
120120
return
121121
}
122-
if ctx.Err() != nil {
122+
if err = ctx.Err(); err != nil {
123123
return
124124
}
125125

@@ -133,7 +133,7 @@ func (sh *Storybook) Build(ctx context.Context) (err error) {
133133
} else {
134134
sh.Log.Info("Storybook is up-to-date, skipping build step.")
135135
}
136-
if ctx.Err() != nil {
136+
if err = ctx.Err(); err != nil {
137137
return
138138
}
139139

0 commit comments

Comments
 (0)