docs(html): add AX usage examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
cafa24163d
commit
24565df459
2 changed files with 15 additions and 1 deletions
|
|
@ -1,7 +1,11 @@
|
|||
package html
|
||||
|
||||
// context.go: Translator provides Text() lookups for a rendering context.
|
||||
// Example: a locale-aware service can satisfy T(key, args...).
|
||||
// Example: type service struct{}
|
||||
//
|
||||
// func (service) T(key string, args ...any) string { return key }
|
||||
//
|
||||
// ctx := NewContextWithService(service{}, "en-GB")
|
||||
type Translator interface {
|
||||
T(key string, args ...any) string
|
||||
}
|
||||
|
|
|
|||
10
layout.go
10
layout.go
|
|
@ -13,6 +13,7 @@ var _ Node = (*Layout)(nil)
|
|||
|
||||
// ErrInvalidLayoutVariant reports that a layout variant string contains at
|
||||
// least one unrecognised slot character.
|
||||
// Example: errors.Is(ValidateLayoutVariant("HXC"), ErrInvalidLayoutVariant).
|
||||
var ErrInvalidLayoutVariant = errors.New("html: invalid layout variant")
|
||||
|
||||
// slotMeta holds the semantic HTML mapping for each HLCRF slot.
|
||||
|
|
@ -215,6 +216,13 @@ func (l *Layout) Render(ctx *Context) string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
// LayoutVariantError describes the invalid characters found in a layout
|
||||
// variant string.
|
||||
// Example: var variantErr *LayoutVariantError
|
||||
//
|
||||
// if errors.As(err, &variantErr) {
|
||||
// _ = variantErr.InvalidSlots()
|
||||
// }
|
||||
type LayoutVariantError struct {
|
||||
variant string
|
||||
invalidSlots []byte
|
||||
|
|
@ -258,6 +266,7 @@ func (e *LayoutVariantError) Unwrap() error {
|
|||
|
||||
// InvalidSlots returns a copy of the invalid slot characters that were present
|
||||
// in the original variant string.
|
||||
// Example: string(variantErr.InvalidSlots()) // "1X?"
|
||||
func (e *LayoutVariantError) InvalidSlots() []byte {
|
||||
if e == nil || len(e.invalidSlots) == 0 {
|
||||
return nil
|
||||
|
|
@ -267,6 +276,7 @@ func (e *LayoutVariantError) InvalidSlots() []byte {
|
|||
|
||||
// InvalidPositions returns a copy of the 1-based positions of the invalid slot
|
||||
// characters in the original variant string.
|
||||
// Example: variantErr.InvalidPositions() // []int{2, 3, 4}
|
||||
func (e *LayoutVariantError) InvalidPositions() []int {
|
||||
if e == nil || len(e.invalidPositions) == 0 {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue