docs(codegen): standardise AX examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
89d2870e20
commit
0716fe991f
2 changed files with 6 additions and 6 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
log "dappco.re/go/core/log"
|
||||
)
|
||||
|
||||
// buildComponentJS takes a JSON slot map and returns the WC bundle JS string.
|
||||
// cmd/wasm/register.go: buildComponentJS takes a JSON slot map and returns the WC bundle JS string.
|
||||
// This is the pure-Go part testable without WASM.
|
||||
// Excluded from WASM builds — encoding/json and text/template are too heavy.
|
||||
// Use cmd/codegen/ CLI instead for build-time generation.
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ var wcTemplate = template.Must(template.New("wc").Parse(`class {{.ClassName}} ex
|
|||
|
||||
// codegen/codegen.go: GenerateClass produces a JS class definition for a custom element.
|
||||
//
|
||||
// cls, err := GenerateClass("nav-bar", "H")
|
||||
// Example: cls, err := GenerateClass("nav-bar", "H")
|
||||
func GenerateClass(tag, slot string) (string, error) {
|
||||
if !isValidCustomElementTag(tag) {
|
||||
return "", log.E("codegen.GenerateClass", "custom element tag must be a lowercase hyphenated name: "+tag, nil)
|
||||
|
|
@ -79,14 +79,14 @@ func GenerateClass(tag, slot string) (string, error) {
|
|||
|
||||
// codegen/codegen.go: GenerateRegistration produces the customElements.define() call.
|
||||
//
|
||||
// js := GenerateRegistration("nav-bar", "NavBar")
|
||||
// Example: GenerateRegistration("nav-bar", "NavBar")
|
||||
func GenerateRegistration(tag, className string) string {
|
||||
return fmt.Sprintf(`customElements.define("%s", %s);`, tag, className)
|
||||
}
|
||||
|
||||
// codegen/codegen.go: TagToClassName converts a kebab-case tag to PascalCase class name.
|
||||
//
|
||||
// className := TagToClassName("nav-bar") // NavBar
|
||||
// Example: className := TagToClassName("nav-bar") // NavBar
|
||||
func TagToClassName(tag string) string {
|
||||
var b strings.Builder
|
||||
for p := range strings.SplitSeq(tag, "-") {
|
||||
|
|
@ -101,7 +101,7 @@ func TagToClassName(tag string) string {
|
|||
// codegen/codegen.go: GenerateBundle produces all WC class definitions and registrations
|
||||
// for a set of HLCRF slot assignments.
|
||||
//
|
||||
// js, err := GenerateBundle(map[string]string{"H":"nav-bar", "C":"main-content"})
|
||||
// Example: js, err := GenerateBundle(map[string]string{"H":"nav-bar", "C":"main-content"})
|
||||
func GenerateBundle(slots map[string]string) (string, error) {
|
||||
if err := validateSlotKeys(slots); err != nil {
|
||||
return "", err
|
||||
|
|
@ -125,7 +125,7 @@ func GenerateBundle(slots map[string]string) (string, error) {
|
|||
// codegen/codegen.go: GenerateTypeDefinitions produces a TypeScript declaration file for the
|
||||
// generated custom elements.
|
||||
//
|
||||
// dts, err := GenerateTypeDefinitions(map[string]string{"H":"nav-bar"})
|
||||
// Example: dts, err := GenerateTypeDefinitions(map[string]string{"H":"nav-bar"})
|
||||
func GenerateTypeDefinitions(slots map[string]string) (string, error) {
|
||||
if err := validateSlotKeys(slots); err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue