Skip to content

Commit

Permalink
refactor: couple of minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed May 12, 2024
1 parent 95eaec2 commit 3663423
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.668
0.2.692
8 changes: 4 additions & 4 deletions cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

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

var Experiment = parseTEMPLEXPERIMENT()
var Experiment = parse()

func parseTEMPLEXPERIMENT() *Flags {
func parse() *Flags {
m := map[string]bool{}
for _, f := range strings.Split(os.Getenv("TEMPLEXPERIMENT"), ",") {
for _, f := range strings.Split(os.Getenv("TEMPL_EXPERIMENT"), ",") {
m[strings.ToLower(f)] = true
}

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/03-syntax-and-usage/09-raw-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

:::caution
This page describes functionality that is experimental, and not enabled by default.
To enable this feature run the generation step with the `rawgo` experiment flag: `TEMPLEXPERIMENT=rawgo templ generate`
To enable this feature run the generation step with the `rawgo` experiment flag: `TEMPL_EXPERIMENT=rawgo templ generate`
:::

For some more advanced usecases it may be useful to write go code statements in your template.
For some more advanced use cases it may be useful to write go code statements in your template.
Use the `{{ ... }}` syntax to allow for this.

## Variable Declarations
## Variable declarations

Scoped variables can be created using this syntax, to reduce the need for multiple calls.
Scoped variables can be created using this syntax, to reduce the need for multiple function calls.

```templ title="component.templ"
package main
Expand Down
2 changes: 1 addition & 1 deletion parser/v2/gocodeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var goCode = parse.Func(func(pi *parse.Input) (n Node, ok bool, err error) {
// Clear any optional whitespace.
_, _, _ = parse.OptionalWhitespace.Parse(pi)

// }
// }}
if _, ok, err = dblCloseBraceWithOptionalPadding.Parse(pi); err != nil || !ok {
err = parse.Error("go code: missing close braces", pi.Position())
return
Expand Down
3 changes: 1 addition & 2 deletions parser/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,7 @@ func (gc GoCode) Trailing() TrailingSpace {
return gc.TrailingSpace
}

func (gc GoCode) IsNode() bool { return true }
func (gc GoCode) IsStyleDeclarationValue() bool { return true }
func (gc GoCode) IsNode() bool { return true }
func (gc GoCode) Write(w io.Writer, indent int) error {
if isWhitespace(gc.Expression.Value) {
gc.Expression.Value = ""
Expand Down

0 comments on commit 3663423

Please sign in to comment.