Skip to content

Commit

Permalink
feat: promote rawgo from experiment to core feature (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav authored Sep 8, 2024
1 parent 5044001 commit 88eed0f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 32 deletions.
9 changes: 2 additions & 7 deletions cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"strings"
)

type Flags struct {
// RawGo will enable the support of arbibrary Go code in templates.
RawGo bool
}
type Flags struct{}

var Experiment = parse()

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

return &Flags{
RawGo: m["rawgo"],
}
return &Flags{}
}
8 changes: 0 additions & 8 deletions docs/docs/03-syntax-and-usage/09-raw-go.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Raw Go

:::caution
This page describes functionality that is experimental, not enabled by default, and may change or be removed in future versions.

To enable this feature run the generation step with the `rawgo` experiment flag: `TEMPL_EXPERIMENT=rawgo templ generate`

You will also need to set the `TEMPL_EXPERIMENT=rawgo` environment variable at your system level or within your editor to enable LSP behavior.
:::

For some more advanced use cases it may be useful to write Go code statements in your template.

Use the `{{ ... }}` syntax for this.
Expand Down
6 changes: 0 additions & 6 deletions parser/v2/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import (
"path/filepath"
"testing"

"github.com/a-h/templ/cfg"
"github.com/google/go-cmp/cmp"
"golang.org/x/tools/txtar"
)

func TestFormatting(t *testing.T) {
oldFlags := cfg.Experiment
t.Cleanup(func() {
cfg.Experiment = oldFlags
})
cfg.Experiment.RawGo = true
files, _ := filepath.Glob("formattestdata/*.txt")
if len(files) == 0 {
t.Errorf("no test files found")
Expand Down
4 changes: 0 additions & 4 deletions parser/v2/gocodeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package parser

import (
"github.com/a-h/parse"
"github.com/a-h/templ/cfg"
"github.com/a-h/templ/parser/v2/goexpression"
)

var goCode = parse.Func(func(pi *parse.Input) (n Node, ok bool, err error) {
if !cfg.Experiment.RawGo {
return
}
// Check the prefix first.
if _, ok, err = parse.Or(parse.String("{{ "), parse.String("{{")).Parse(pi); err != nil || !ok {
return
Expand Down
7 changes: 0 additions & 7 deletions parser/v2/gocodeparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ import (
"testing"

"github.com/a-h/parse"
"github.com/a-h/templ/cfg"
"github.com/google/go-cmp/cmp"
)

func TestGoCodeParser(t *testing.T) {
flagVal := cfg.Experiment.RawGo
cfg.Experiment.RawGo = true
defer func() {
cfg.Experiment.RawGo = flagVal
}()

tests := []struct {
name string
input string
Expand Down

0 comments on commit 88eed0f

Please sign in to comment.