ponzu: github.com/ponzu-cms/ponzu/system/item Index | Files

package item

import "github.com/ponzu-cms/ponzu/system/item"

Package item provides the default functionality to Ponzu's content/data types, how they interact with the API, and how to override or enhance their abilities using various interfaces.

Index

Package Files

item.go types.go upload.go

Variables

var (
    // ErrTypeNotRegistered means content type isn't registered (not found in Types map)
    ErrTypeNotRegistered = errors.New(typeNotRegistered)

    // ErrAllowHiddenItem should be used as an error to tell a caller of Hideable#Hide
    // that this type is hidden, but should be shown in a particular case, i.e.
    // if requested by a valid admin or user
    ErrAllowHiddenItem = errors.New(`Allow hidden item`)

    // Types is a map used to reference a type name to its actual Editable type
    // mainly for lookups in /admin route based utilities
    Types map[string]func() interface{}
)

func FmtBytes Uses

func FmtBytes(size float64) string

FmtBytes converts the numeric byte size value to the appropriate magnitude size in KB, MB, GB, TB, PB, or EB.

func FmtTime Uses

func FmtTime(t int64) string

FmtTime shows a human readable time based on the timestamp

func NormalizeString Uses

func NormalizeString(s string) (string, error)

NormalizeString removes and replaces illegal characters for URLs and other path entities. Useful for taking user input and converting it for keys or URLs.

func Slug Uses

func Slug(i Identifiable) (string, error)

Slug returns a URL friendly string from the title of a post item

type FileUpload Uses

type FileUpload struct {
    Item

    Name          string `json:"name"`
    Path          string `json:"path"`
    ContentLength int64  `json:"content_length"`
    ContentType   string `json:"content_type"`
}

FileUpload represents the file uploaded to the system

func (*FileUpload) MarshalEditor Uses

func (f *FileUpload) MarshalEditor() ([]byte, error)

MarshalEditor writes a buffer of html to edit a Post and partially implements editor.Editable

func (*FileUpload) Push Uses

func (f *FileUpload) Push() []string

func (*FileUpload) String Uses

func (f *FileUpload) String() string

String partially implements item.Identifiable and overrides Item's String()

type Hideable Uses

type Hideable interface {
    Hide(http.ResponseWriter, *http.Request) error
}

Hideable lets a user keep items hidden

type Hookable Uses

type Hookable interface {
    BeforeAPICreate(http.ResponseWriter, *http.Request) error
    AfterAPICreate(http.ResponseWriter, *http.Request) error

    BeforeAPIUpdate(http.ResponseWriter, *http.Request) error
    AfterAPIUpdate(http.ResponseWriter, *http.Request) error

    BeforeAPIDelete(http.ResponseWriter, *http.Request) error
    AfterAPIDelete(http.ResponseWriter, *http.Request) error

    BeforeAdminCreate(http.ResponseWriter, *http.Request) error
    AfterAdminCreate(http.ResponseWriter, *http.Request) error

    BeforeAdminUpdate(http.ResponseWriter, *http.Request) error
    AfterAdminUpdate(http.ResponseWriter, *http.Request) error

    BeforeAdminDelete(http.ResponseWriter, *http.Request) error
    AfterAdminDelete(http.ResponseWriter, *http.Request) error

    BeforeSave(http.ResponseWriter, *http.Request) error
    AfterSave(http.ResponseWriter, *http.Request) error

    BeforeDelete(http.ResponseWriter, *http.Request) error
    AfterDelete(http.ResponseWriter, *http.Request) error

    BeforeApprove(http.ResponseWriter, *http.Request) error
    AfterApprove(http.ResponseWriter, *http.Request) error

    BeforeReject(http.ResponseWriter, *http.Request) error
    AfterReject(http.ResponseWriter, *http.Request) error

    // Enable/Disable used for addons
    BeforeEnable(http.ResponseWriter, *http.Request) error
    AfterEnable(http.ResponseWriter, *http.Request) error

    BeforeDisable(http.ResponseWriter, *http.Request) error
    AfterDisable(http.ResponseWriter, *http.Request) error
}

Hookable provides our user with an easy way to intercept or add functionality to the different lifecycles/events a struct may encounter. Item implements Hookable with no-ops so our user can override only whichever ones necessary.

type Identifiable Uses

type Identifiable interface {
    ItemID() int
    SetItemID(int)
    UniqueID() uuid.UUID
    String() string
}

Identifiable enables a struct to have its ID set/get. Typically this is done to set an ID to -1 indicating it is new for DB inserts, since by default a newly initialized struct would have an ID of 0, the int zero-value, and BoltDB's starting key per bucket is 0, thus overwriting the first record.

type Item Uses

type Item struct {
    UUID      uuid.UUID `json:"uuid"`
    ID        int       `json:"id"`
    Slug      string    `json:"slug"`
    Timestamp int64     `json:"timestamp"`
    Updated   int64     `json:"updated"`
}

Item should only be embedded into content type structs.

func (Item) AfterAPICreate Uses

func (i Item) AfterAPICreate(res http.ResponseWriter, req *http.Request) error

AfterAPICreate is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterAPIDelete Uses

func (i Item) AfterAPIDelete(res http.ResponseWriter, req *http.Request) error

AfterAPIDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterAPIUpdate Uses

func (i Item) AfterAPIUpdate(res http.ResponseWriter, req *http.Request) error

AfterAPIUpdate is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterAdminCreate Uses

func (i Item) AfterAdminCreate(res http.ResponseWriter, req *http.Request) error

