template

package
v0.0.0-...-122f59b Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const MaxTemplateSize = 1024 * 1024 * 1

MaxTemplateSize is 1MiB.

View Source
const TranslationJSONName = "translation.json"

Variables

View Source
var AnyFs = func(fs resource.Fs) bool {
	return true
}
View Source
var ErrLimitReached = errors.New("template: rendered template is too large")
View Source
var ErrNotFound = errors.New("requested template not found")
View Source
var ExcludeAppFs = func(fs resource.Fs) bool {
	if fs.GetFsLevel() == resource.FsLevelApp {
		return false
	}
	return true
}
View Source
var TranslationJSON = resource.RegisterResource(&translationJSON{})

Functions

func Embed

func Embed(data map[string]interface{}, value interface{})

Embed embeds the given value into data.

func EnsureTime

func EnsureTime(anyValue interface{}) interface{}

func HTMLAttr

func HTMLAttr(v string) template.HTMLAttr

func IsNil

func IsNil(v interface{}) bool

func MakeTemplateFuncMap

func MakeTemplateFuncMap(t tpl) map[string]interface{}

func RFC3339

func RFC3339(date interface{}) interface{}

func ShowAttributeValue

func ShowAttributeValue(v interface{}) string

Types

type DefaultLanguageTag

type DefaultLanguageTag string

type Engine

type Engine struct {
	Resolver EngineTemplateResolver
}

func (*Engine) Render

func (e *Engine) Render(resource Resource, preferredLanguages []string, data interface{}) (string, error)

func (*Engine) RenderStatus

func (e *Engine) RenderStatus(w http.ResponseWriter, r *http.Request, status int, tpl Resource, data interface{})

func (*Engine) Translation

func (e *Engine) Translation(preferredLanguages []string) (*TranslationMap, error)

type EngineTemplateResolver

type EngineTemplateResolver interface {
	ResolveHTML(desc *HTML, preferredLanguages []string) (*htmltemplate.Template, error)
	ResolvePlainText(desc *PlainText, preferredLanguages []string) (*texttemplate.Template, error)
	ResolveTranslations(preferredLanguages []string) (map[string]Translation, error)
}

type FindResourcesFsFilter

type FindResourcesFsFilter = func(fs resource.Fs) bool

type HTML

type HTML struct {
	// Name is the name of template
	Name string
	// ComponentDependencies is the HTML component templates this template depends on.
	ComponentDependencies []*HTML
	// IsFindAllowedInFs returns an boolean indicating if the Fs can be used to find this resources
	// For example, if you don't want a html inside the app fs to be used, it should return false.
	IsFindAllowedInFs FindResourcesFsFilter
}

HTML defines a HTML template

func RegisterAppOverridableHTML

func RegisterAppOverridableHTML(name string, dependencies ...*HTML) *HTML

func RegisterHTML

func RegisterHTML(name string, dependencies ...*HTML) *HTML

func (*HTML) FindResources

func (t *HTML) FindResources(fs resource.Fs) ([]resource.Location, error)

func (*HTML) MatchResource

func (t *HTML) MatchResource(path string) (*resource.Match, bool)

func (*HTML) UpdateResource

func (t *HTML) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)

func (*HTML) ViewResources

func (t *HTML) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)

type LimitWriter

type LimitWriter struct {
	// Writer is the underlying writer.
	Writer io.Writer
	// RemainingQuota is the remaining quota in bytes.
	RemainingQuota int64
}

func NewLimitWriter

func NewLimitWriter(w io.Writer) *LimitWriter

func (*LimitWriter) Write

func (w *LimitWriter) Write(p []byte) (n int, err error)

type PlainText

type PlainText struct {
	// Name is the name of template
	Name string
	// ComponentDependencies is the plain text component templates this template depends on.
	ComponentDependencies []*PlainText
}

PlainText defines a plain text template

func RegisterPlainText

func RegisterPlainText(name string, dependencies ...*PlainText) *PlainText

func (*PlainText) FindResources

func (t *PlainText) FindResources(fs resource.Fs) ([]resource.Location, error)

func (*PlainText) MatchResource

func (t *PlainText) MatchResource(path string) (*resource.Match, bool)

func (*PlainText) UpdateResource

func (t *PlainText) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)

func (*PlainText) ViewResources

func (t *PlainText) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)

type Resolver

type Resolver struct {
	Resources             ResourceManager
	DefaultLanguageTag    DefaultLanguageTag
	SupportedLanguageTags SupportedLanguageTags
}

func (*Resolver) ResolveHTML

func (r *Resolver) ResolveHTML(desc *HTML, preferredLanguages []string) (*htmltemplate.Template, error)

func (*Resolver) ResolvePlainText

func (r *Resolver) ResolvePlainText(desc *PlainText, preferredLanguages []string) (*texttemplate.Template, error)

func (*Resolver) ResolveTranslations

func (r *Resolver) ResolveTranslations(preferredLanguages []string) (map[string]Translation, error)

type Resource

type Resource interface {
	// contains filtered or unexported methods
}

type ResourceManager

type ResourceManager interface {
	Read(desc resource.Descriptor, view resource.View) (interface{}, error)
}

type SupportedLanguageTags

type SupportedLanguageTags []string

type Translation

type Translation struct {
	LanguageTag string
	Value       string
}

func (Translation) GetLanguageTag

func (t Translation) GetLanguageTag() string

type TranslationMap

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

func (*TranslationMap) HasKey

func (t *TranslationMap) HasKey(key string) bool

func (*TranslationMap) RenderHTML

func (t *TranslationMap) RenderHTML(key string, args interface{}) (string, error)

func (*TranslationMap) RenderText

func (t *TranslationMap) RenderText(key string, args interface{}) (string, error)

type Validator

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

func NewValidator

func NewValidator(opts ...ValidatorOption) *Validator

func (*Validator) ValidateHTMLTemplate

func (v *Validator) ValidateHTMLTemplate(template *html.Template) error

func (*Validator) ValidateTextTemplate

func (v *Validator) ValidateTextTemplate(template *text.Template) error

type ValidatorOption

type ValidatorOption func(*Validator)

func AllowDeclaration

func AllowDeclaration(b bool) ValidatorOption

func AllowIdentifierNode

func AllowIdentifierNode(b bool) ValidatorOption

func AllowRangeNode

func AllowRangeNode(b bool) ValidatorOption

func AllowTemplateNode

func AllowTemplateNode(b bool) ValidatorOption

func MaxDepth

func MaxDepth(d int) ValidatorOption

Jump to

Keyboard shortcuts

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