Documentation
¶
Overview ¶
Package reformism provides several utility functions for native text/template
Index ¶
- Variables
- func Flash(r *http.Request, data any, category ...string)
- func FlashedFrom(r *http.Request) *_Flashed
- func PatchFlashed(r *http.Request) *http.Request
- func ReplyJson(w http.ResponseWriter, status int, obj any)
- type Admin
- type BaseView
- func (V *BaseView) Expose(path string, h http.HandlerFunc)
- func (V *BaseView) GetBlueprint() *Blueprint
- func (V *BaseView) GetMenu() *MenuItem
- func (V *BaseView) GetUrl(ep string, q *Query, args ...any) string
- func (V *BaseView) IsAccessible() bool
- func (V *BaseView) IsVisible() bool
- func (V *BaseView) Render(w http.ResponseWriter, r *http.Request, name string, funcs template.FuncMap, ...)
- type Blueprint
- type Menu
- type MenuItem
- type ModelView
- func (mv *ModelView) Render(w http.ResponseWriter, r *http.Request, name string, funcs template.FuncMap, ...)
- func (mv *ModelView) SetCanCreate(v bool) *ModelView
- func (mv *ModelView) SetCanEdit(v bool) *ModelView
- func (mv *ModelView) SetCanExport(v bool) *ModelView
- func (mv *ModelView) SetCanSetPageSize(v bool) *ModelView
- func (mv *ModelView) SetColumnDescriptions(m map[string]string) *ModelView
- func (mv *ModelView) SetColumnEditableList(vs ...string) *ModelView
- func (mv *ModelView) SetColumnList(vs ...string) *ModelView
- func (mv *ModelView) SetPageSize(v int) *ModelView
- func (mv *ModelView) SetTablePrefixHtml(v string) *ModelView
- type Pack
- type Query
- type RegisterFunc
- type View
- type XEditableWidget
Constants ¶
This section is empty.
Variables ¶
var ( ContentTypeJson = "application/json; charset=utf-8" ContentTypeUtf8Html = "text/html; charset=utf-8" )
var Funcs = template.FuncMap{ "arg": witharg, "require": requireArg, "done": done, "args": args, "slice": makeSlice, "map": makeMap, "seq": makeSequence, "append": appendSlice, "split": splitStr, "join": joinStr, "only": only, "delete": deleteItem, "set": mapSet, "default": defaultOf, "log": logto, "add": func(is ...int) int { var a int = 0 for _, b := range is { a += b } return a }, "sub": func(a, b int) int { return a - b }, }
Funcs is a FuncMap which can be passed as argument of .Func of text/template
Functions ¶
func FlashedFrom ¶
func PatchFlashed ¶
Inject Flashed into cloned Request
Types ¶
type BaseView ¶
type BaseView struct { *Blueprint // contains filtered or unexported fields }
func (*BaseView) Expose ¶
func (V *BaseView) Expose(path string, h http.HandlerFunc)
Expose "/test" create Blueprint{Endpoint: "test", Path: "/test"}
func (*BaseView) GetBlueprint ¶
func (*BaseView) IsAccessible ¶
type Blueprint ¶
type Blueprint struct { Endpoint string // {foo}.index Path string // /foo Children map[string]*Blueprint // endpoint => *Blueprint Name string // Foo Handler http.HandlerFunc Register RegisterFunc // Custom register to mux, serve static file }
like flask.Blueprint
| Name | Endpoint | Path | |-------|----------------|------------| | Foo | foo | foo | | | .index | / | | | .action_view | /action | | | foo.index | foo/ | | Admin | admin | /admin | | | .index | / |
A blueprint is A model and dependent pages
type MenuItem ¶
type MenuItem struct { Category string // parent item Name Name string Path string Icon string Class string IsActive bool IsVisible bool IsAccessible bool Children []*MenuItem }
Tree liked structure
type ModelView ¶
type ModelView struct { *BaseView // contains filtered or unexported fields }
func (*ModelView) SetCanCreate ¶
Permissions Is model creation allowed
func (*ModelView) SetCanEdit ¶
Is model editing allowed
func (*ModelView) SetCanExport ¶
func (*ModelView) SetCanSetPageSize ¶
func (*ModelView) SetColumnDescriptions ¶
func (*ModelView) SetColumnEditableList ¶
func (*ModelView) SetColumnList ¶
Collection of the model field names for the list view. If not set, will get them from the model.
func (*ModelView) SetPageSize ¶
func (*ModelView) SetTablePrefixHtml ¶
type Query ¶
type Query struct { // 0 based with omit Page int `form:"page,omitempty"` PageSize int `form:"page_size,omitempty"` // column index: 0,1,... maybe `null.String` is better Sort string `form:"sort,omitempty"` // desc or asc, default is asc Desc bool `form:"desc,omitempty"` Search string `form:"search,omitempty"` // contains filtered or unexported fields }
type View ¶
type View interface { // Add custom handler, eg: /admin/{model}/path Expose(path string, h http.HandlerFunc) // Generate URL for the endpoint. // In model view, return {model}/{action} GetUrl(ep string, q *Query, args ...any) string GetBlueprint() *Blueprint GetMenu() *MenuItem // Override this method if you want dynamically hide or show // administrative views from Flask-Admin menu structure IsVisible() bool // Override this method to add permission checks. IsAccessible() bool Render(http.ResponseWriter, *http.Request, string, template.FuncMap, map[string]any) }
type XEditableWidget ¶
type XEditableWidget struct {
// contains filtered or unexported fields
}