Skip to content

Commit 88eed0f

Browse files
authoredSep 8, 2024··
feat: promote rawgo from experiment to core feature (#905)
1 parent 5044001 commit 88eed0f

File tree

5 files changed

+2
-32
lines changed

5 files changed

+2
-32
lines changed
 

‎cfg/cfg.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import (
66
"strings"
77
)
88

9-
type Flags struct {
10-
// RawGo will enable the support of arbibrary Go code in templates.
11-
RawGo bool
12-
}
9+
type Flags struct{}
1310

1411
var Experiment = parse()
1512

@@ -19,7 +16,5 @@ func parse() *Flags {
1916
m[strings.ToLower(f)] = true
2017
}
2118

22-
return &Flags{
23-
RawGo: m["rawgo"],
24-
}
19+
return &Flags{}
2520
}

‎docs/docs/03-syntax-and-usage/09-raw-go.md

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# Raw Go
22

3-
:::caution
4-
This page describes functionality that is experimental, not enabled by default, and may change or be removed in future versions.
5-
6-
To enable this feature run the generation step with the `rawgo` experiment flag: `TEMPL_EXPERIMENT=rawgo templ generate`
7-
8-
You will also need to set the `TEMPL_EXPERIMENT=rawgo` environment variable at your system level or within your editor to enable LSP behavior.
9-
:::
10-
113
For some more advanced use cases it may be useful to write Go code statements in your template.
124

135
Use the `{{ ... }}` syntax for this.

‎parser/v2/format_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@ import (
55
"path/filepath"
66
"testing"
77

8-
"github.com/a-h/templ/cfg"
98
"github.com/google/go-cmp/cmp"
109
"golang.org/x/tools/txtar"
1110
)
1211

1312
func TestFormatting(t *testing.T) {
14-
oldFlags := cfg.Experiment
15-
t.Cleanup(func() {
16-
cfg.Experiment = oldFlags
17-
})
18-
cfg.Experiment.RawGo = true
1913
files, _ := filepath.Glob("formattestdata/*.txt")
2014
if len(files) == 0 {
2115
t.Errorf("no test files found")

‎parser/v2/gocodeparser.go

-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ package parser
22

33
import (
44
"github.com/a-h/parse"
5-
"github.com/a-h/templ/cfg"
65
"github.com/a-h/templ/parser/v2/goexpression"
76
)
87

98
var goCode = parse.Func(func(pi *parse.Input) (n Node, ok bool, err error) {
10-
if !cfg.Experiment.RawGo {
11-
return
12-
}
139
// Check the prefix first.
1410
if _, ok, err = parse.Or(parse.String("{{ "), parse.String("{{")).Parse(pi); err != nil || !ok {
1511
return

‎parser/v2/gocodeparser_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ import (
44
"testing"
55

66
"github.com/a-h/parse"
7-
"github.com/a-h/templ/cfg"
87
"github.com/google/go-cmp/cmp"
98
)
109

1110
func TestGoCodeParser(t *testing.T) {
12-
flagVal := cfg.Experiment.RawGo
13-
cfg.Experiment.RawGo = true
14-
defer func() {
15-
cfg.Experiment.RawGo = flagVal
16-
}()
17-
1811
tests := []struct {
1912
name string
2013
input string

0 commit comments

Comments
 (0)
Please sign in to comment.