nebula

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

nebula 🪐

GoDoc Build Status Codecov Go Report Card Version

A loosely coupled library for building and editing HTML content

Nebula is a container format for rich HTML content, along with a reference library of HTML layouts and widgets, along with transactions to change items within the container.

Each nebula item has a view-only method along ith an editor method. This lets developers create in-place editors for all kinds of applications.

Instead of storing content items in a natural, nested format, nebula puts each one in a single-dimensional array, which simplifies direct access to individual content items.

Widget Library (in-progress)

  • WYSIWYG content editor
  • Image Uploads (with hooks into mediaserver)
  • OEmbed content for pictures, videos, and other rich objects
  • more to come

Layout Library (in progress)

  • Row Layouts
  • Responsive Columns (coming soon)
  • Tab Control (coming soon)

DO NOT USE

This project is a work-in-progress, and should NOT be used by ANYONE, for ANY PURPOSE, under ANY CIRCUMSTANCES. It is NOT READY FOR PRIME TIME, and is essentially GUARANTEED to blow up your computer, send your cat into an infinite loop, and combine your hot and cold laundry into a single cycle.

Pull Requests Welcome

This library is a work in progress, and will benefit from your experience reports, use cases, and contributions. If you have an idea for making this library better, send in a pull request. We're all in this together! 🤔

Documentation

Index

Constants

View Source
const ItemTypeHTML = "HTML"

ItemTypeHTML describes an HTML code editor

View Source
const ItemTypeLayout = "LAYOUT"

ItemTypeLayout represents a Layout widget

View Source
const ItemTypeMarkdown = "Markdown"

ItemTypeMarkdown describes a what-you-see-is-what-you-get content editor

View Source
const ItemTypeOEmbed = "OEMBED"