AfterAdminCreate is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterAdminDelete Uses

func (i Item) AfterAdminDelete(res http.ResponseWriter, req *http.Request) error

AfterAdminDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterAdminUpdate Uses

func (i Item) AfterAdminUpdate(res http.ResponseWriter, req *http.Request) error

AfterAdminUpdate is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterApprove Uses

func (i Item) AfterApprove(res http.ResponseWriter, req *http.Request) error

AfterApprove is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterDelete Uses

func (i Item) AfterDelete(res http.ResponseWriter, req *http.Request) error

AfterDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterDisable Uses

func (i Item) AfterDisable(res http.ResponseWriter, req *http.Request) error

AfterDisable is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterEnable Uses

func (i Item) AfterEnable(res http.ResponseWriter, req *http.Request) error

AfterEnable is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterReject Uses

func (i Item) AfterReject(res http.ResponseWriter, req *http.Request) error

AfterReject is a no-op to ensure structs which embed Item implement Hookable

func (Item) AfterSave Uses

func (i Item) AfterSave(res http.ResponseWriter, req *http.Request) error

AfterSave is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAPICreate Uses

func (i Item) BeforeAPICreate(res http.ResponseWriter, req *http.Request) error

BeforeAPICreate is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAPIDelete Uses

func (i Item) BeforeAPIDelete(res http.ResponseWriter, req *http.Request) error

BeforeAPIDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAPIUpdate Uses

func (i Item) BeforeAPIUpdate(res http.ResponseWriter, req *http.Request) error

BeforeAPIUpdate is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAdminCreate Uses

func (i Item) BeforeAdminCreate(res http.ResponseWriter, req *http.Request) error

BeforeAdminCreate is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAdminDelete Uses

func (i Item) BeforeAdminDelete(res http.ResponseWriter, req *http.Request) error

BeforeAdminDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeAdminUpdate Uses

func (i Item) BeforeAdminUpdate(res http.ResponseWriter, req *http.Request) error

BeforeAdminUpdate is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeApprove Uses

func (i Item) BeforeApprove(res http.ResponseWriter, req *http.Request) error

BeforeApprove is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeDelete Uses

func (i Item) BeforeDelete(res http.ResponseWriter, req *http.Request) error

BeforeDelete is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeDisable Uses

func (i Item) BeforeDisable(res http.ResponseWriter, req *http.Request) error

BeforeDisable is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeEnable Uses

func (i Item) BeforeEnable(res http.ResponseWriter, req *http.Request) error

BeforeEnable is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeReject Uses

func (i Item) BeforeReject(res http.ResponseWriter, req *http.Request) error

BeforeReject is a no-op to ensure structs which embed Item implement Hookable

func (Item) BeforeSave Uses

func (i Item) BeforeSave(res http.ResponseWriter, req *http.Request) error

BeforeSave is a no-op to ensure structs which embed Item implement Hookable

func (Item) IndexContent Uses

func (i Item) IndexContent() bool

IndexContent determines if a type should be indexed for searching partially implements search.Searchable

func (Item) ItemID Uses

func (i Item) ItemID() int

ItemID gets the Item's ID field partially implements the Identifiable interface

func (*Item) ItemSlug Uses

func (i *Item) ItemSlug() string

ItemSlug sets the item's slug for its URL

func (Item) SearchMapping Uses

func (i Item) SearchMapping() (*mapping.IndexMappingImpl, error)

SearchMapping returns a default implementation of a Bleve IndexMappingImpl partially implements search.Searchable

func (*Item) SetItemID Uses

func (i *Item) SetItemID(id int)

SetItemID sets the Item's ID field partially implements the Identifiable interface

func (*Item) SetSlug Uses

func (i *Item) SetSlug(slug string)

SetSlug sets the item's slug for its URL

func (Item) String Uses

func (i Item) String() string

String formats an Item into a printable value partially implements the Identifiable interface

func (Item) Time Uses

func (i Item) Time() int64

Time partially implements the Sortable interface

func (Item) Touch Uses

func (i Item) Touch() int64

Touch partially implements the Sortable interface

func (Item) UniqueID Uses

func (i Item) UniqueID() uuid.UUID

UniqueID gets the Item's UUID field partially implements the Identifiable interface

type Omittable Uses

type Omittable interface {
    Omit(http.ResponseWriter, *http.Request) ([]string, error)
}

Omittable lets a user define certin fields within a content struct to remove from an API response. Helpful when you want data in the CMS, but not entirely shown or available from the content API. All items in the slice should be the json tag names of the struct fields to which they correspond.

type Pushable Uses

type Pushable interface {
    // the values contained by fields returned by Push must strictly be URL paths
    Push(http.ResponseWriter, *http.Request) ([]string, error)
}

Pushable lets a user define which values of certain struct fields are 'pushed' down to a client via HTTP/2 Server Push. All items in the slice should be the json tag names of the struct fields to which they correspond.

type Sluggable Uses

type Sluggable interface {
    SetSlug(string)
    ItemSlug() string
}

Sluggable makes a struct locatable by URL with it's own path. As an Item implementing Sluggable, slugs may overlap. If this is an issue, make your content struct (or one which embeds Item) implement Sluggable and it will override the slug created by Item's SetSlug with your own

type Sortable Uses

type Sortable interface {
    Time() int64
    Touch() int64
}

Sortable ensures data is sortable by time

Package item imports 13 packages (graph) and is imported by 20 packages. Updated 2018-10-29. Refresh now. Tools for package owners.