Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable rawgo experiment as a core feature #905

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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