Documentation ¶
Index ¶
- Constants
- Variables
- func Embed(data map[string]interface{}, value interface{})
- func EnsureTime(anyValue interface{}) interface{}
- func HTMLAttr(v string) template.HTMLAttr
- func IsNil(v interface{}) bool
- func MakeTemplateFuncMap(t tpl) map[string]interface{}
- func RFC3339(date interface{}) interface{}
- func ResolveError(apiErr *apierrors.APIError, input ResolveErrorRawInput) map[string]interface{}
- func ShowAttributeValue(v interface{}) string
- type DefaultLanguageTag
- type Engine
- type EngineTemplateResolver
- type GetErrorInput
- type HTML
- func (t *HTML) FindResources(fs resource.Fs) ([]resource.Location, error)
- func (t *HTML) MatchResource(path string) (*resource.Match, bool)
- func (t *HTML) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, ...) (*resource.ResourceFile, error)
- func (t *HTML) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)
- type HTMLTemplateEffectiveResource
- type LimitWriter
- type MessageHTML
- func (t *MessageHTML) FindResources(fs resource.Fs) ([]resource.Location, error)
- func (t *MessageHTML) MatchResource(path string) (*resource.Match, bool)
- func (t *MessageHTML) UpdateResource(ctx context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, ...) (*resource.ResourceFile, error)
- func (t *MessageHTML) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)
- type MessagePlainText
- func (t *MessagePlainText) FindResources(fs resource.Fs) ([]resource.Location, error)
- func (t *MessagePlainText) MatchResource(path string) (*resource.Match, bool)
- func (t *MessagePlainText) UpdateResource(ctx context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, ...) (*resource.ResourceFile, error)
- func (t *MessagePlainText) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)
- type PlainText
- func (t *PlainText) FindResources(fs resource.Fs) ([]resource.Location, error)
- func (t *PlainText) MatchResource(path string) (*resource.Match, bool)
- func (t *PlainText) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, ...) (*resource.ResourceFile, error)
- func (t *PlainText) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)
- type RenderResult
- type ResolveErrorInput
- type ResolveErrorRawInput
- type Resolver
- func (r *Resolver) ResolveHTML(desc *HTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error)
- func (r *Resolver) ResolveMessageHTML(desc *MessageHTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error)
- func (r *Resolver) ResolveMessagePlainText(desc *MessagePlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error)
- func (r *Resolver) ResolvePlainText(desc *PlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error)
- func (r *Resolver) ResolveTranslations(preferredLanguages []string) (map[string]Translation, error)
- type Resource
- type ResourceManager
- type SupportedLanguageTags
- type TextTemplateEffectiveResource
- type Translation
- type TranslationMap
- type Validator
- type ValidatorOption
Constants ¶
View Source
const MaxTemplateSize = 1024 * 1024 * 1
MaxTemplateSize is 1MiB.
View Source
const TranslationJSONName = "translation.json"
Variables ¶
View Source
var DependencySet = wire.NewSet( wire.Struct(new(Resolver), "*"), wire.Struct(new(Engine), "*"), wire.Bind(new(EngineTemplateResolver), new(*Resolver)), )
View Source
var ErrLimitReached = errors.New("template: rendered template is too large")
View Source
var ErrMissingFeatureFlagInCtx = errors.New("template: feature flag config missing in ctx")
View Source
var ErrNotFound = errors.New("requested template not found")
View Source
var ErrUpdateDisallowed = errors.New("template: update disallowed")
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 MakeTemplateFuncMap ¶
func MakeTemplateFuncMap(t tpl) map[string]interface{}
func ResolveError ¶
func ResolveError(apiErr *apierrors.APIError, input ResolveErrorRawInput) map[string]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{}) (*RenderResult, error)
func (*Engine) RenderStatus ¶
func (*Engine) Translation ¶
func (e *Engine) Translation(preferredLanguages []string) (*TranslationMap, error)
type EngineTemplateResolver ¶
type EngineTemplateResolver interface { ResolveHTML(desc *HTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error) ResolveMessageHTML(desc *MessageHTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error) ResolvePlainText(desc *PlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error) ResolveMessagePlainText(desc *MessagePlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error) ResolveTranslations(preferredLanguages []string) (map[string]Translation, error) }
type GetErrorInput ¶
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 }
HTML defines a HTML template that is non-customizable
func RegisterHTML ¶
func (*HTML) FindResources ¶
func (*HTML) UpdateResource ¶
func (t *HTML) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)
func (*HTML) ViewResources ¶
type HTMLTemplateEffectiveResource ¶
type HTMLTemplateEffectiveResource struct { Data []byte LanguageTag string Template *htmltemplate.Template }
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
type MessageHTML ¶
type MessageHTML struct { // Name is the name of template Name string }
MessageHTML defines a HTML template that is customizable
func RegisterMessageHTML ¶
func RegisterMessageHTML(name string) *MessageHTML
func (*MessageHTML) FindResources ¶
func (*MessageHTML) MatchResource ¶
func (t *MessageHTML) MatchResource(path string) (*resource.Match, bool)
func (*MessageHTML) UpdateResource ¶
func (t *MessageHTML) UpdateResource(ctx context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)
func (*MessageHTML) ViewResources ¶
func (t *MessageHTML) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, error)
type MessagePlainText ¶
type MessagePlainText struct { // Name is the name of template Name string }
MessagePlainText defines a plain text template that is customizable
func RegisterMessagePlainText ¶
func RegisterMessagePlainText(name string) *MessagePlainText
func (*MessagePlainText) FindResources ¶
func (*MessagePlainText) MatchResource ¶
func (t *MessagePlainText) MatchResource(path string) (*resource.Match, bool)
func (*MessagePlainText) UpdateResource ¶
func (t *MessagePlainText) UpdateResource(ctx context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)
func (*MessagePlainText) ViewResources ¶
func (t *MessagePlainText) ViewResources(resources []resource.ResourceFile, view resource.View) (interface{}, 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 that is non-customizable
func RegisterPlainText ¶
func (*PlainText) FindResources ¶
func (*PlainText) MatchResource ¶
func (*PlainText) UpdateResource ¶
func (t *PlainText) UpdateResource(_ context.Context, _ []resource.ResourceFile, resrc *resource.ResourceFile, data []byte) (*resource.ResourceFile, error)
func (*PlainText) ViewResources ¶
type RenderResult ¶
type ResolveErrorInput ¶
type ResolveErrorInput map[string]*GetErrorInput
type ResolveErrorRawInput ¶
type ResolveErrorRawInput map[string]interface{} // actually map[string][]string, but go template dict always map[string]interface{}
type Resolver ¶
type Resolver struct { Resources ResourceManager DefaultLanguageTag DefaultLanguageTag SupportedLanguageTags SupportedLanguageTags }
func (*Resolver) ResolveHTML ¶
func (r *Resolver) ResolveHTML(desc *HTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error)
func (*Resolver) ResolveMessageHTML ¶
func (r *Resolver) ResolveMessageHTML(desc *MessageHTML, preferredLanguages []string) (*HTMLTemplateEffectiveResource, error)
func (*Resolver) ResolveMessagePlainText ¶
func (r *Resolver) ResolveMessagePlainText(desc *MessagePlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error)
func (*Resolver) ResolvePlainText ¶
func (r *Resolver) ResolvePlainText(desc *PlainText, preferredLanguages []string) (*TextTemplateEffectiveResource, error)
func (*Resolver) ResolveTranslations ¶
func (r *Resolver) ResolveTranslations(preferredLanguages []string) (map[string]Translation, error)
type ResourceManager ¶
type ResourceManager interface {
Read(desc resource.Descriptor, view resource.View) (interface{}, error)
}
type SupportedLanguageTags ¶
type SupportedLanguageTags []string
type TextTemplateEffectiveResource ¶
type TextTemplateEffectiveResource struct { Data []byte LanguageTag string Template *texttemplate.Template }
type Translation ¶
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) 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 ¶
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
Click to show internal directories.
Click to hide internal directories.