Documentation ¶
Overview ¶
Package editor enables users to create edit views from their content structs so that admins can manage content
Index ¶
- func Checkbox(fieldName string, p interface{}, attrs, options map[string]string) []byte
- func DOMElement(e *Element) []byte
- func DOMElementCheckbox(e *Element) []byte
- func DOMElementSelfClose(e *Element) []byte
- func DOMElementWithChildrenCheckbox(e *Element, children []*Element) []byte
- func DOMElementWithChildrenSelect(e *Element, children []*Element) []byte
- func File(fieldName string, p interface{}, attrs map[string]string) []byte
- func FileRepeater(fieldName string, p interface{}, attrs map[string]string) []byte
- func Form(post Editable, fields ...Field) ([]byte, error)
- func Input(fieldName string, p interface{}, attrs map[string]string) []byte
- func InputRepeater(fieldName string, p interface{}, attrs map[string]string) []byte
- func RepeatController(fieldName string, p interface{}, inputSelector, cloneSelector string) []byte
- func Richtext(fieldName string, p interface{}, attrs map[string]string) []byte
- func Select(fieldName string, p interface{}, attrs, options map[string]string) []byte
- func SelectRepeater(fieldName string, p interface{}, attrs, options map[string]string) []byte
- func TagNameFromStructField(name string, post interface{}) string
- func TagNameFromStructFieldMulti(name string, i int, post interface{}) string
- func Tags(fieldName string, p interface{}, attrs map[string]string) []byte
- func Textarea(fieldName string, p interface{}, attrs map[string]string) []byte
- func Timestamp(fieldName string, p interface{}, attrs map[string]string) []byte
- func ValueFromStructField(name string, post interface{}) string
- type Editable
- type Editor
- type Element
- type Field
- type Mergeable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Checkbox ¶
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 DOMElementCheckbox ¶
DOMElementCheckbox is a special DOM element which is parsed as a checkbox input tag and thus needs to be created differently
func DOMElementSelfClose ¶
DOMElementSelfClose is a special DOM element which is parsed as a self-closing tag and thus needs to be created differently
func File ¶
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 ¶
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 ¶
Form takes editable content and any number of Field funcs to describe the edit page for any content struct added by a user
func Input ¶
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{ View: editor.Input("Name", p, map[string]string{ "label": "Name", "type": "text", "placeholder": "Enter the Name here", }), } ) }
func InputRepeater ¶
InputRepeater returns the []byte of an <input> 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
type Person struct { item.Item editor editor.Editor Names []string `json:"names"` //... } func (p *Person) MarshalEditor() ([]byte, error) { view, err := editor.Form(p, editor.Field{ View: editor.InputRepeater("Names", p, map[string]string{ "label": "Names", "type": "text", "placeholder": "Enter a Name here", }), } ) }
func RepeatController ¶
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 ¶
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 ¶
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 ¶
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 ¶
TagNameFromStructField does a lookup on the `json` struct tag for a given field of a struct
func TagNameFromStructFieldMulti ¶
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 ¶
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 ¶
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 ¶
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 ValueFromStructField ¶
ValueFromStructField returns the string value of a field in a struct
Types ¶
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
type Field ¶
type Field struct {
View []byte
}
Field is used to create the editable view for a field within a particular content struct
type Mergeable ¶
type Mergeable interface { // Approve copies an external post to the internal collection and triggers // a re-sort of its content type posts Approve(http.ResponseWriter, *http.Request) error }
Mergeable allows external post content to be approved and published through the public-facing API