editor

package
v0.0.0-...-b27b957 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package editor enables users to create edit templates from their entities structs so that admins can manage entities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildContentListEntryTemplate

func BuildContentListEntryTemplate(e Editable, typeName string) string

func Checkbox

func Checkbox(fieldName string, p interface{}, attrs, options map[string]string) []byte

Checkbox returns the []byte of a set of <input type="checkbox"> HTML elements wrapped in a <div> with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func DOMElement

func DOMElement(e *Element) []byte

DOMElement creates a DOM element

func DOMElementCheckbox

func DOMElementCheckbox(e *Element) []byte

DOMElementCheckbox is a special DOM element which is parsed as a checkbox input tag and thus needs to be created differently

func DOMElementSelfClose

func DOMElementSelfClose(e *Element) []byte

DOMElementSelfClose is a special DOM element which is parsed as a self-closing tag and thus needs to be created differently

func DOMElementWithChildrenCheckbox

func DOMElementWithChildrenCheckbox(e *Element, children []*Element) []byte

func DOMElementWithChildrenSelect

func DOMElementWithChildrenSelect(e *Element, children []*Element) []byte

func FieldCollection

func FieldCollection(fieldName, label string, p interface{}, types map[string]func(interface{}, *FieldArgs, ...Field) []byte) []byte

func File

func File(fieldName string, p interface{}, attrs map[string]string) []byte

File returns the []byte of a <input type="file"> HTML element with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func FileRepeater

func FileRepeater(fieldName string, p interface{}, attrs map[string]string) []byte

FileRepeater returns the []byte of a <input type="file"> HTML element with a label. It also includes repeat controllers (+ / -) so the element can be dynamically multiplied or reduced. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func Form

func Form(post Editable, paths config.Paths, fields ...Field) ([]byte, error)

Form takes editable entities and any number of Field funcs to describe the edit page for any entities struct added by a user

func Input

func Input(fieldName string, p interface{}, attrs map[string]string, args *FieldArgs) []byte

Input returns the []byte of an <input> HTML element with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

type Person struct {
	item.Item
	editor editor.Editor

	Name string `json:"name"`
	//...
}

func (p *Person) MarshalEditor() ([]byte, error) {
	view, err := editor.Form(p,
		editor.Field{
			Template: editor.Input("Name", p, map[string]string{
				"label":       "Name",
				"type":        "text",
				"placeholder": "Enter the Name here",
			}),
		}
	)
}

func InputRepeater

func InputRepeater(fieldName string, p interface{}, attrs map[string]string) []byte

func Nested

func Nested(fieldName string, p interface{}, args *FieldArgs, fields ...Field) []byte

func NestedRepeater

func NestedRepeater(fieldName string, p interface{}, m func(v interface{}, f *FieldArgs) (string, []Field)) []byte

func RepeatController

func RepeatController(fieldName string, p interface{}, inputSelector, cloneSelector string) []byte

RepeatController generates the javascript to control any repeatable form element in an editor based on its type, field name and HTML tag name

func Richtext

func Richtext(fieldName string, p interface{}, attrs map[string]string, args *FieldArgs) []byte

Richtext returns the []byte of a rich text editor (provided by http://summernote.org/) with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func Select

func Select(fieldName string, p interface{}, attrs, options map[string]string) []byte

Select returns the []byte of a <select> HTML element plus internal <options> with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func SelectRepeater

func SelectRepeater(fieldName string, p interface{}, attrs, options map[string]string) []byte

SelectRepeater returns the []byte of a <select> HTML element plus internal <options> with a label. It also includes repeat controllers (+ / -) so the element can be dynamically multiplied or reduced. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func TagNameFromStructField

func TagNameFromStructField(name string, post interface{}, args *FieldArgs) string

func TagNameFromStructFieldMulti

func TagNameFromStructFieldMulti(name string, i int, post interface{}) string

TagNameFromStructFieldMulti calls TagNameFromStructField and formats is for use with gorilla/schema due to the format in which gorilla/schema expects form names to be when one is associated with multiple values, we need to output the name as such. Ex. 'category.0', 'category.1', 'category.2' and so on.

func Tags

func Tags(fieldName string, p interface{}, attrs map[string]string) []byte

Tags returns the []byte of a tag input (in the style of Materialze 'Chips') with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func Textarea

func Textarea(fieldName string, p interface{}, attrs map[string]string) []byte

Textarea returns the []byte of a <textarea> HTML element with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func Timestamp

func Timestamp(fieldName string, p interface{}, attrs map[string]string) []byte

Timestamp returns the []byte of an <input> HTML element with a label. IMPORTANT: The `fieldName` argument will cause a panic if it is not exactly the string form of the struct field that this editor input is representing

func ValueByName

func ValueByName(name string, post interface{}, args *FieldArgs) reflect.Value

func ValueFromStructField

func ValueFromStructField(name string, post interface{}, args *FieldArgs) interface{}

ValueFromStructField returns the string value of a field in a struct

Types

type ContentMetadata

type ContentMetadata struct {
	TypeName string
}

type Editable

type Editable interface {
	MarshalEditor(paths config.Paths) ([]byte, error)
}

Editable ensures data is editable

type Editor

type Editor struct {
	ViewBuf *bytes.Buffer
}

Editor is a view containing fields to manage entities

type Element

type Element struct {
	TagName string
	Attrs   map[string]string
	Name    string
	Label   string
	Data    string
	ViewBuf *bytes.Buffer
}

Element is a basic struct for representing DOM elements

func NewElement

func NewElement(tagName, label, fieldName string, p interface{}, attrs map[string]string, args *FieldArgs) *Element

NewElement returns an Element with Name and Data already processed from the fieldName and entities interface provided

type Field

type Field struct {
	View []byte
}

Field is used to create the editable view for a field within a particular entities struct

type FieldArgs

type FieldArgs struct {
	Parent   string
	TypeName string
}

type Tab

type Tab struct {
	Name       string
	Icon       string
	ClassNames []string
	Content    []byte
}

Jump to

Keyboard shortcuts

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