Documentation
¶
Overview ¶
Package core provides core rendering functionality. Use Render to evaluate a node graph and write it to an io.Writer, or Dump to write to stdout for debugging.
Example (Fallback) ¶
Fallback() catches render errors and substitutes alternative content. Useful for graceful degradation of page sections.
package main
import (
"context"
"errors"
"github.com/protolambda/chord/core"
"github.com/protolambda/chord/core/attr"
"github.com/protolambda/chord/core/elem"
"github.com/protolambda/chord/html/text"
)
func main() {
unreliable := elem.Fn(func(ctx context.Context) (elem.Node, error) {
return nil, errors.New("database unavailable")
})
core.Dump(core.Fallback(
elem.New("div")(unreliable),
func(ctx context.Context, err error) elem.Node {
return elem.New("div", attr.KV("class", "error"))(
text.Text("Failed to load content"))
},
))
}
Output: <div class="error">Failed to load content</div>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DumpCtx ¶
DumpCtx prints the element (evaluated with ctx) to stdout, for convenience in testing and debugging.
Types ¶
type FallbackFn ¶
FallbackFn is called when a render error occurs to provide alternative content.
type Option ¶
type Option func(*renderConfig)
Option applies a configuration to the renderer.
func WithIndent ¶
func WithIndent() Option
WithIndent enables indentation of elements with two spaces per depth level.
Example ¶
Dump(
elem.New("div", attr.KV("class", "outer"), attr.KV("id", "root"))(
elem.New("div", attr.KV("class", "middle"))(
elem.New("div", attr.KV("class", "inner"))(
elem.Raw("Hello"),
),
elem.New("span")(elem.Raw("World")),
),
),
WithIndent(),
)
Output: <div class="outer" id="root"> <div class="middle"> <div class="inner"> Hello </div> <span> World </span> </div> </div>
Click to show internal directories.
Click to hide internal directories.