post

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PermissionCreatePost is the permission for creating posts.
	PermissionCreatePost = "create-post"
	// PermissionEditOwnPost is the permission for editing own posts.
	PermissionEditOwnPost = "edit-own-post"
	// PermissionEditAnyPost is the permission for editing any posts.
	PermissionEditAnyPost = "edit-any-post"

	// PageSize is the default page size for post listing pages.
	PageSize = 15
)

Variables

This section is empty.

Functions

func EnsurePostMiddleware

func EnsurePostMiddleware() negroni.Handler

EnsurePostMiddleware loads the post record object from the URL.

func ListPage

func ListPage() http.Handler

ListPage is a http handler that lists posts.

func LoadEntity

func LoadEntity(r *http.Request) (interface{}, error)

LoadEntity loads an entity from the URL with the default parameter name 'id'.

func LoadEntityFromUrl

func LoadEntityFromUrl(r *http.Request, param string) (interface{}, error)

LoadEntityFromUrl loads a post from the URL.

The 'param' tells the name of the parameter where the post's uuid is.

func NewPostForm

func NewPostForm(filter func(string) string) form.Delegate

NewPostForm creates the delegate for the post form.

This form handles the creating and editing of a post.

func NewRevisionsForm

func NewRevisionsForm() form.Delegate

NewRevisionsForm creates the delegate for the post revision form page.

func Pages

func Pages(store keyvalue.Store, filter func(string) string) []server.Route

Pages returns the list of routes for the post entity.

func PostEditAccessMiddleware

func PostEditAccessMiddleware() negroni.Handler

PostEditAccessMiddleware is a middleware that makes sure that the current account has edit access on the post in the URL.

func RevisionDiffPage

func RevisionDiffPage() http.Handler

RevisionDiffPage is a http handler that shows a diff page between two revisions of a post.

Types

type Post

type Post struct {
	ID       uuid.UUID `json:"id"`
	Title    string    `json:"title"`
	Revision uuid.UUID `json:"revision"`
	Created  time.Time `json:"created"`
	Updated  time.Time `json:"updated"`
}

Post represents the post entity.

func (*Post) Publish

func (p *Post) Publish(revision uuid.UUID)

Publish sets a revision as the active one.

func (*Post) Save

func (p *Post) Save(conn database.DB) error

Save inserts or updates a post.

func (Post) SchemaSQL

func (p Post) SchemaSQL() string

SchemaSQL returns the schema for the post entity.

func (*Post) Unpublish

func (p *Post) Unpublish()

Unpublish removes the reference to the active revision.

This hides the post from all of the public listing pages.

type PostRecord

type PostRecord struct {
	Post     *Post
	Revision *PostRevision
}

PostRecord represents a post and its current revision.

func GetPostRecord

func GetPostRecord(r *http.Request) *PostRecord

GetPostRecord returns the loaded PostRecord from the request context.

func (*PostRecord) Save

func (pr *PostRecord) Save(conn database.DB) error

Save inserts or updates a post and its active revision.

type PostRevision

type PostRevision struct {
	ID       uuid.UUID     `json:"id"`
	Post     uuid.UUID     `json:"post"`
	Content  string        `json:"content"`
	Filtered template.HTML `json:"filtered"`
	Author   uuid.UUID     `json:"author"`
	Created  time.Time     `json:"created"`
}

PostRevision represents a post's revision.

func ListRevisions

func ListRevisions(conn database.DB, pid uuid.UUID) ([]*PostRevision, error)

ListRevisions lists revisions for a given post.

func (*PostRevision) Save

func (r *PostRevision) Save(conn database.DB) error

Save inserts a new revision.

func (PostRevision) SchemaSQL

func (r PostRevision) SchemaSQL() string

SchemaSQL returns the schema of the PostRevision.

Jump to

Keyboard shortcuts

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