-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4623e39
commit 56c20d7
Showing
23 changed files
with
371 additions
and
194 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
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
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package component | ||
|
||
templ Button(text string) { | ||
<button class="button" onclick="alert('按钮被点击了!')">{ text }</button> | ||
<button class="button" onclick="alert('Clicked!')">{ text }</button> | ||
} | ||
|
||
func init() { | ||
RegisterExample("/button", Button("Click Me!")) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
package component | ||
|
||
import ( | ||
"fmt" | ||
"github.com/a-h/templ" | ||
"github.com/emirpasic/gods/v2/maps/linkedhashmap" | ||
) | ||
|
||
// nolint | ||
var ExamplePool = linkedhashmap.New[string, templ.Component]() | ||
|
||
// RegisterExample | ||
// | ||
// @Description: | ||
// @param path | ||
// @param example | ||
func RegisterExample(path string, example templ.Component) { | ||
|
||
if example == nil { | ||
return | ||
} | ||
|
||
if _, ok := ExamplePool.Get(path); ok { | ||
panic("duplicated path: " + path) | ||
} | ||
|
||
ExamplePool.Put(path, example) | ||
} | ||
|
||
// GetExample | ||
// | ||
// @Description: | ||
// @param path | ||
// @return templ.Component | ||
// @return error | ||
func GetExample(path string) (templ.Component, error) { | ||
|
||
example, ok := ExamplePool.Get(path) | ||
if !ok { | ||
return nil, fmt.Errorf("not found path: %s", path) | ||
} | ||
|
||
return example, nil | ||
} |
Oops, something went wrong.