libtemplate

package module
v0.0.0-...-7e7f9ea Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

README

libtemplate

Documentation

Index

Constants

View Source
const (
	DefaultSuffix = ".gohtml"
)
View Source
const LoginName = "login"

LoginName is the name of the login template.

Variables

This section is empty.

Functions

func New

func New(f template.FuncMap, fs embed.FS, directory, suffix string) (*template.Template, error)

New creates a new templates.

func SetActive

func SetActive(a ActivableSlice, s string)

SetActive sets an active bit in a slice.

Types

type ActivableSlice

type ActivableSlice interface {
	GetChildren(i int) ActivableSlice
	GetMatcher(i int) *regexp.Regexp
	SetActive(i int, a bool)
	Len() int
}

ActivableSlice a slice where each element has an active bit which can be set based on a string.

type Alert

type Alert struct {
	Color        Color
	Header       string
	Text         string
	Button       *Button
	DisableClose bool
}

Alert is a page alert.

type AlertBars

type AlertBars *[]Alert

AlertBars is a set of alerts to display together.

type Badge

type Badge struct {
	Color Color
	Text  string
}

type Button

type Button struct {
	Color Color
	Text  string
	HRef  string
}

Button is a page alert.

type Color

type Color string
const (
	ColorPrimary   Color = "primary"
	ColorSecondary Color = "secondary"
	ColorSuccess   Color = "success"
	ColorDanger    Color = "danger"
	ColorWarning   Color = "warning"
	ColorInfo      Color = "info"
	ColorLight     Color = "light"
	ColorDark      Color = "dark"
)

type FormInput

type FormInput struct {
	ID           string
	Type         FormInputType
	Name         string
	Placeholder  string
	Label        *FormLabel
	Help         LocalizedString
	Value        string
	Disabled     bool
	Required     bool
	Checked      bool
	ExtraClasses []string
	Validation   *FormValidation
}

FormInput is a templated form input.

type FormInputType

type FormInputType string
const (
	// FormInputTypeCheckbox is a checkbox html input field.
	FormInputTypeCheckbox FormInputType = "checkbox"
	// FormInputTypeFile is a file html input field.
	FormInputTypeFile FormInputType = "file"
	// FormInputTypeHidden is a hidden html input field.
	FormInputTypeHidden FormInputType = "hidden"
	// FormInputTypePassword is a password html input field.
	FormInputTypePassword FormInputType = "password"
	// FormInputTypeRadio is a radio html input field.
	FormInputTypeRadio FormInputType = "radio"
	// FormInputTypeText is a text html input field.
	FormInputTypeText FormInputType = "text"
)

type FormLabel

type FormLabel struct {
	Text  LocalizedString
	Badge *Badge
	Class string
}

type FormRadio

type FormRadio struct {
	ID         string
	Name       string
	Values     []Value
	Selected   string
	Disabled   bool
	Required   bool
	Validation *FormValidation
}

FormRadio is a templated form radio input.

func (*FormRadio) GetFormInputs

func (f *FormRadio) GetFormInputs() *[]FormInput

type FormSelect

type FormSelect struct {
	ID           string
	Name         string
	Label        *FormLabel
	Help         LocalizedString
	Options      []Value
	Disabled     bool
	Required     bool
	ExtraClasses []string
	Validation   *FormValidation
}

FormSelect is a templated form select.

type FormTextarea

type FormTextarea struct {
	ID         string
	Name       string
	Rows       int
	Label      *FormLabel
	Value      string
	Disabled   bool
	Required   bool
	Validation *FormValidation
}

FormTextarea is a templated form textarea.

type FormValidation

type FormValidation struct {
	Valid    bool
	Response string
}

FormValidation is a validation response to a form input.

type HeadLink struct {
	HRef        string
	Rel         string
	Integrity   string
	CrossOrigin string
	Sizes       string
	Type        string
}

HeadLink is the data for a header link.

type LocalizedString

type LocalizedString interface {
	Language() language.Tag
	String() string
}

type Login

type Login struct {
	FooterScripts     []Script
	FooterExtraScript []string
	HeadLinks         []HeadLink
	Language          string
	TextLogin         LocalizedString

	FormError     *Alert
	FormInstance  FormInput
	LogoDarkHRef  string
	LogoLightHRef string
}

Login contains the variables for the "login" template.

type Navbar []NavbarNode

Navbar is a navbar that can be added to a page.

func (n *Navbar) ActivateFromPath(path string)

ActivateFromPath sets the active bool based on the match regex.

func (n *Navbar) GetChildren(i int) ActivableSlice

GetChildren returns the children of the node or nil if no children.

func (n *Navbar) GetMatcher(i int) *regexp.Regexp

GetMatcher returns the matcher of the node or nil if no matcher.

func (n *Navbar) Len() int

Len returns the matcher of the node or nil if no matcher.

func (n *Navbar) SetActive(i int, a bool)

SetActive sets the active bool based on the match regex.

type NavbarNode struct {
	Text     string
	URL      string
	MatchStr *regexp.Regexp
	Icon     string

	Active   bool
	Disabled bool
	Divider  bool

	Children Navbar
}

NavbarNode is an entry on a navbar, can be nested one level.

type Pagination

type Pagination struct {
	Align string
	Nodes []PaginationNode
}

Pagination is a pagination element that can be added to a webpage.

func MakePagination

func MakePagination(c *PaginationConfig) Pagination

MakePagination creates a pagination element from the provided parameters.

type PaginationConfig

type PaginationConfig struct {
	Align         string // pagination alignment
	Count         int    // item count
	DisplayCount  int    // how many items to display per page
	HRef          string // href to add query to
	HRefCount     int    // count to include in the href, if 0 no count is added
	MaxPagination int    // the max number of pages to show
	Page          int    // current page
}

PaginationConfig contains the config to construct pagination.

type PaginationNode

type PaginationNode struct {
	Text string
	Icon string
	HRef string

	Active   bool
	Disabled bool
}

PaginationNode is an element in a pagination element.

type Script

type Script struct {
	Src         string
	Integrity   string
	CrossOrigin string
}

Script is a javascript script.

type Value

type Value struct {
	Value    string
	Text     LocalizedString
	Disabled bool
	Selected bool
}

Jump to

Keyboard shortcuts

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