extensions

package
v3.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: GPL-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func View

func View(options *Options, ext Extension) func(r *request.Request)

View returns a view that renders the extension into the base template.

Types

type Base added in v3.1.2

type Base struct {
	// The name of the extension.
	// This is used to uniquely identify the extension.
	ExtensionName string

	// The callback that is called when the extension is rendered.
	// This is used to get the template data and the template name.
	// The template name is the name of the template to render.
	// This is not the file name, but the name of the template.
	// IE: {{template "base" .}}
	Callback func(*request.Request) map[string]any
}

Base extension This is the base extension.

type Block

type Block struct {
	// The name of the block.
	// IE: {{define "content"}}, the block name is "content".
	BlockName string
	// The value of the block.
	// IE: {{define "content"}}Hello World{{end}}, the value is "Hello World".
	Value string
}

Block is a block of text that is rendered before or after the template.

type Extension

type Extension interface {
	// The name of the extension.
	// This is used to uniquely identify the extension.
	Name() string

	// Extra data for the extension when it is rendered.
	View(*request.Request) map[string]any
}

Template extensions These are extensions that are rendered into the base template. This is useful, if you want to allow people from other packages to extend base templates of for example; an admin panel.

type ExtensionWithFilename added in v3.1.2

type ExtensionWithFilename interface {
	Extension
	// The file name for the extension.
	// This is the name of the template to render.
	// The template will be fetched from a template.Manager.
	Filename() string
}

ExtensionWithFilename is an extension that exists of a file. This is an addition to the default extensions, where you can specify your own file as a template.

type ExtensionWithStrings added in v3.1.0

type ExtensionWithStrings interface {
	Extension
	String(*request.Request) string
}

ExtensionWithStrings is an extension that exists of a string. This is an addition to the default extensions, where you can specify your own string as a template.

type ExtensionWithTemplate added in v3.1.0

type ExtensionWithTemplate interface {
	Extension
	Template(*request.Request) *template.Template
}

ExtensionWithTemplate is an extension that has a template. This is an addition to the default extensions, where you can specify your own template.

type Options

type Options struct {
	// BaseManager is the manager for the base template.
	// It is used to get the base template, and to parse the extension template.
	BaseManager *templates.Manager

	// ExtensionManager is the manager for the extension template.
	ExtensionManager *templates.Manager

	// TemplateName is the name of the template to use as the base.
	// This is not the file name, but the name of the template.
	// IE: {{template "base" .}}
	TemplateName string

	// BlockName is the name of the block to render the template into.
	// IE: {{define "content"}}
	BlockName string

	// Called when an error occurs.
	OnError func(*request.Request, error)

	// Called before the template is rendered.
	BeforeRender func(*request.Request, *template.Template)

	// Custom blocks
	// These are blocks that are rendered before and after the template.
	CSS *Block
	JS  *Block
}

Default options for the extension view. This is used to render the extension into the base template.

type SimpleWithFilename added in v3.1.2

type SimpleWithFilename struct {
	Base
	// The file name for the extension.
	// This is the name of the template to render.
	FileName string
}

Simple extension struct. This is used to render the extension into the base template. Avoids having to create a new struct for each extension.

func (*SimpleWithFilename) Filename added in v3.1.2

func (s *SimpleWithFilename) Filename() string

Returns the file name of the extension. This is the name of the template to render. The template will be fetched from a template.Manager.

func (*SimpleWithFilename) Name added in v3.1.2

func (s *SimpleWithFilename) Name() string

Returns the name of the extension.

func (*SimpleWithFilename) View added in v3.1.2

func (s *SimpleWithFilename) View(r *request.Request) map[string]any

Returns the template data for the extension.

type SimpleWithStrings added in v3.1.1

type SimpleWithStrings struct {
	Base
	HTMLString string
}

func (*SimpleWithStrings) Name added in v3.1.1

func (s *SimpleWithStrings) Name() string

Returns the name of the extension.

func (*SimpleWithStrings) String added in v3.1.1

func (s *SimpleWithStrings) String(r *request.Request) string

func (*SimpleWithStrings) View added in v3.1.1

func (s *SimpleWithStrings) View(r *request.Request) map[string]any

Returns the template data for the extension.

type SimpleWithTemplate added in v3.1.1

type SimpleWithTemplate struct {
	Base
	HTMLTemplate *template.Template
}

func (*SimpleWithTemplate) Name added in v3.1.1

func (s *SimpleWithTemplate) Name() string

Returns the name of the extension.

func (*SimpleWithTemplate) Template added in v3.1.1

func (*SimpleWithTemplate) View added in v3.1.1

func (s *SimpleWithTemplate) View(r *request.Request) map[string]any

Returns the template data for the extension.

Jump to

Keyboard shortcuts

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