menu

package
v2.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: MIT, MIT Imports: 2 Imported by: 0

README

menu

Menu provides methods to construct flexible menu trees that are independent from the representation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Json

type Json struct {
	Text string `json:",omitempty"`
	Path string `json:",omitempty"`
	Subs []Json `json:",omitempty"`
}

helper for simple json based loading and saving

type Leaf

type Leaf interface {

	// Path returns the URL path for the leaf.
	// If it returns an empty string or a string that begins with ~ or $, the leaf
	// is not treated as a link.
	Path() string

	// String returns the string that is used to represent the leaf.
	// If the leaf is treated as a link (see Path()), String() would return the
	// linked text.
	String() string
}

Leaf is the content of a Node It can be used for the html representation of the menu

func Item

func Item(text, path string) Leaf

Item creates a menu item, based on the given text and path. The returned item can be used as leaf in a menu tree.

type Node

type Node struct {
	// Edges is a collection of menu nodes that are children the current node
	Edges []*Node

	// Leaf contains the item of the current node.
	// The root node of a menu tree has no leaf (<nil>).
	Leaf Leaf
}

Node is a node of a menu tree

func (*Node) FindByPath

func (n *Node) FindByPath(path string) *Node

FindByPath returns the first node that has the given path by starting with the leaf of m and then going through its egdes. If no node is found, <nil> is returned

func (*Node) FindByText

func (n *Node) FindByText(text string) *Node

FindByText returns the first node that has the given text by starting with the leaf and then going through its egdes. If no node is found, <nil> is returned

func (Node) MarshalJSON

func (n Node) MarshalJSON() ([]byte, error)

func (*Node) RootAt

func (n *Node) RootAt(depth int, path string) *Node

RootAt looks for the node with the given path and returns its parent node at nesting level depth. It can be used to get a sub menu for the request path within a http handler to show it in the layout at a different place than other parts of the menu tree. The returned node is a copy of the original node (without the leaf) and may not be used to manipulate the original node. For the later, FindByText() or FindByPath() can be used. If a node was found but it has no edges, <nil> is returned.

func (*Node) UnmarshalJSON

func (n *Node) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON([]byte) error

type WriterTo

type WriterTo interface {

	// WriterTo returns an io.WriterTo that writes the menu tree for the given root node.
	// The leaf matching the given path may be treated in a special way.
	// The given path may be seen as "active" or "selected" path.
	// The tree should only be visited up to the given depth.
	// WriterTo must handle the case when the root is <nil> (empty menu).
	WriterTo(root *Node, depth int, path string) io.WriterTo
}

WriterTo provides a WriterTo that writes a representation of a menu tree

type WriterToFunc

type WriterToFunc func(root *Node, depth int, path string) io.WriterTo

func (WriterToFunc) WriterTo

func (wf WriterToFunc) WriterTo(root *Node, depth int, path string) io.WriterTo

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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