package renderer
import "github.com/go-arrower/arrower/renderer"
Package renderer provides renderers for web views and unit tests.
The renderer expects a fs.FS with the following folder structure:
- . - layouts in which the pages are embedded.
- pages - the actual pages to render. They can include page scoped fragments and components.
- components - containing fragments of a page that are shared with each page template.
Index ¶
- Constants
- Variables
- type DataFunc
- type EchoRenderer
- func NewEchoRenderer( logger alog.Logger, traceProvider trace.TracerProvider, echo *echo.Echo, viewFS fs.FS, hotReload bool, ) (*EchoRenderer, error)
- func (r *EchoRenderer) Render(w io.Writer, templateName string, data interface{}, c echo.Context) error
- type Map
- type Renderer
- func New( logger alog.Logger, traceProvider trace.TracerProvider, viewFS fs.FS, funcMap template.FuncMap, hotReload bool, ) (*Renderer, error)
- func (r *Renderer) AddBaseData(baseName string, dataFunc DataFunc) error
- func (r *Renderer) AddContext(name string, viewFS fs.FS) error
- func (r *Renderer) AddLayoutData(context string, layoutName string, dataFunc DataFunc) error
- func (r *Renderer) Render(ctx context.Context, w io.Writer, contextName string, templateName string, data interface{}) error
- type RendererAssertions
- func (a *RendererAssertions) Contains(contains any, msgAndArgs ...any) bool
- func (a *RendererAssertions) NotEmpty(msgAndArgs ...any) bool
- type TestRenderer
Constants ¶
const (
= ""
)Variables ¶
var ( ErrCreateRendererFailed = errors.New("create renderer failed") ErrRenderFailed = errors.New("rendering failed") ErrNotExistsComponent = fmt.Errorf("%w: component does not exist", ErrRenderFailed) ErrNotExistsPage = fmt.Errorf("%w: page does not exist", ErrRenderFailed) ErrNotExistsFragment = fmt.Errorf("%w: fragment does not exist", ErrRenderFailed) ErrNotExistsLayout = fmt.Errorf("%w: layout does not exist", ErrRenderFailed) // todo new err for base as well? ErrContextNotAdded = errors.New("context not added") )
Types ¶
type DataFunc ¶
type EchoRenderer ¶
type EchoRenderer struct { *Renderer }
EchoRenderer is a wrapper that makes the Renderer available for the echo router: https://echo.labstack.com/
func NewEchoRenderer ¶
func NewEchoRenderer( logger alog.Logger, traceProvider trace.TracerProvider, echo *echo.Echo, viewFS fs.FS, hotReload bool, ) (*EchoRenderer, error)
func (*EchoRenderer) Render ¶
func (r *EchoRenderer) Render(w io.Writer, templateName string, data interface{}, c echo.Context) error
type Map ¶
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
func New ¶
func New( logger alog.Logger, traceProvider trace.TracerProvider, viewFS fs.FS, funcMap template.FuncMap, hotReload bool, ) (*Renderer, error)
New prepares a renderer for HTML web views.
func (*Renderer) AddBaseData ¶
func (*Renderer) AddContext ¶
func (*Renderer) AddLayoutData ¶
func (*Renderer) Render ¶
func (r *Renderer) Render(ctx context.Context, w io.Writer, contextName string, templateName string, data interface{}) error
type RendererAssertions ¶
type RendererAssertions struct {
// contains filtered or unexported fields
}
RendererAssertions is a helper that exposes a lot of TestRenderer-specific assertions for the use in tests. The interface follows stretchr/testify as close as possible.
- Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions.
func (*RendererAssertions) Contains ¶
func (a *RendererAssertions) Contains(contains any, msgAndArgs ...any) bool
func (*RendererAssertions) NotEmpty ¶
func (a *RendererAssertions) NotEmpty(msgAndArgs ...any) bool
NotEmpty asserts that the html is not empty.
type TestRenderer ¶
type TestRenderer struct {
// contains filtered or unexported fields
}
func Test ¶
func (*TestRenderer) Render ¶
func (r *TestRenderer) Render( t *testing.T, ctx context.Context, context string, name string, data interface{}, ) (*RendererAssertions, error)
Source Files ¶
echo-renderer.go renderer.go testing.go
- Version
- v0.0.0-20250311203644-ab26c1152cb4 (latest)
- Published
- Mar 11, 2025
- Platform
- linux/amd64
- Imports
- 21 packages
- Last checked
- 1 week ago –
Tools for package owners.