render

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package render handles output size constraints and paginated rendering of contents and menus against templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrowseConfig

type BrowseConfig struct {
	NextAvailable     bool
	NextSelector      string
	NextTitle         string
	PreviousAvailable bool
	PreviousSelector  string
	PreviousTitle     string
}

BrowseConfig defines the availability and display parameters for page browsing.

func DefaultBrowseConfig

func DefaultBrowseConfig() BrowseConfig

Default browse settings for convenience.

type BrowseError

type BrowseError struct {
	Idx       uint16
	PageCount uint16
}

BrowseError is raised when browsing outside the page range of a rendered node.

func (*BrowseError) Error

func (err *BrowseError) Error() string

Error implements the Error interface.

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

Menu renders menus. May be included in a Page object to render menus for pages.

func NewMenu

func NewMenu() *Menu

NewMenu creates a new Menu with an explicit page count.

func (m *Menu) GetBrowseConfig() BrowseConfig

GetBrowseConfig returns a copy of the current state of the browse configuration.

func (m *Menu) GetOutputSize() uint32

GetOutputSize returns the defined heuristic menu size.

func (m *Menu) Put(selector string, title string) error

Put adds a menu option to the menu rendering.

func (m *Menu) Render(idx uint16) (string, error)

Render returns the full current state of the menu as a string.

After this has been executed, the state of the menu will be empty.

func (m *Menu) ReservedSize() uint16

ReservedSize returns the maximum render byte size of the menu.

func (m *Menu) WithBrowseConfig(cfg BrowseConfig) *Menu

WithBrowseConfig defines the criteria for page browsing.

func (m *Menu) WithOutputSize(outputSize uint16) *Menu

WithSize defines the maximum byte size of the rendered menu.

func (m *Menu) WithPageCount(pageCount uint16) *Menu

WithBrowseConfig defines the criteria for page browsing.

type Page

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

Page exectues output rendering into pages constrained by size.

func NewPage

func NewPage(cache cache.Memory, rs resource.Resource) *Page

NewPage creates a new Page object.

func (*Page) Map

func (pg *Page) Map(key string) error

Map marks the given key for retrieval.

After this, Val() will return the value for the key, and Size() will include the value size and limitations in its calculations.

Only one symbol with no size limitation may be mapped at the current level.

func (*Page) Render

func (pg *Page) Render(sym string, idx uint16) (string, error)

Render renders the current mapped content and menu state against the template associated with the symbol.

func (*Page) RenderTemplate

func (pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16) (string, error)

RenderTemplate is an adapter to implement the builtin golang text template renderer as resource.RenderTemplate.

func (*Page) Reset

func (pg *Page) Reset()

Reset prepared the Page object for re-use.

It clears mappings and removes the sink definition.

func (*Page) Sizes

func (pg *Page) Sizes() (map[string]uint16, error)

Sizes returned the actual used bytes by each mapped symbol.

func (*Page) Usage

func (pg *Page) Usage() (uint32, uint32, error)

Usage returns size used by values and menu, and remaining size available

func (*Page) Val

func (pg *Page) Val(key string) (string, error)

Val gets the mapped content for the given symbol.

Fails if key is not mapped.

func (*Page) WithMenu

func (pg *Page) WithMenu(menu *Menu) *Page

WithMenu sets a menu renderer for the page.

func (*Page) WithSizer

func (pg *Page) WithSizer(sizer *Sizer) *Page

WithSizer sets a size constraints definition for the page.

type Sizer

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

Sizer splits dynamic contents into individual segments for browseable pages.

func NewSizer

func NewSizer(outputSize uint32) *Sizer

NewSizer creates a new Sizer object with the given output size constraint.

func (*Sizer) AddCursor

func (szr *Sizer) AddCursor(c uint32)

AddCursor adds a pagination cursor for the paged sink content.

func (*Sizer) Check

func (szr *Sizer) Check(s string) (uint32, bool)

Check audits whether the rendered string is within the output size constraint of the sizer.

func (*Sizer) GetAt

func (szr *Sizer) GetAt(values map[string]string, idx uint16) (map[string]string, error)

GetAt the paged symbols for the current page index.

Fails if index requested is out of range.

func (*Sizer) MenuSize

func (szr *Sizer) MenuSize() uint16

Menusize returns the currently defined menu size.

func (*Sizer) Set

func (szr *Sizer) Set(key string, size uint16) error

Set adds a content symbol in the state it will be used by the renderer.

func (*Sizer) Size

func (szr *Sizer) Size(s string) (uint16, error)

Size gives the byte size of content for a single symbol.

Fails if the symbol has not been registered using Set

func (*Sizer) String

func (szr *Sizer) String() string

String implements the String interface.

func (*Sizer) WithMenuSize

func (szr *Sizer) WithMenuSize(menuSize uint16) *Sizer

WithMenuSize sets the size of the menu being used in the rendering context.

Jump to

Keyboard shortcuts

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