template

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFuncMap = template.FuncMap{
	"lang":     language.Get,
	"langHtml": language.GetFromHtml,
	"link": func(cdnUrl, prefixUrl, assetsUrl string) string {
		if cdnUrl == "" {
			return prefixUrl + assetsUrl
		}
		return cdnUrl + assetsUrl
	},
	"isLinkUrl": func(s string) bool {
		return (len(s) > 7 && s[:7] == "http://") || (len(s) > 8 && s[:8] == "https://")
	},
	"render": func(s, old, repl template.HTML) template.HTML {
		return template.HTML(strings.Replace(string(s), string(old), string(repl), -1))
	},
	"renderJS": func(s template.JS, old, repl template.HTML) template.JS {
		return template.JS(strings.Replace(string(s), string(old), string(repl), -1))
	},
	"divide": func(a, b int) int {
		return a / b
	},
	"js": func(s interface{}) template.JS {
		if ss, ok := s.(string); ok {
			return template.JS(ss)
		}
		if ss, ok := s.(template.HTML); ok {
			return template.JS(ss)
		}
		return ""
	},
}

Functions

func Add added in v0.0.2

func Add(name string, temp Template)

Add makes a template available by the provided theme name. If Add is called twice with the same name or if template is nil, it panics.

func AddComp added in v0.0.2

func AddComp(comp Component)

AddComp makes a component available by the provided name. If Add is called twice with the same name or if component is nil, it panics.

func AddFromPlugin added in v1.2.12

func AddFromPlugin(name string, mod string)

func AddLoginComp added in v1.2.12

func AddLoginComp(comp Component)

AddLoginComp add the specified login component.

func CSS added in v1.2.12

func CSS(s string) template.CSS

func Execute added in v1.2.12

func Execute(tmpl *template.Template,
	tmplName string,
	user models.UserModel,
	panel types.Panel,
	config c.Config,
	globalMenu *menu.Menu, animation ...bool) *bytes.Buffer

func GetAsset added in v1.2.12

func GetAsset(path string) ([]byte, error)

func GetComponentAssetLists added in v1.2.12

func GetComponentAssetLists() []string

func GetComponentAssetListsHTML added in v1.2.12

func GetComponentAssetListsHTML() (res template.HTML)

func GetComponentAssetListsWithinPage added in v1.2.12

func GetComponentAssetListsWithinPage() []string

func HTML added in v1.2.12

func HTML(s string) template.HTML

func JS added in v1.2.12

func JS(s string) template.JS

func SetComp added in v1.2.12

func SetComp(name string, comp Component)

SetComp makes a component available by the provided name. If the value corresponding to the key is empty or if component is nil, it panics.

Types

type BaseComponent added in v1.2.12

type BaseComponent struct{}

func (BaseComponent) GetAsset added in v1.2.12

func (b BaseComponent) GetAsset(name string) ([]byte, error)

func (BaseComponent) GetAssetList added in v1.2.12

func (b BaseComponent) GetAssetList() []string

type Component added in v0.0.2

type Component interface {
	// GetTemplate return a *template.Template and a given key.
	GetTemplate() (*template.Template, string)

	// GetAssetList return the assets url suffix used in the component.
	// example:
	//
	// {{.UrlPrefix}}/assets/login/css/bootstrap.min.css => login/css/bootstrap.min.css
	//
	// See:
	// https://github.com/davidlcarrascal/go-admin/blob/master/template/login/theme1.tmpl#L32
	// https://github.com/davidlcarrascal/go-admin/blob/master/template/login/list.go
	GetAssetList() []string

	// GetAsset return the asset content according to the corresponding url suffix.
	// Asset content is recommended to use the tool go-bindata to generate.
	//
	// See: http://github.com/jteeuwen/go-bindata
	GetAsset(string) ([]byte, error)

	GetContent() template.HTML

	IsAPage() bool

	GetName() string
}

Component is the interface which stand for a ui component.

func GetComp added in v0.0.2

func GetComp(name string) Component

GetComp gets the component by registered name. If the name is not found, it panics.

type Template added in v0.0.2

type Template interface {

	// layout
	Col() types.ColAttribute
	Row() types.RowAttribute

	// form and table
	Form() types.FormAttribute
	Table() types.TableAttribute
	DataTable() types.DataTableAttribute

	Tree() types.TreeAttribute
	Tabs() types.TabsAttribute
	Alert() types.AlertAttribute
	Link() types.LinkAttribute

	Paginator() types.PaginatorAttribute
	Popup() types.PopupAttribute
	Box() types.BoxAttribute

	Label() types.LabelAttribute
	Image() types.ImgAttribute

	Button() types.ButtonAttribute

	// Builder methods
	GetTmplList() map[string]string
	GetAssetList() []string
	GetAsset(string) ([]byte, error)
	GetTemplate(bool) (*template.Template, string)
}

Template is the interface which contains methods of ui components. It will be used in the plugins for custom the ui.

func Default added in v1.2.12

func Default() Template

Get the default template with the theme name set with the global config. If the name is not found, it panics.

func Get added in v0.0.2

func Get(theme string) Template

Get the template interface by theme name. If the name is not found, it panics.

Directories

Path Synopsis
Code generated by go-bindata.
Code generated by go-bindata.

Jump to

Keyboard shortcuts

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