template

package
v1.2.24 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: Apache-2.0 Imports: 18 Imported by: 805

Documentation

Index

Constants

View Source
const (
	CompCol       = "col"
	CompRow       = "row"
	CompForm      = "form"
	CompTable     = "table"
	CompDataTable = "datatable"
	CompTree      = "tree"
	CompTreeView  = "treeview"
	CompTabs      = "tabs"
	CompAlert     = "alert"
	CompLink      = "link"
	CompPaginator = "paginator"
	CompPopup     = "popup"
	CompBox       = "box"
	CompLabel     = "label"
	CompImage     = "image"
	CompButton    = "button"
)

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.ReplaceAll(string(s), string(old), string(repl)))
	},
	"renderJS": func(s template.JS, old, repl template.HTML) template.JS {
		return template.JS(strings.ReplaceAll(string(s), string(old), string(repl)))
	},
	"divide": func(a, b int) int {
		return a / b
	},
	"renderRowDataHTML": func(id, content template.HTML, value ...map[string]types.InfoItem) template.HTML {
		return template.HTML(types.ParseTableDataTmplWithID(id, string(content), value...))
	},
	"renderRowDataJS": func(id template.HTML, content template.JS, value ...map[string]types.InfoItem) template.JS {
		return template.JS(types.ParseTableDataTmplWithID(id, string(content), value...))
	},
	"attr": func(s template.HTML) template.HTMLAttr {
		return template.HTMLAttr(s)
	},
	"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 ""
	},
	"changeValue": func(f types.FormField, index int) types.FormField {
		if len(f.ValueArr) > 0 {
			f.Value = template.HTML(f.ValueArr[index])
		}
		if len(f.OptionsArr) > 0 {
			f.Options = f.OptionsArr[index]
		}
		if f.FormType.IsSelect() {
			f.FieldClass += "_" + strconv.Itoa(index)
		}
		return f
	},
}
View Source
var DefaultThemeNames = []string{"sword", "adminlte"}

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.0.3

func AddFromPlugin(name string, mod string)

func AddLoginComp added in v1.0.0

func AddLoginComp(comp Component)

AddLoginComp add the specified login component.

func CSS added in v1.0.9

func CSS(s string) template.CSS

func CheckRequirements added in v1.2.8

func CheckRequirements() (bool, bool)

CheckRequirements check the theme and GoAdmin interdependence limit. The first return parameter means that whether GoAdmin version meets the requirement of the theme used or not. The second return parameter means that whether the version of theme used meets the requirement of GoAdmin or not.

func CheckThemeRequirements added in v1.2.9

func CheckThemeRequirements() bool

func Execute added in v1.0.0

func Execute(param *ExecuteParam) *bytes.Buffer

func GetAsset added in v1.0.6

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

func GetComponentAsset added in v1.2.10

func GetComponentAsset() []string

func GetComponentAssetImportHTML added in v1.2.10

func GetComponentAssetImportHTML() (res template.HTML)

func GetComponentAssetWithinPage added in v1.2.10

func GetComponentAssetWithinPage() []string

func GetPageContentFromPageType added in v1.2.12

func GetPageContentFromPageType(title, desc, msg string, pt PageType) (template.HTML, template.HTML, template.HTML)

func HTML added in v1.0.9

func HTML(s string) template.HTML

func JS added in v1.0.9

func JS(s string) template.JS

func SetComp added in v1.0.0

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.

func Themes added in v1.2.8

func Themes() []string

func VersionCompare added in v1.2.9

func VersionCompare(toCompare string, versions []string) bool

func WarningPanel added in v1.2.7

func WarningPanel(msg string, pts ...PageType) types.Panel

func WarningPanelWithDescAndTitle added in v1.2.15

func WarningPanelWithDescAndTitle(msg, desc, title string, pts ...PageType) types.Panel

Types

type BaseComponent added in v1.0.3

type BaseComponent struct {
	Name      string
	HTMLData  string
	CSS       template.CSS
	JS        template.JS
	Callbacks types.Callbacks
}

func (*BaseComponent) BindActionTo added in v1.2.16

func (b *BaseComponent) BindActionTo(action types.Action, id string)

func (*BaseComponent) GetAsset added in v1.0.3

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

func (*BaseComponent) GetAssetList added in v1.0.3

func (b *BaseComponent) GetAssetList() []string

func (*BaseComponent) GetCSS added in v1.2.16

func (b *BaseComponent) GetCSS() template.CSS

func (*BaseComponent) GetCallbacks added in v1.2.16

func (b *BaseComponent) GetCallbacks() types.Callbacks

func (*BaseComponent) GetContentWithData added in v1.2.16

func (b *BaseComponent) GetContentWithData(obj interface{}) template.HTML

func (*BaseComponent) GetJS added in v1.2.16

func (b *BaseComponent) GetJS() template.JS

func (*BaseComponent) GetName added in v1.2.16

func (b *BaseComponent) GetName() string

func (*BaseComponent) GetTemplate added in v1.2.16

func (b *BaseComponent) GetTemplate() (*template.Template, string)

func (*BaseComponent) IsAPage added in v1.2.16

func (b *BaseComponent) IsAPage() bool

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/GoAdminGroup/go-admin/blob/master/template/login/theme1.tmpl#L32
	// https://github.com/GoAdminGroup/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

	GetJS() template.JS
	GetCSS() template.CSS
	GetCallbacks() types.Callbacks
}

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 ExecuteOptions added in v1.2.15

type ExecuteOptions struct {
	Animation         bool
	NoCompress        bool
	HideSideBar       bool
	HideHeader        bool
	UpdateMenu        bool
	NavDropDownButton []*types.NavDropDownItemButton
}

func GetExecuteOptions added in v1.2.15

func GetExecuteOptions(options []ExecuteOptions) ExecuteOptions

type ExecuteParam added in v1.2.7

type ExecuteParam struct {
	User       models.UserModel
	Tmpl       *template.Template
	TmplName   string
	IsPjax     bool
	Panel      types.Panel
	Config     *c.Config
	Menu       *menu.Menu
	Animation  bool
	Buttons    types.Buttons
	NoCompress bool
	Iframe     bool
}

type PageType added in v1.2.12

type PageType uint8
const (
	NormalPage PageType = iota
	Missing404Page
	Error500Page
	NoPermission403Page
)

func GetPageTypeFromPageError added in v1.2.15

func GetPageTypeFromPageError(err errors2.PageError) PageType

type Template added in v0.0.2

type Template interface {
	Name() string

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

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

	TreeView() types.TreeViewAttribute
	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
	GetAssetImportHTML(exceptComponents ...string) template.HTML
	GetAsset(string) ([]byte, error)
	GetTemplate(bool) (*template.Template, string)
	GetVersion() string
	GetRequirements() []string
	GetHeadHTML() template.HTML
	GetFootJS() template.HTML
	Get404HTML() template.HTML
	Get500HTML() template.HTML
	Get403HTML() template.HTML
}

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.0.3

func Default() Template

Default 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.
Code generated by go-bindata.
Code generated by go-bindata.
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