common

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 16 Imported by: 9

Documentation

Overview

Package common This package provides basic constants used by forms packages.

Index

Constants

View Source
const (
	BASE      = "base"
	BOOTSTRAP = "bootstrap3"
)

Available form themes

View Source
const (
	BUTTON         = "button"
	CHECKBOX       = "checkbox"
	COLOR          = "color"
	DATE           = "date"
	DATETIME       = "datetime"
	DATETIME_LOCAL = "datetime-local"
	EMAIL          = "email"
	FILE           = "file"
	HIDDEN         = "hidden"
	IMAGE          = "image"
	MONTH          = "month"
	NUMBER         = "number"
	PASSWORD       = "password"
	RADIO          = "radio"
	RANGE          = "range"
	RESET          = "reset"
	SEARCH         = "search"
	SUBMIT         = "submit"
	TEL            = "tel"
	TEXT           = "text"
	TIME           = "time"
	URL            = "url"
	WEEK           = "week"
	TEXTAREA       = "textarea"
	SELECT         = "select"
	STATIC         = "static"
)

Input field types

View Source
const (
	PACKAGE_NAME = "github.com/coscms/forms"
)

Variables

View Source
var (
	LabelFn = func(s string) string {
		return s
	}
)
View Source
var TplFuncs = func() template.FuncMap {
	return template.FuncMap{
		`RandomString`:    RandomString,
		`Slugify`:         Slugify,
		`SlugifyMaxWidth`: SlugifyMaxWidth,
	}
}

Functions

func ClearCachedConfig added in v1.4.0

func ClearCachedConfig()

func ClearCachedTemplate

func ClearCachedTemplate()

func DelCachedConfig added in v1.4.0

func DelCachedConfig(key string) bool

func DelCachedTemplate added in v1.4.0

func DelCachedTemplate(key string) bool

func GetOrSetCachedConfig added in v1.8.5

func GetOrSetCachedConfig(cachedKey string, generator func() (*config.Config, error)) (c *config.Config, err error)

func GetOrSetCachedTemplate added in v1.8.5

func GetOrSetCachedTemplate(cachedKey string, generator func() (*template.Template, error)) (c *template.Template, err error)

func LookupPath added in v1.7.2

func LookupPath(widget string) string

LookupPath creates the complete path of the desired widget template

func ParseFS added in v1.4.0

func ParseFS(fs fs.FS, files ...string) (*template.Template, error)

ParseFS 从给定的文件系统(fs)中解析指定的模板文件,并返回一个模板对象。 第一个文件将作为主模板,后续文件将作为子模板解析。 参数:

fs: 文件系统接口
files: 要解析的模板文件路径列表

返回值:

*template.Template: 解析后的模板对象
error: 解析过程中遇到的错误

func ParseFiles added in v1.4.0

func ParseFiles(files ...string) (*template.Template, error)

ParseFiles 从给定的文件路径中解析模板文件并返回一个模板对象。 如果配置了文件系统(FileSystem),则使用ParseFS进行解析,否则从本地文件系统读取。 第一个文件将作为主模板,其余文件将作为附加模板进行解析。 返回解析后的模板对象和可能发生的错误。

func ParseTmpl added in v1.2.1

func ParseTmpl(data interface{},
	fn_tpl template.FuncMap,
	fn_fixTpl func(tpls ...string) ([]string, error),
	tpls ...string) string

func RandomString added in v1.13.18

func RandomString(length ...uint) string

RandomString 生成一个指定长度的随机字母数字字符串 如果未指定长度,则默认生成8位长度的字符串

func SetTmplDir added in v1.4.0

func SetTmplDir(theme, tmplDir string)

func Slugify added in v1.16.2

func Slugify(v string) string

Slugify 将字符串转换为URL友好的slug格式

func SlugifyMaxWidth added in v1.16.2

func SlugifyMaxWidth(v string, maxWidth int) string

SlugifyMaxWidth 将字符串转换为slug格式并限制最大长度 v: 需要转换的原始字符串 maxWidth: 返回字符串的最大长度限制 返回: 转换后的slug字符串,长度不超过maxWidth

func Tag

func Tag(t reflect.Type, f reflect.StructField, tagName string) (value string, tf tagfast.Faster)

func TagVal added in v1.4.0

func TagVal(t reflect.Type, fieldNo int, tagName string) string

func TmplDir

func TmplDir(theme string) (tmplDir string)

func TmplExists added in v1.4.0

func TmplExists(tmpl string) bool

Types

type FileSystems added in v1.4.4

type FileSystems []fs.FS
var FileSystem FileSystems

func (FileSystems) IsEmpty added in v1.4.4

func (f FileSystems) IsEmpty() bool

func (FileSystems) Open added in v1.4.4

func (f FileSystems) Open(name string) (file fs.File, err error)

func (*FileSystems) Register added in v1.4.4

func (f *FileSystems) Register(fileSystem fs.FS)

func (FileSystems) Size added in v1.4.4

func (f FileSystems) Size() int

type HTMLAttrValues added in v1.6.0

type HTMLAttrValues []string

func (*HTMLAttrValues) Add added in v1.6.0

func (s *HTMLAttrValues) Add(value string)

func (HTMLAttrValues) Clone added in v1.13.20

func (s HTMLAttrValues) Clone() HTMLAttrValues

func (HTMLAttrValues) Exists added in v1.8.3

func (s HTMLAttrValues) Exists(attr string) bool

func (HTMLAttrValues) IsEmpty added in v1.6.0

func (s HTMLAttrValues) IsEmpty() bool

func (*HTMLAttrValues) Remove added in v1.6.0

func (s *HTMLAttrValues) Remove(value string)

func (HTMLAttrValues) Size added in v1.6.0

func (s HTMLAttrValues) Size() int

func (HTMLAttrValues) String added in v1.6.0

func (s HTMLAttrValues) String() string

type HTMLAttributes added in v1.8.3

type HTMLAttributes map[template.HTMLAttr]interface{}

func (HTMLAttributes) Clone added in v1.13.20

func (s HTMLAttributes) Clone() HTMLAttributes

func (HTMLAttributes) Exists added in v1.8.3

func (s HTMLAttributes) Exists(attr string) bool

func (HTMLAttributes) FillFrom added in v1.8.3

func (s HTMLAttributes) FillFrom(data map[string]interface{})

func (HTMLAttributes) FillFromStringMap added in v1.8.3

func (s HTMLAttributes) FillFromStringMap(data map[string]string)

func (HTMLAttributes) Get added in v1.15.3

func (s HTMLAttributes) Get(attr string) interface{}

type HTMLData added in v1.8.3

type HTMLData map[string]interface{}

func (HTMLData) Clone added in v1.13.20

func (s HTMLData) Clone() HTMLData

func (HTMLData) Exists added in v1.8.3

func (s HTMLData) Exists(key string) bool

Jump to

Keyboard shortcuts

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