-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templ): add context support for templ
- Loading branch information
1 parent
f3ec0d8
commit 0ddf6f0
Showing
3 changed files
with
184 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; inherits: go,html | ||
|
||
([ | ||
(component_declaration) | ||
(script_declaration) | ||
(css_declaration) | ||
(component_switch_statement) | ||
(component_switch_expression_case) | ||
(component_switch_default_case) | ||
] @context) | ||
|
||
(component_if_statement | ||
consequence: (component_block (_) @context.end) | ||
) @context | ||
|
||
(component_for_statement | ||
body: (component_block (_) @context.end) | ||
) @context | ||
|
||
(component_import | ||
body: (component_block (_) @context.end) | ||
) @context |
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,161 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
|
||
|
||
|
||
|
||
"time" | ||
) | ||
|
||
templ headerTemplate(name string) { | ||
<header data-testid="headerTemplate"> | ||
switch name { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
case "Alice", "Bob": | ||
<h1>{ name }</h1> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
default: | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h1>{ "Unknown" }</h1> | ||
} | ||
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script> | ||
<style type="text/css"> | ||
p { | ||
font-family: sans-serif; | ||
} | ||
</style> | ||
</header> | ||
} | ||
|
||
templ posts(posts []Post) { | ||
@layout("Posts") { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
@postsTemplate(posts) | ||
if len(posts) > 0 { | ||
<div>{ "Not empty" }</div> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} else { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div>{ "Empty" }</div> | ||
} | ||
} | ||
} | ||
|
||
templ postsTemplate(posts []Post) { | ||
<div data-testid="postsTemplate"> | ||
for _, p := range posts { | ||
|
||
<div data-testid="postsTemplatePost"> | ||
<div data-testid="postsTemplatePostName">{ p.Name }</div> | ||
<div data-testid="postsTemplatePostAuthor">{ p.Author }</div> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
} | ||
</div> | ||
} | ||
|
||
script withParameters(a string, b string, c int) { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
console.log(a, b, c); | ||
} | ||
|
||
css red() { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
background-color: #ff0000; | ||
font-family: "Iosevka"; | ||
} |