tplimpl

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DelimitersLeft left for the template.
	DelimitersLeft = "{{"
	// DelimitersRight right for the template.
	DelimitersRight = "}}"
)

Variables

This section is empty.

Functions

func DefaultFileHandler

func DefaultFileHandler() fileHandler

DefaultFileHandler

Accepts a template path and looks up the page template by the template path and file extension set in the engine.

Returns errors.TEMPLATE if thee file does not exist or filepath.Abs failed.

Types

type Execute

type Execute struct {
	*TemplateManager
	// contains filtered or unexported fields
}

Execute defines the data for rendering a template contains.

func (*Execute) Config

func (e *Execute) Config() tpl.TemplateConfig

Config

Satisfies the tpl.TemplateExecutor interface by returning the Execute configuration to obtain the root, extension and master layout.

func (*Execute) Execute

func (e *Execute) Execute(w io.Writer, name string, data interface{}) (string, error)

Execute

Satisfies the tpl.TemplateExecutor interface by executing a template with a io.Writer, the name of the template and any data to be passed. As this function is not attached to any context, the generic function map is used.

func (*Execute) ExecutePost

func (e *Execute) ExecutePost(w io.Writer, name string, ctx *gin.Context, post *domain.PostDatum) (string, error)

ExecutePost

Satisfies the tpl.TemplateExecutor interface by executing a template with a io.Writer, the name of the template the context and the domain.PostDatum. Data is not needed to be passed as data is obtained from the variables package.

func (*Execute) Executor

func (e *Execute) Executor() tpl.TemplateExecutor

Executor

Satisfies the tpl.TemplateExecutor interface by returning itself for use with recovery

func (*Execute) Exists

func (e *Execute) Exists(name string) bool

Exists

Satisfies the tpl.TemplateExecutor interface by determining if a template file exists with the given name.

type TemplateManager

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

TemplateManager defines the service for executing and parsing Verbis templates. It's responsible for obtaining a template.FuncMap and Data to be used within the template.

func New

func New(d *deps.Deps) *TemplateManager

New creates a new TemplateManager.

func (*TemplateManager) Data

func (t *TemplateManager) Data(ctx *gin.Context, post *domain.PostDatum) interface{}

Data

Satisfies the tpl.TemplateDataGetter interface by returning data for the front end that relies on context and post data.

func (*TemplateManager) ExecuteTpl

func (t *TemplateManager) ExecuteTpl(w io.Writer, text string, data interface{}) error

ExecuteTpl

Is a helper function for executing standard templates that are embedded.

func (*TemplateManager) FuncMap

FuncMap

Satisfies the tpl.TemplateFuncGetter interface by returning functions that relies on context and post data such as `Meta` and `url`. Generic functions are also included.

func (*TemplateManager) GenericFuncMap

func (t *TemplateManager) GenericFuncMap() template.FuncMap

GenericFuncMap

Satisfies the tpl.TemplateFuncGetter interface by returning functions that do not rely on any data that is processed at runtime. These functions are loaded on initialisation and stored in memory.

func (*TemplateManager) Prepare

Prepare

Satisfies the tpl.TemplateHandler interface by accepting a tpl.Config data and set's up the template so it's ready for execution.

Jump to

Keyboard shortcuts

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