github.com/rpdict/ponzu@v0.10.1-0.20190226054626-477f29d6bf5e/docs/src/Interfaces/Editor.md (about)

     1  title: Editor Package Interfaces
     2  
     3  Ponzu provides a set of interfaces from the `management/editor` package which 
     4  extend the system's functionality and determine how content editors are rendered 
     5  within the CMS.
     6  
     7  ---
     8  
     9  ## Interfaces
    10  
    11  ### [editor.Editable](https://godoc.org/github.com/rpdict/ponzu/management/editor#Editable)
    12  
    13  Editable determines what `[]bytes` are rendered inside the editor page. Use 
    14  Edtiable on anything inside your CMS that you want to provide configuration, editable 
    15  fields, or any HTML/markup to display to an end-user.
    16  
    17  !!! note "Implementing `editor.Editable`"
    18      Most of the time, Ponzu developers generate the majority of this code using 
    19      the Ponzu CLI [`generate` command](/CLI/Usage).
    20  
    21  ##### Method Set
    22  
    23  ```go
    24  type Editable interface {
    25      MarshalEditor() ([]byte, error)
    26  }
    27  ```
    28  
    29  ##### Implementation
    30  
    31  ```go
    32  func (p *Post) MarshalEditor() ([]byte, error) {
    33      // The editor.Form func sets up a structured UI with default styles and form
    34      // elements based on the fields provided. Most often, Ponzu developers will
    35      // have the `$ ponzu generate` command generate the MarshalEditor func and 
    36      // its internal form fields
    37      view, err := editor.Form(p,
    38  		editor.Field{
    39  			View: editor.Input("Name", p, map[string]string{
    40  				"label":       "Name",
    41  				"type":        "text",
    42  				"placeholder": "Enter the Name here",
    43  			}),
    44  		},
    45      )
    46  }
    47  ```
    48  
    49  !!! note "MarshalEditor() & View Rendering"
    50      Although it is common to use the `editor.Form` and `editor.Fields` to structure your content editor inside `MarshalEditor()`, the method signature defines that its return value needs only to be `[]byte, error`. Keep in mind that you can return a `[]byte` of any raw HTML or other markup to be rendered in the editor view.
    51  
    52  ---
    53  
    54  ### [editor.Mergeable](https://godoc.org/github.com/rpdict/ponzu/management/editor#Mergeable)
    55  
    56  Mergable enables a CMS end-user to merge the "Pending" content from an outside source into the "Public" section, and thus making it visible via the public content API. It also allows the end-user to reject content. "Approve" and "Reject" buttons will be visible on the edit page for content submitted.
    57  
    58  ##### Method Set
    59  ```go
    60  type Mergeable interface {
    61      Approve(http.ResponseWriter, *http.Request) error
    62  }
    63  ```
    64  
    65  ##### Example
    66  ```go
    67  func (p *Post) Approve(res http.ResponseWriter, req *http.Request) error {
    68      return nil
    69  }
    70  ```