html

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package html maps your filesystem to `html/template` and handles templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin interface {
	TemplateFuncs() template.FuncMap
}

Plugin for Renderer to add template functions with

type Renderer

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

Renderer holds settings and config to Render with

func NewRenderer

func NewRenderer(settings *Settings, plugins []Plugin, log logrus.FieldLogger) *Renderer

NewRenderer returns a new instance of Renderer

func (*Renderer) Render

func (renderer *Renderer) Render(name string, layoutData interface{}) ([]byte, error)

Render calls RenderWithLayout with the default layoutName from html.Settings.LayoutName

func (*Renderer) RenderWithLayout

func (renderer *Renderer) RenderWithLayout(layoutName, templateName string, layoutData interface{}) ([]byte, error)

RenderWithLayout renders the given templateName with the given layoutName and data It finds the templates within the given html.Settings.TemplatePath.

Default template functions are provided in addition to the plugin template functions. See https://github.com/s12chung/gostatic/blob/master/go/lib/html/helpers.go for a list of default helper functions.

type Scratch

type Scratch struct {
	M map[string]interface{}
}

Scratch is a struct holding temp data, inspired by: https://gohugo.io/functions/scratch

func NewScratch

func NewScratch() *Scratch

NewScratch returns a clean instance of Scratch

func (*Scratch) Append

func (s *Scratch) Append(key string, value interface{}) string

Append appends the value to an []interface{} at key

func (*Scratch) Delete

func (s *Scratch) Delete(key string) string

Delete deletes the value at key

func (*Scratch) Get

func (s *Scratch) Get(key string) interface{}

Get returns the value at key

func (*Scratch) HasKey

func (s *Scratch) HasKey(key string) bool

HasKey returns true if the key exists

func (*Scratch) Set

func (s *Scratch) Set(key string, value interface{}) string

Set sets the key/value of the Scratch

type Settings

type Settings struct {
	TemplatePath string `json:"template_path,omitempty"`
	TemplateExt  string `json:"template_ext,omitempty"`
	LayoutName   string `json:"layoutName,omitempty"`
	WebsiteTitle string `json:"website_title,omitempty"`
}

Settings represents the settings of the HTML templates

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings is the default settings of the HTML templates

Jump to

Keyboard shortcuts

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