templates

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package templates used for load templates from file system and render template to HTML

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assets

type Assets interface {
	Open(string) (io.Reader, error)
}

Assets interface.

type AssetsLoader

type AssetsLoader interface {
	LoadAssets(
		templateDirPath string,
		logger log.Logger,
	) Assets
}

AssetsLoader interface.

type Data

type Data map[string]interface{}

Data for render and examples.

type DefaultRenderer

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

DefaultRenderer is default implementation of TemplatesRender.

func NewDefaultRenderer

func NewDefaultRenderer(
	store Store,
	tracerProvider trace.TracerProvider,
) *DefaultRenderer

NewDefaultRenderer constructor.

func (*DefaultRenderer) RenderHTMLExample

func (render *DefaultRenderer) RenderHTMLExample(
	ctx context.Context,
	templateName Name,
	exampleName string,
) (
	*RenderResult,
	error,
)

RenderHTMLExample template by name and example.

func (*DefaultRenderer) RenderHTMLWithData

func (render *DefaultRenderer) RenderHTMLWithData(
	ctx context.Context,
	templateName Name,
	data Data,
) (
	*RenderResult,
	error,
)

RenderHTMLWithData template by name and data.

type ExampleNotExistsError

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

ExampleNotExistsError returned on DefaultRenderer.RenderHTMLExample.

func NewExampleNotExistsError

func NewExampleNotExistsError(exampleName string) *ExampleNotExistsError

NewExampleNotExistsError construct new ExampleNotExistsError.

func (*ExampleNotExistsError) Error

func (err *ExampleNotExistsError) Error() string

func (*ExampleNotExistsError) Is

func (err *ExampleNotExistsError) Is(otherErr error) bool

Is implements errors.Is.

type Examples

type Examples map[string]Data

Examples map.

type ExamplesLoader

type ExamplesLoader interface {
	LoadExamples(
		templateDirPath string,
		logger log.Logger,
	) (Examples, error)
}

ExamplesLoader interface.

type InvalidDataSchemaError

type InvalidDataSchemaError struct{}

InvalidDataSchemaError returned by Validator when provided data is not valid.

func (*InvalidDataSchemaError) Error

func (err *InvalidDataSchemaError) Error() string

func (*InvalidDataSchemaError) Is

func (err *InvalidDataSchemaError) Is(otherError error) bool

Is used by errors.Is.

type JSONSchemaValidator

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

JSONSchemaValidator validate data with json schema.

func NewJSONSchemaValidator

func NewJSONSchemaValidator(rawSchema []byte) (*JSONSchemaValidator, error)

NewJSONSchemaValidator construct new JSONSchemaValidator.

func (*JSONSchemaValidator) MarshalJSON

func (validator *JSONSchemaValidator) MarshalJSON() ([]byte, error)

MarshalJSON return raw schema representation. nolint:unparam

func (*JSONSchemaValidator) ValidateData

func (validator *JSONSchemaValidator) ValidateData(ctx context.Context, data interface{}) error

ValidateData match provided data with JSON schema.

type List

type List []*Template

List wrap templates slice and implement sort.Sort interface.

func (List) Len

func (list List) Len() int

func (List) Less

func (list List) Less(i, j int) bool

func (List) Swap

func (list List) Swap(i, j int)

type MapStore

type MapStore map[Name]*Template

MapStore is simple templates store.

func (MapStore) Fetch

func (store MapStore) Fetch(templateName Name) (*Template, error)

Fetch template by name.

func (MapStore) List

func (store MapStore) List() ([]*Template, error)

List all templates nolint:unparam

type Name

type Name string

Name of template.

type PDFParams

type PDFParams struct {
	Landscape         *bool    `json:"landscape"`
	PrintBackground   *bool    `json:"printBackground"`
	PreferCSSPageSize *bool    `json:"preferCSSPageSize"`
	Scale             *float64 `json:"scale"`
	PaperWidth        *float64 `json:"paperWidth"`
	PaperHeight       *float64 `json:"paperHeight"`
	MarginTop         *float64 `json:"marginTop"`
	MarginBottom      *float64 `json:"marginBottom"`
	MarginLeft        *float64 `json:"marginLeft"`
	MarginRight       *float64 `json:"marginRight"`
}

