-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable implicit context, fixes #253
- Loading branch information
Showing
6 changed files
with
166 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ul> | ||
<li>test</li> | ||
<li>the if passed</li> | ||
<li>the else if passed</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package testcontext | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/a-h/templ/generator/htmldiff" | ||
) | ||
|
||
//go:embed expected.html | ||
var expected string | ||
|
||
func Test(t *testing.T) { | ||
component := render() | ||
|
||
ctx := context.WithValue(context.Background(), contextKeyName, "test") | ||
|
||
diff, err := htmldiff.DiffCtx(ctx, component, expected) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff != "" { | ||
t.Error(diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package testcontext | ||
|
||
type contextKey string | ||
|
||
var contextKeyName contextKey = "name" | ||
|
||
templ render() { | ||
<ul> | ||
<li>{ ctx.Value(contextKeyName).(string) }</li> | ||
if ctx.Value(contextKeyName).(string) == "test" { | ||
<li>the if passed</li> | ||
} | ||
if ctx.Value(contextKeyName).(string) != "test" { | ||
<li>the else if failed</li> | ||
} else if ctx.Value(contextKeyName).(string) == "test" { | ||
<li>the else if passed</li> | ||
} | ||
</ul> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.