navbar

package
v0.0.0-...-97c67fc Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attrs

func Attrs(entries ...template.HTMLAttr) template.HTMLAttr

Types

type Item

type Item struct {
	// Name is the name to display to the user
	Name string
	// Attr is one (or more) html attributes that should be on the <a>
	// element of this navbar item, this includes the href attribute
	Attr template.HTMLAttr
	// Perm is the permission required to see this item
	Perm radio.UserPermission
}

Item is a single item that should be shown on a navigation bar, the simplest way to render these in a template would be:

`<a {{.Attr}}>{{.Name}}</a>`

func NewItem

func NewItem(name string, attr template.HTMLAttr) Item

func NewProtectedItem

func NewProtectedItem(name string, perm radio.UserPermission, attr template.HTMLAttr) Item
type NavBar struct {

	// Attr contains html attributes that should be applied
	// to the parent of the navbar items
	Attr template.HTMLAttr
	// contains filtered or unexported fields
}

NavBar consists of the items that should be contained in a navigation bar on the website, items can be iterated by using the following template range {{range .NavBar.Values}} the dot will be set to each NavBarItem in order.

an example of rendering the whole navbar would be:

{{range .NavBar.Values}}<a {{.Attr}}>{{.Name}}</a>{{end}}

if you want to use a non-default ordering you need to call Get manually but remember that this might break if a name changes at a later point and so use of Get should always use {{with .NavBar.Get("name")}} to make sure the item actually exists

func New

func New(attrs template.HTMLAttr, items ...Item) NavBar
func (nb NavBar) Get(name string) *Item

Get returns an item by its name, returns nil if the name does not exist

func (nb NavBar) Values() []Item

Values returns a sequence of all the items in this navbar

TODO: change to iter.Seq once we switch to 1.24

func (nb NavBar) WithUser(user *radio.User) NavBar

Jump to

Keyboard shortcuts

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