ItemTypeOEmbed describes an oEmbed object (see https://oembed.com)

View Source
const ItemTypeTabs = "TABS"

ItemTypeTabs describes a multi-tab container layout

View Source
const ItemTypeText = "TEXT"

ItemTypeText describes a plain text editor

View Source
const ItemTypeWYSIWYG = "WYSIWYG"

ItemTypeWYSIWYG describes a what-you-see-is-what-you-get content editor

View Source
const LayoutPlaceAbove = "ABOVE"

LayoutPlaceAbove represents the placement of a new item above the reference item

View Source
const LayoutPlaceAfter = "AFTER"

LayoutPlaceAfter represents the placement of a new item after the reference item

View Source
const LayoutPlaceBefore = "BEFORE"

LayoutPlaceBefore represents the placement of a new item before the reference item

View Source
const LayoutPlaceBelow = "BELOW"

LayoutPlaceAbove represents the placement of a new item below the reference item

View Source
const LayoutPlaceLeft = "LEFT"

LayoutPlaceAbove represents the placement of a new item to the left of the reference item

View Source
const LayoutPlaceRight = "RIGHT"

LayoutPlaceAbove represents the placement of a new item to the right of the reference item

View Source
const LayoutStyleColumns = "COLS"

LayoutStyle Colums represents a group of content items organized into responsive columns

View Source
const LayoutStyleRows = "ROWS"

LayoutStyleRows represents a group of content items organized into rows

Variables

This section is empty.

Functions

func Edit

func Edit(library *Library, container *Container, endpoint string) string

Edit returns an HTML string containing the EDIT version of the container

func View

func View(library *Library, container *Container) string

View returns an HTML string containing the VIEW version of the container

Types

type Action

type Action interface {
	Get(library *Library, container *Container, endpoint string) string

	// Execute performs an update to the content data.  It returns
	// the ID of the element to be re-rendered on the client, along
	// with an error (if present).  Implementations can use this to
	// selectively re-render portions of the content structure without
	// reloading the entire page.
	Post(library *Library, container *Container) (int, error)
}

Action interface wraps the "Execute" method, which takes some non-reversible, non-idempotent action on the container.

func NewAction

func NewAction(in map[string]interface{}) Action

type AddItem

type AddItem struct {
	ItemID    int    `json:"itemId"    form:"itemId"`    // ID of the layout that will hold the new item
	SubItemID int    `json:"subItemID" form:"subItemId"` // ID of the item used for relative positioning
	Place     string `json:"place"     form:"place"`     // Position of the new element (BEFORE, AFTER) relative to the index
	ItemType  string `json:"itemType"  form:"itemType"`  // Type of content item to add
	Style     string `json:"style"     form:"style"`     // Optional "style" aregument for certain types (like layouts)
	Check     string `json:"check"     form:"check"`     // Checksum to validation transaction.
}

func (AddItem) Get added in v0.2.0

func (txn AddItem) Get(library *Library, container *Container, endpoint string) string

func (AddItem) Post added in v0.2.0

func (txn AddItem) Post(library *Library, container *Container) (int, error)

Execute performs the AddItem transaction on the provided content structure

type ChangeType

type ChangeType struct {
	ItemID   int    `json:"itemId"   form:"itemId"`   // ID of the root item that will be added to
	ItemType string `json:"itemType" form:"itemType"` // Type of content item to add
	Check    string `json:"check"    form:"check"`    // Checksum to validation transaction.
}

func (ChangeType) Get added in v0.2.0

func (txn ChangeType) Get(library *Library, container *Container, endpoint string) string

func (ChangeType) Post added in v0.2.0

func (txn ChangeType) Post(library *Library, container *Container) (int, error)

Execute performs the ChangeType transaction on the provided content structure

type Container

type Container []Item

Container represents a complete package of container

func NewContainer

func NewContainer() Container

NewContainer returns a fully initialized Container object

func (*Container) AddFirstReference

func (container *Container) AddFirstReference(itemID int, newItemID int)

func (*Container) AddLastReference

func (container *Container) AddLastReference(itemID int, newItemID int)

func (*Container) AddReference

func (container *Container) AddReference(parentID int, place string, referenceID int, newItemID int)

AddReference links the newItemID into the parent's reference list, placed relative to the referenceID

func (*Container) Compact

func (container *Container) Compact()

Compact removes any unused items in the container slice and reorganizes references

func (*Container) DeleteReference

func (container *Container) DeleteReference(parentID int, referenceID int)

func (*Container) Get added in v0.2.0

func (container *Container) Get(library *Library, input map[string]interface{}, endpoint string) string

Execute parses and executes a new Action against this container.

func (*Container) GetChecksum

func (container *Container) GetChecksum(itemID int) string

GetChecksum returns the checksum of the designated item

func (*Container) GetItem

func (container *Container) GetItem(itemID int) Item

GetItem returns a copy of the item at the desired index

func (*Container) GetParentID

func (container *Container) GetParentID(itemID int) int

GetParent searches for the ID of a parent item

func (*Container) GetRefs

func (container *Container) GetRefs(itemID int) []int

GetRefs returns the child references of the designated item

func (*Container) GetType

func (container *Container) GetType(itemID int) string

GetType returns the item type of the designated item

func (*Container) IsNil

func (container *Container) IsNil(itemID int) bool

IsNil returns TRUE if the identified item is empty or out of bounds

func (*Container) Len

func (container *Container) Len() int

Len returns the number of items in the container

func (*Container) NewChecksum added in v0.2.0

func (container *Container) NewChecksum(itemID int)

NewChecksum assigns a new checksum value to the designated item

func (*Container) NewItem

func (container *Container) NewItem(itemType string, data maps.Map) int

NewItem creates a new item of the designated type

func (*Container) NewItemWithInit

func (container *Container) NewItemWithInit(library *Library, itemType string, data maps.Map) int

NewItem creates a new item of the designated type and initializes it with the default Init() method from the corresponding widget library

func (*Container) Post added in v0.2.0

func (container *Container) Post(library *Library, input map[string]interface{}) (int, error)

Execute parses and executes a new Action against this container.

type DeleteItem

type DeleteItem struct {
	ItemID int    `json:"itemId" form:"itemId"`
	Check  string `json:"check"  form:"check"`
}

Delete action removes a single item from a container

func (DeleteItem) Get added in v0.2.0

func (txn DeleteItem) Get(library *Library, container *Container, endpoint string) string

func (DeleteItem) Post added in v0.2.0

func (txn DeleteItem) Post(library *Library, container *Container) (int, error)

Execute removes a single itme from a container

type Getter

type Getter interface {
	GetContainer() Container
}

Getter wraps the "GetContainer" method, which allows an object to safely expose it's underlying container data

type GetterSetter

type GetterSetter interface {
	Getter
	Setter
}

GetterSetter wraps both "GetContainer" and "SetContainer" methods, allowing read/write access to an object's underlying container data.

type HTML

type HTML struct{}

HTML widget displays plain HTML content

func (HTML) Edit

func (w HTML) Edit(b *html.Builder, container *Container, id int, endpoint string)

Edit renders a plain text editor for editing HTML code

func (HTML) Validate added in v0.3.0

func (w HTML) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (HTML) View

func (w HTML) View(b *html.Builder, container *Container, id int)

View renders the HTML content of the widget

type Item

type Item struct {
	Type  string   `json:"type"           bson:"type"`  // The type of contem item (WYSIWYG, CONTAINER, OEMBED, ETC...)
	Check string   `json:"check"          bson:"check"` // A random code or nonce to authenticate requests
	Refs  []int    `json:"refs,omitempty" bson:"refs"`  // Indexes of sub-items contained by this item
	Data  maps.Map `json:"data,omitempty" bson:"data"`  // Additional data specific to this item type.
}

Item represents a single piece of content. It will be rendered by one of several rendering Libraries, using the custom data it contains.

func NewItem

func NewItem(t string, refs ...int) Item

NewItem returns a fully initialized Item

func (*Item) AddFirstReference

func (item *Item) AddFirstReference(id int)

AddFirstReference adds an itemID to the beginning of the reference list

func (*Item) AddLastReference

func (item *Item) AddLastReference(id int)

AddLastReference adds and itemID to the end of the reference list

func (*Item) AddReference

func (item *Item) AddReference(id int, index int)

AddReference adds a new item into the middle of the reference list

func (*Item) DeleteReference

func (item *Item) DeleteReference(itemID int)

DeleteReference removes a reference from this Item.

func (*Item) GetBytes added in v0.6.2

func (item *Item) GetBytes(key string) []byte

func (*Item) GetInt

func (item *Item) GetInt(key string) int

func (*Item) GetInterface

func (item *Item) GetInterface(key string) interface{}

func (*Item) GetPath

func (item *Item) GetPath(path string) (interface{}, bool)

func (*Item) GetSliceOfInt

func (item *Item) GetSliceOfInt(key string) []int

func (*Item) GetSliceOfString

func (item *Item) GetSliceOfString(key string) []string

func (*Item) GetString

func (item *Item) GetString(key string) string

func (*Item) IsEmpty

func (item *Item) IsEmpty() bool

IsEmpty returns TRUE if this item does not have a valid item.Type

func (*Item) Set

func (item *Item) Set(key string, value interface{}) *Item

func (*Item) SetPath

func (item *Item) SetPath(path string, value interface{}) error

func (*Item) UnmarshalMap

func (item *Item) UnmarshalMap(value map[string]interface{})

UnmarshalMap extracts data from a map[string]interface{} to populate this Item

func (*Item) UpdateReference

func (item *Item) UpdateReference(from int, to int)

UpdateReference migrates references from an old value to a new one

func (*Item) Validate

func (item *Item) Validate(checksum string) error

Validate checks that an item has a type (meaning it has been found by container.GetItem) and has a valid checksum

type ItemType

type ItemType struct {
	Code        string
	Label       string
	Description string
	Icon        string
	Data        maps.Map
}

func ItemTypes

func ItemTypes() []ItemType

ItemTypes returns all item types provided by this widget library

type Layout

type Layout struct {
	// contains filtered or unexported fields
}

func (Layout) Edit

func (w Layout) Edit(b *html.Builder, container *Container, layoutID int, endpoint string)

func (Layout) Init

func (w Layout) Init(container *Container, id int)

Init adds a child WYSIWYG element

func (Layout) Validate added in v0.3.0

func (w Layout) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (Layout) View

func (w Layout) View(b *html.Builder, container *Container, layoutID int)

View dsplays the layout and its children.

type Library

type Library map[string]Widget

func NewLibrary

func NewLibrary() Library

func (*Library) Edit

func (library *Library) Edit(builder *html.Builder, container *Container, id int, endpoint string)

Edit safely renders a widget's Edit method (including any sub-widgets)

func (*Library) Init

func (library *Library) Init(container *Container, id int)

func (*Library) Register

func (library *Library) Register(name string, widget Widget)

Register adds a new named widget to the library

func (*Library) Validate added in v0.3.0

func (library *Library) Validate(container *Container)

Validate scans all content in the container, removing invalid content before it is saved.

func (*Library) View

func (library *Library) View(builder *html.Builder, container *Container, id int)

View safely renders a widget's View method (including any sub-widgets)

func (*Library) Widget

func (library *Library) Widget(name string) Widget

Widget looks up a widget in the library by its name. If no matching widget is found, than an empty "Nil" widget is returned

type Markdown added in v0.6.2

type Markdown struct{}

func (Markdown) Edit added in v0.6.2

func (w Markdown) Edit(b *html.Builder, container *Container, id int, endpoint string)

func (Markdown) Init added in v0.6.2

func (w Markdown) Init(container *Container, id int)

Init sets up an empty "html" property

func (Markdown) Prop added in v0.6.2

func (w Markdown) Prop(container *Container, id int, params url.Values) (string, error)

func (Markdown) Validate added in v0.6.2

func (w Markdown) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (Markdown) View added in v0.6.2

func (w Markdown) View(b *html.Builder, container *Container, id int)

type MoveItem

type MoveItem struct {
	ItemID      int    `json:"itemId"      form:"itemId"`
	NewParentID int    `json:"newParentId" form:"newParentId"`
	Position    int    `json:"position"    form:"position"`
	Check       string `json:"check"       form:"check"`
}

func (MoveItem) Get added in v0.2.0

func (txn MoveItem) Get(library *Library, container *Container, endpoint string) string

func (MoveItem) Post added in v0.2.0

func (txn MoveItem) Post(library *Library, container *Container) (int, error)

type NilAction

type NilAction maps.Map

func (NilAction) Get added in v0.2.0

func (txn NilAction) Get(library *Library, container *Container, endpoint string) string

func (NilAction) Post added in v0.2.0

func (txn NilAction) Post(library *Library, container *Container) (int, error)

type NilWidget

type NilWidget struct{}

NilWidget is a default/empty widget that does nothing.

func (NilWidget) Edit

func (w NilWidget) Edit(b *html.Builder, container *Container, id int, endpoint string)

func (NilWidget) Validate added in v0.3.0

func (w NilWidget) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (NilWidget) View

func (w NilWidget) View(b *html.Builder, container *Container, id int)

type OEmbed

type OEmbed struct{}

func (OEmbed) Edit

func (w OEmbed) Edit(b *html.Builder, container *Container, itemID int, endpoint string)

func (OEmbed) Validate added in v0.3.0

func (w OEmbed) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (OEmbed) View

func (w OEmbed) View(b *html.Builder, container *Container, itemID int)

type Setter

type Setter interface {
	SetContainer(Container)
}

Setter wraps the "SetContent" method, which allows an object to safely expose it's underlying container data

type SortChildren added in v0.2.0

type SortChildren struct {
	ItemID   int    `json:"itemId"   form:"itemId"`   // ID of the layout that will hold the new item
	ChildIDs []int  `json:"childIds" form:"childIds"` // Sorted list of IDs to use for child references
	Check    string `json:"check"    form:"check"`    // Checksum to validation transaction.
}

func (SortChildren) Get added in v0.2.0

func (txn SortChildren) Get(library *Library, container *Container, endpoint string) string

func (SortChildren) Post added in v0.2.0

func (txn SortChildren) Post(library *Library, container *Container) (int, error)

Execute performs the SortChildren transaction on the provided content structure

type Tabs

type Tabs struct {
	// contains filtered or unexported fields
}

func (Tabs) Edit

func (w Tabs) Edit(b *html.Builder, container *Container, id int, endpoint string)

func (Tabs) Init

func (w Tabs) Init(container *Container, id int)

Init appends three empty tabs into this tab control.

func (Tabs) Validate added in v0.3.0

func (w Tabs) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (Tabs) View

func (w Tabs) View(b *html.Builder, container *Container, id int)

View displays that tabs in HTML, along with sub-elements

type Text

type Text struct{}

func (Text) Edit

func (w Text) Edit(b *html.Builder, container *Container, id int, endpoint string)

Edit returns a textarea where the text content can be edited

func (Text) Validate added in v0.3.0

func (w Text) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (Text) View

func (w Text) View(b *html.Builder, container *Container, id int)

View returns the Text widget, rendered as HTML

type UpdateItem

type UpdateItem struct {
	ItemID int                    `json:"itemId" form:"itemId"`
	Data   map[string]interface{} `json:"data"   form:"data"`
	Check  string                 `json:"hash"   form:"hash"`
}

func (UpdateItem) Get added in v0.2.0

func (txn UpdateItem) Get(library *Library, container *Container, endpoint string) string

func (UpdateItem) Post added in v0.2.0

func (txn UpdateItem) Post(library *Library, container *Container) (int, error)

type UploadFile

type UploadFile struct {
	ItemID int    `json:"itemId" form:"itemId"`
	File   string `json:"file" form:"file"`
	Check  string `json:"hash"   form:"hash"`
}

func (UploadFile) Get added in v0.2.0

func (txn UploadFile) Get(library *Library, container *Container, endpoint string) string

func (UploadFile) Post added in v0.2.0

func (txn UploadFile) Post(library *Library, container *Container) (int, error)

type WYSIWYG

type WYSIWYG struct{}

func (WYSIWYG) Edit

func (w WYSIWYG) Edit(b *html.Builder, container *Container, id int, endpoint string)

func (WYSIWYG) Init

func (w WYSIWYG) Init(container *Container, id int)

Init sets up an empty "html" property

func (WYSIWYG) Prop

func (w WYSIWYG) Prop(container *Container, id int, params url.Values) (string, error)

func (WYSIWYG) Validate added in v0.3.0

func (w WYSIWYG) Validate(container *Container, index int)

Validate cleans the container for invalid content

func (WYSIWYG) View

func (w WYSIWYG) View(b *html.Builder, container *Container, id int)

type Widget

type Widget interface {

	// View writes the widget HTML into the provided HTML builder
	View(*html.Builder, *Container, int)

	// Edit writes an editable widget into the provided HTML builder
	Edit(*html.Builder, *Container, int, string)

	// Validate cleans/updates each item, stripping strip away invalid content
	Validate(*Container, int)
}

type WidgetIniter

type WidgetIniter interface {

	// Init is called on every new Item in the container data.
	// It allows widgets to customize their internal data before use.
	Init(*Container, int)
}

Jump to

Keyboard shortcuts

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