render

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package render contains utility functions that make it easier to render content in a web service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileRenderer

type FileRenderer struct {
	// contains filtered or unexported fields
}

FileRenderer is a renderer that can be used to render files (as opposed to HTML pages) in a embedded FS. Note that this only supports individual file templates and does not support componentization.

func NewFileRenderer

func NewFileRenderer(logger *zap.Logger, opts FileRendererOpts) (*FileRenderer, error)

NewFileRenderer will load the file templates from the views FS and load each template as a named template by its path.

func (FileRenderer) RenderFile

func (r FileRenderer) RenderFile(tplPath string, data interface{}) (string, error)

RenderFile will render the file template at the given path using the provided data.

type FileRendererOpts

type FileRendererOpts struct {
	ViewsFS         embed.FS
	GlobPath        string
	CustomFunctions template.FuncMap
}

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(logger *zap.Logger, opts RendererOpts) (*Renderer, error)

NewRenderer will load the templates from the views FS and load each page template as a named template by its path. Note that every template will include all the templates from the layouts and components folder so that cross references work, but NOT individual pages. This means that a page template can reference components and layouts with a template directive, but will not be able to load templates from another page.

func (Renderer) RenderHTML

func (r Renderer) RenderHTML(tplPath string, data interface{}) (string, error)

RenderHTML will render the html template at the given path using the provided data.

type RendererOpts

type RendererOpts struct {
	ViewsFS           embed.FS
	LayoutGlobPath    string
	ComponentGlobPath string
	PageGlobPath      string
	CustomFunctions   template.FuncMap
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL