templating

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCurrency

func ExtractCurrency(tplData pongo2.Context) string

ExtractCurrency extracts the currency isocode from various locations in the supplied Context, and defaults to 'GBP'.

func ExtractTimezone

func ExtractTimezone(tplData pongo2.Context) string

ExtractTimezone extracts the time-zone isocode from various location in the supplied Context, and defaults to 'Europe/London'.

func PrepareFilters

func PrepareFilters(locale string, timezone string, currencyCode string) map[string]pongo2.FilterFunction

PrepareFilters a FilterPreparation function - prepares filters before rendering the template

Types

type AssetInfo

type AssetInfo func(name string) (os.FileInfo, error)

AssetInfo defines the sugnatire of functions used to find the template files

type FilterPreparation

type FilterPreparation func(locale string, timezone string, currencyCode string) map[string]pongo2.FilterFunction

FilterPreparation defines the signature of functions used to prepare the filters

type TemplateContext

type TemplateContext interface {
}

TemplateContext an interface to serve as a generic type passed to the TemplatePathFactory - extend later?

type TemplateInfoSource

type TemplateInfoSource interface {
	SetFormat(string)
	GetFormat(string) string
	GetTemplate() TemplateInfoSourceDetail
	GetTemplateData() map[string]interface{}
	PathOptions() ([]string, error)
}

TemplateInfoSource is a source of data to be used in rendering using a template

type TemplateInfoSourceDetail

type TemplateInfoSourceDetail interface {
	GetId() string
	GetRegulatoryArea() string
	GetLocale() string
}

TemplateInfoSourceDetail contains details for use with rendering

type TemplatePathFactory

type TemplatePathFactory func(ctx TemplateContext) ([]string, error)

TemplatePathFactory defines the signature of a function to get the paths to the templates

type Templating

type Templating struct {
	TemplateSet *pongo2.TemplateSet

	FilterPreparation FilterPreparation
	// contains filtered or unexported fields
}

Templating wraps up a set of templates (TemplateSet) with a function to find the template files, and function to prepare the filters

func NewTemplating

func NewTemplating(fetcher pongo2.TemplateFetcher, af AssetInfo) *Templating

NewTemplating creates a Templating instance - sets templatesDir and initializes template cache

func (*Templating) ExtractTemplateInfoFromRequest

func (t *Templating) ExtractTemplateInfoFromRequest(request TemplateInfoSource) (templateName string, hob string, locale string, format string)

ExtractTemplateInfoFromRequest extracts template info from the supplied TemplateInfoSource, the info being: templateName, hob, locale and format

func (*Templating) FindAndRenderTemplate

func (t *Templating) FindAndRenderTemplate(source TemplateInfoSource, templateData pongo2.Context) (string, error)

FindAndRenderTemplate finds and renders a given TemplateSet and templatePath with the upplied data and context.

func (*Templating) FindTemplatePath

func (t *Templating) FindTemplatePath(source TemplateInfoSource) (string, error)

FindTemplatePath Returns a template path based on the path-options that are given to it

func (*Templating) RenderTemplate

func (t *Templating) RenderTemplate(templatePath string, templateData pongo2.Context) (string, error)

RenderTemplate renders a given templatePath with its data retruining the rendered template as a string

func (*Templating) RenderTemplateFromSource

func (t *Templating) RenderTemplateFromSource(request TemplateInfoSource, targets ...string) (map[string]string, error)

RenderTemplateFromSource renders the supplied TemplateInfoSource using the 'self' templatData and context to a list of 'targets' output types (say, 'html', 'tsv' etc.).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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