theme

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

README

Go-Enjin Theme System

The Go-Enjin theming system is inspired by the hugo theme system. A hugo theme is not intended to be directly usable within Go-Enjin though that would be a "nice to have" goal.

The Go-Enjin theming system provides the following features:

  • include a theme from a local filesystem
  • include a theme from an embedded filesystem
  • include multiple themes
  • one theme can extend one other theme
  • easily switch between themes
  • contains an embedded default pair of themes: dark and light
  • caches the processing output when given the same inputs
  • directory and file structure mimic hugo themes
  • can be used as a standalone Go library

Default Theme Structure:

    theme-name/
        layouts/
            _default/
                single.html
                list.html
            partials/
                footer.html
                footer/
                    nav.html
                    fineprint.html
                head.html
                head/
                    favicon.html
                    metadata.html
                    social.html
                header.html
                header/
                    nav.html
                    banner.html
    	static/
            styles.css
        archetypes/
            default.md

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCacheControl = "public, max-age=604800, no-transform, immutable"
)

Functions

func AddParseTree

func AddParseTree(src, dst *template.Template) (err error)

func AddRegisteredHtmlFuncsToMap

func AddRegisteredHtmlFuncsToMap(fm *htmlTemplate.FuncMap)

func AddRegisteredTextFuncsToMap

func AddRegisteredTextFuncsToMap(fm *textTemplate.FuncMap)

func DefaultFuncMap

func DefaultFuncMap() (funcMap htmlTemplate.FuncMap)

func GetFuncMap

func GetFuncMap(key string) (fn interface{}, ok bool)

func LookupTemplate

func LookupTemplate(tt *template.Template, names ...string) (tmpl *template.Template)

func RegisterFuncMap

func RegisterFuncMap(key string, fn interface{})

func RegisterPartialBodyHead added in v0.1.0

func RegisterPartialBodyHead(name, tmpl string)

func RegisterPartialBodyTail added in v0.1.0

func RegisterPartialBodyTail(name, tmpl string)

func RegisterPartialHeadHead added in v0.1.0

func RegisterPartialHeadHead(name, tmpl string)

func RegisterPartialHeadTail added in v0.1.0

func RegisterPartialHeadTail(name, tmpl string)

Types

type Archetype

type Archetype struct {
}

type Author

type Author struct {
	Name     string
	Homepage string
}

type Config

type Config struct {
	Name        string
	Parent      string
	License     string
	LicenseLink string
	Description string
	Homepage    string
	Authors     []Author
	Extends     string

	GoogleAnalytics GoogleAnalyticsConfig

	RootStyles  []template.CSS
	BlockStyles map[string][]template.CSS
	BlockThemes map[string]map[string]interface{}

	FontawesomeLinks   map[string]string
	FontawesomeClasses []string

	CacheControl string

	PermissionsPolicy     []permissions.Directive
	ContentSecurityPolicy csp.ContentSecurityPolicyConfig

	Context context.Context
}

type GoogleAnalyticsConfig

type GoogleAnalyticsConfig struct {
	GTM string
}

type Layout

type Layout struct {
	Path string
	Name string
	Keys []string

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLayout

func NewLayout(path string, efs beFs.FileSystem, t *Theme) (layout *Layout, err error)

func (*Layout) Apply

func (l *Layout) Apply(tt *template.Template, ctx context.Context) (err error)

func (*Layout) HasKey

func (l *Layout) HasKey(key string) bool

func (*Layout) NewTemplate

func (l *Layout) NewTemplate(ctx context.Context) (tmpl *template.Template, err error)

func (*Layout) NewTemplateFrom

func (l *Layout) NewTemplateFrom(parent *Layout, ctx context.Context) (tmpl *template.Template, err error)

func (*Layout) Reload

func (l *Layout) Reload() (err error)

type Layouts

type Layouts struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLayouts

func NewLayouts(t *Theme) (layouts *Layouts, err error)

func (*Layouts) GetLayout

func (l *Layouts) GetLayout(name string) (layout *Layout)

func (*Layouts) NewTemplate

func (l *Layouts) NewTemplate(name string, ctx context.Context) (tmpl *template.Template, err error)

func (*Layouts) Reload

func (l *Layouts) Reload() (err error)

func (*Layouts) SetLayout

func (l *Layouts) SetLayout(name string, layout *Layout)

type Theme

type Theme struct {
	Name   string
	Path   string
	Config Config
	Minify bool

	FuncMap    template.FuncMap
	Layouts    *Layouts
	Archetypes map[string]*Archetype

	FileSystem fs.FileSystem
	StaticFS   fs.FileSystem

	FormatProviders []types.FormatProvider
}

func New

func New(path string, fs fs.FileSystem) (t *Theme, err error)

func (*Theme) AddFormatProvider

func (t *Theme) AddFormatProvider(providers ...types.FormatProvider)

func (*Theme) FS

func (t *Theme) FS() fs.FileSystem

func (*Theme) FindLayout

func (t *Theme) FindLayout(named string) (layout *Layout, name string, ok bool)

func (*Theme) GetBlockThemeNames

func (t *Theme) GetBlockThemeNames() (names []string)

func (*Theme) GetConfig

func (t *Theme) GetConfig() (config Config)

func (*Theme) GetFormat

func (t *Theme) GetFormat(name string) (format types.Format)

func (*Theme) GetParent

func (t *Theme) GetParent() (parent *Theme)

func (*Theme) GetParentTheme

func (t *Theme) GetParentTheme() (parent types.Theme)

func (*Theme) ListFormats added in v0.1.0

func (t *Theme) ListFormats() (names []string)

func (*Theme) Locales

func (t *Theme) Locales() (locales fs.FileSystem, ok bool)

func (*Theme) MatchFormat

func (t *Theme) MatchFormat(filename string) (format types.Format, match string)

func (*Theme) Middleware

func (t *Theme) Middleware(next http.Handler) http.Handler

func (*Theme) NewHtmlFuncMapWithContext

func (t *Theme) NewHtmlFuncMapWithContext(ctx context.Context) (fm htmlTemplate.FuncMap)

func (*Theme) NewHtmlTemplateWithContext

func (t *Theme) NewHtmlTemplateWithContext(name string, ctx context.Context) (tmpl *htmlTemplate.Template, err error)

func (*Theme) NewTextFuncMapWithContext

func (t *Theme) NewTextFuncMapWithContext(ctx context.Context) (fm textTemplate.FuncMap)

func (*Theme) NewTextTemplateWithContext

func (t *Theme) NewTextTemplateWithContext(name string, ctx context.Context) (tmpl *textTemplate.Template, err error)

func (*Theme) Render

func (t *Theme) Render(view string, ctx context.Context) (data []byte, err error)

func (*Theme) RenderHtmlTemplateContent

func (t *Theme) RenderHtmlTemplateContent(ctx context.Context, tmplContent string) (rendered string, err error)

func (*Theme) RenderPage

func (t *Theme) RenderPage(ctx context.Context, p *page.Page) (data []byte, redirect string, err error)

func (*Theme) RenderTextTemplateContent

func (t *Theme) RenderTextTemplateContent(ctx context.Context, tmplContent string) (rendered string, err error)

func (*Theme) TemplateFromContext

func (t *Theme) TemplateFromContext(view string, ctx context.Context) (tt *htmlTemplate.Template, err error)

Jump to

Keyboard shortcuts

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