mirror of
https://github.com/a-h/templ.git
synced 2025-02-06 10:03:16 +00:00
feat: promote rawgo from experiment to core feature (#905)
This commit is contained in:
parent
50440018dd
commit
88eed0f460
@ -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()
|
||||
|
||||
@ -19,7 +16,5 @@ func parse() *Flags {
|
||||
m[strings.ToLower(f)] = true
|
||||
}
|
||||
|
||||
return &Flags{
|
||||
RawGo: m["rawgo"],
|
||||
}
|
||||
return &Flags{}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user