PDFParams definition.

func (*PDFParams) GetLandscape

func (params *PDFParams) GetLandscape() *bool

GetLandscape return params Landscape.

func (*PDFParams) GetMarginBottom

func (params *PDFParams) GetMarginBottom() *float64

GetMarginBottom return params MarginBottom.

func (*PDFParams) GetMarginLeft

func (params *PDFParams) GetMarginLeft() *float64

GetMarginLeft return params MarginLeft.

func (*PDFParams) GetMarginRight

func (params *PDFParams) GetMarginRight() *float64

GetMarginRight return params MarginRight.

func (*PDFParams) GetMarginTop

func (params *PDFParams) GetMarginTop() *float64

GetMarginTop return params MarginTop.

func (*PDFParams) GetPaperHeight

func (params *PDFParams) GetPaperHeight() *float64

GetPaperHeight return params PaperHeight.

func (*PDFParams) GetPaperWidth

func (params *PDFParams) GetPaperWidth() *float64

GetPaperWidth return params PaperWidth.

func (*PDFParams) GetPreferCSSPageSize

func (params *PDFParams) GetPreferCSSPageSize() *bool

GetPreferCSSPageSize return params PreferCSSPageSize.

func (*PDFParams) GetPrintBackground

func (params *PDFParams) GetPrintBackground() *bool

GetPrintBackground return params PrintBackground.

func (*PDFParams) GetScale

func (params *PDFParams) GetScale() *float64

GetScale return params Scale.

type Params

type Params struct {
	PDF PDFParams `json:"pdf"`
}

Params definition.

type ParamsLoader

type ParamsLoader interface {
	LoadParams(
		templateDirPath string,
		logger log.Logger,
	) (*Params, error)
}

ParamsLoader interface.

type RenderResult

type RenderResult struct {
	BodyPayload   string
	HeaderPayload *string
	FooterPayload *string
	PDFParams     *PDFParams
}

RenderResult returned by Renderer interface.

type Renderer

type Renderer interface {
	RenderHTMLWithData(
		ctx context.Context,
		templateName Name,
		data Data,
	) (*RenderResult, error)
	RenderHTMLExample(
		ctx context.Context,
		templateName Name,
		exampleName string,
	) (*RenderResult, error)
}

Renderer engine interface.

type SchemaLoader

type SchemaLoader interface {
	LoadSchema(
		templateDirPath string,
		logger log.Logger,
	) (Validator, error)
}

SchemaLoader interface.

type Store

type Store interface {
	Fetch(Name) (*Template, error)
	List() ([]*Template, error)
}

Store of templates.

type Template

type Template struct {
	Name
	Body   TemplateInstance
	Header TemplateInstance
	Footer TemplateInstance
	*Params
	Validator Validator
	Assets
	Examples
}

Template wrap TemplateInstance with Schema.

type TemplateInstance

type TemplateInstance interface {
	Render(data interface{}) (string, error)
}

TemplateInstance render template with data.

type TemplateInstanceLoader

type TemplateInstanceLoader interface {
	LoadTemplateInstance(
		templateDirPath string,
		partName string,
		logger log.Logger,
	) (TemplateInstance, error)
}

TemplateInstanceLoader interface.

type TemplateLoader

type TemplateLoader interface {
	LoadTemplate(
		templateDirPath string,
		templateName string,
		logger log.Logger,
	) (*Template, error)
}

TemplateLoader interface.

type TemplateNotExistsError

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

TemplateNotExistsError returned from Store.Fetch.

func NewTemplateNotExistsError

func NewTemplateNotExistsError(templateName Name) *TemplateNotExistsError

NewTemplateNotExistsError construct new TemplateNotExistsError.

func (*TemplateNotExistsError) Error

func (err *TemplateNotExistsError) Error() string

func (*TemplateNotExistsError) Is

func (err *TemplateNotExistsError) Is(otherErr error) bool

Is implement errors.Is.

type Validator

type Validator interface {
	ValidateData(ctx context.Context, data interface{}) error
	MarshalJSON() ([]byte, error)
}

Validator validate render data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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