roles

package
v0.9.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package roles holds the role model and the visual decorations it produces.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSVGTag = errors.New("roles: icon has no <svg tag")

Functions

func ColorizeIcon

func ColorizeIcon(svg, color string) (string, error)

ColorizeIcon injects a colour rule after the opening <svg> and percent encodes the result for a data: URI. The style element is spliced in without its final > because the join below supplies one.

Types

type Badge

type Badge struct {
	Text       string
	Bg         string
	TextColor  string
	ShowBorder bool
	Tooltip    string
}

type Icon

type Icon struct {
	Icon    string
	Color   string
	Tooltip string
}

type IconLoader

type IconLoader func(path string) (string, error)

IconLoader reads a role icon, given the path stored in the icon column relative to the media root.

func FileIcons

func FileIcons(root string) IconLoader

FileIcons reads role icons out of the media root. The icon column holds a path chosen in the admin, so it goes through Resolve rather than a plain join.

type InlineVisualMode

type InlineVisualMode string
const (
	InlineHidden InlineVisualMode = "hidden"
	InlineBadge  InlineVisualMode = "badge"
	InlineIcon   InlineVisualMode = "icon"
)

type ProfileVisualMode

type ProfileVisualMode string
const (
	ProfileHidden ProfileVisualMode = "hidden"
	ProfileBadge  ProfileVisualMode = "badge"
	ProfileStatus ProfileVisualMode = "status"
)

type Role

type Role struct {
	ID                int64
	Slug              string
	Name              string
	ShortName         string
	CategoryID        *int64
	Index             int
	IsStaff           bool
	GroupVotes        bool
	InlineVisualMode  InlineVisualMode
	ProfileVisualMode ProfileVisualMode
	Color             string
	Icon              string
	BadgeText         string
	BadgeBg           string
	BadgeTextColor    string
	BadgeShowBorder   bool
}

func (Role) IsVisual

func (r Role) IsVisual() bool

func (Role) NameTail

func (r Role) NameTail(load IconLoader) (*Badge, *Icon, error)

NameTail returns at most one of the two; a role in icon mode with no icon file produces neither.

type Showcase

type Showcase struct {
	Badges []Badge
	Titles []string
}

func ShowcaseOf

func ShowcaseOf(rs []Role) Showcase

ShowcaseOf is the profile page's half of NameTails, and it reads a different column. Only one role per category reaches it, whatever mode each is in.

type Tails

type Tails struct {
	Badges []Badge
	Icons  []Icon
}

func NameTails

func NameTails(rs []Role, load IconLoader) (Tails, error)

Roles must arrive ordered by index, since the first role of a given mode and category pair is the one that wins.

Jump to

Keyboard shortcuts

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