helpers

package
v0.5.18 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Overview

templ: version: v0.3.1001

templ: version: v0.3.1001

Package helpers provides shared components for templ templates.

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

Index

Constants

This section is empty.

Variables

View Source
var RunStatusThemeMappings = map[runstatus.Status]string{
	runstatus.Applied:            "success",
	runstatus.ApplyQueued:        "secondary",
	runstatus.Applying:           "accent",
	runstatus.Canceled:           "warning",
	runstatus.Confirmed:          "info",
	runstatus.Discarded:          "warning",
	runstatus.Errored:            "error",
	runstatus.ForceCanceled:      "warning",
	runstatus.Pending:            "primary",
	runstatus.PlanQueued:         "secondary",
	runstatus.Planned:            "info",
	runstatus.PlannedAndFinished: "success",
	runstatus.Planning:           "primary",
}

Functions

func Ago

func Ago(t time.Time) templ.Component

func AssetPath

func AssetPath(ctx context.Context, path string) (string, error)

func Authenticated

func Authenticated(ctx context.Context) bool

func Avatar

func Avatar(url *string) templ.Component

func BareLayout

func BareLayout(props BareLayoutProps) templ.Component
func Cookie(ctx context.Context, name string) string

func CopyableContent

func CopyableContent() templ.Component

func CurrentPath

func CurrentPath(ctx context.Context) string

func CurrentURL

func CurrentURL(ctx context.Context) string

func CurrentURLWithoutQuery

func CurrentURLWithoutQuery(ctx context.Context) string

func CurrentUserAvatar

func CurrentUserAvatar() templ.Component

func CurrentUsername

func CurrentUsername(ctx context.Context) (string, error)

func DeleteButton

func DeleteButton() templ.Component

func EditButton

func EditButton() templ.Component

func Error added in v0.5.18

func Error(r *http.Request, w http.ResponseWriter, err string, opts ...ErrorOption)

Error sends an appropriate error response to an http request. If the request was to carry out an operation, i.e. a POST action, then a flash message is set and the user is redirected to the last page. Otherwise it's assumed the request was a normal page navigation request, i.e. a GET action, and an error notice is rendered with an optional status code, defaulting to HTTP500.

func ExternalIcon

func ExternalIcon() templ.Component

func Filter

func Filter[T ~string](props FilterProps[T]) templ.Component

func FilterLabel added in v0.5.18

func FilterLabel(status runstatus.Status) templ.Component

func FlashError added in v0.5.18

func FlashError(w http.ResponseWriter, msg string)

FlashError helper writes a single flash error message

func FlashSuccess added in v0.5.18

func FlashSuccess(w http.ResponseWriter, msg string)

FlashSuccess helper writes a single flash success message

func FlashWarning added in v0.5.18

func FlashWarning(w http.ResponseWriter, msg string)

FlashWarning helper writes a single flash warning message

func Flashes

func Flashes() templ.Component

func Identifier

func Identifier(id resource.TfeID) templ.Component

func IsOwner

func IsOwner(ctx context.Context, organization resource.ID) bool

func IsSiteAdmin

func IsSiteAdmin(ctx context.Context) bool

func Layout

func Layout(props LayoutProps) templ.Component

func MarkdownToHTML added in v0.5.18

func MarkdownToHTML(md []byte) template.HTML
func MenuItem(title string, path string, matchPrefixes ...string) templ.Component

func MergeQuery added in v0.5.18

func MergeQuery(u string, q string) (templ.SafeURL, error)

MergeQuery merges the query string into the given url, replacing any existing query parameters with the same name.

func OrganizationMenu

func OrganizationMenu(organization resource.ID) templ.Component

func PollingTable

func PollingTable[T any](populator TablePopulator[T], page *resource.Page[T]) templ.Component

PollingTable renders a table that polls for updates every X seconds.

func Render added in v0.5.18

func Render(c templ.Component, w http.ResponseWriter, r *http.Request, renderOptions ...RenderOption)

Render a template. Wraps the upstream templ handler to carry out additional actions every time a template is rendered.

func RenderPage added in v0.5.18

func RenderPage(c templ.Component, title string, w http.ResponseWriter, r *http.Request, opts ...RenderPageOption)

RenderPage renders a component within a layout, e.g. header, footer, menus etc.

func RenderSnippet added in v0.5.18

func RenderSnippet(c templ.Component, w io.Writer, r *http.Request) error

func RequestFromContext added in v0.5.18

func RequestFromContext(ctx context.Context) *http.Request

func ResponseFromContext added in v0.5.18

func ResponseFromContext(ctx context.Context) http.ResponseWriter

func ReturnUserOriginalPage added in v0.5.18

func ReturnUserOriginalPage(w http.ResponseWriter, r *http.Request)

ReturnUserOriginalPage returns a user to the original page they tried to access before they were redirected to the login page.

func RunStatusBadge added in v0.5.18

func RunStatusBadge(runID resource.TfeID, status runstatus.Status) templ.Component

func RunStatusFilter added in v0.5.18

func RunStatusFilter(selected []runstatus.Status, visible bool) templ.Component

func SearchDropdown

func SearchDropdown(props SearchDropdownProps) templ.Component

func SendUserToLoginPage added in v0.5.18

func SendUserToLoginPage(w http.ResponseWriter, r *http.Request)

SendUserToLoginPage sends user to the login prompt page, saving the original path they tried to access so it can return them there after login.

func SetCookie added in v0.5.18

func SetCookie(w http.ResponseWriter, name, value string, expiry *time.Time)

SetCookie sets a cookie on the http response. A nil expiry sets no expiry, and a zero expiry sets it to be purged from the browser.

func SiteMenu() templ.Component

func Strikethrough

func Strikethrough(cond bool) templ.Component

func Table

func Table[T any](populator TablePopulator[T], page *resource.Page[T]) templ.Component

func ToBytes

func ToBytes(comp templ.Component) []byte

func ToString

func ToString(comp templ.Component) string

func TokenFlashMessage

func TokenFlashMessage(w gohttp.ResponseWriter, token []byte) error

TokenFlashMessage is a helper for rendering a flash message with an authentication token.

func UnpaginatedTable

func UnpaginatedTable[T any](populator TablePopulator[T], resources []T) templ.Component

func WorkspaceMenu

func WorkspaceMenu(workspace resource.Info, organization resource.ID, authorizer authz.Interface) templ.Component

Types

type BareLayoutProps

type BareLayoutProps struct {
	Title        string
	Organization resource.ID
	Workspace    *resource.Info
	Menu         templ.Component
	PreContent   templ.Component
	PostContent  templ.Component
}
type Breadcrumb struct {
	Name string
	Link string
}
type DropDownUIWidth string
const (
	NarrowDropDown DropDownUIWidth = "narrow"
	WideDropDown   DropDownUIWidth = "wide"
)

type ErrorOption added in v0.5.18

type ErrorOption func(*errorConfig)

func WithStatus added in v0.5.18

func WithStatus(statusCode int) ErrorOption

type FilterProps

type FilterProps[T ~string] struct {
	Title            string
	All              []T
	Selected         []T
	ParamName        string
	Visible          bool
	VisibleParamName string
	Label            func(T) templ.Component
	CheckboxClass    func(T) string
}

type Flash added in v0.5.18

type Flash struct {
	Type    FlashType
	Message string
}

Flash is a Flash message for the web UI

func PopFlashes added in v0.5.18

func PopFlashes(r *http.Request, w http.ResponseWriter) ([]Flash, error)

PopFlashes pops all flash messages off the stack

type FlashStack added in v0.5.18

type FlashStack []Flash

FlashStack is a stack of flash messages

func (*FlashStack) Push added in v0.5.18

func (s *FlashStack) Push(t FlashType, msg string)

func (FlashStack) Write added in v0.5.18

func (s FlashStack) Write(w http.ResponseWriter)

type FlashType added in v0.5.18

type FlashType string
const (
	FlashSuccessType FlashType = "success"
	FlashWarningType FlashType = "warning"
	FlashErrorType   FlashType = "error"
)

func (FlashType) String added in v0.5.18

func (f FlashType) String() string

type LayoutProps

type LayoutProps struct {
	Authorizer     authz.Interface
	Title          string
	Organization   resource.ID
	Workspace      *resource.Info
	Breadcrumbs    []Breadcrumb
	ContentActions templ.Component
	ContentMenu    templ.Component
	PreContent     templ.Component
	PostContent    templ.Component
}

type RenderOption added in v0.5.18

type RenderOption func(ctx context.Context) context.Context

func WithChildren added in v0.5.18

func WithChildren(comp templ.Component) RenderOption

type RenderPageOption added in v0.5.18

type RenderPageOption func(opts *LayoutProps)

func WithBreadcrumbs added in v0.5.18

func WithBreadcrumbs(crumbs ...Breadcrumb) RenderPageOption

func WithContentActions added in v0.5.18

func WithContentActions(comp templ.Component) RenderPageOption

func WithOrganization added in v0.5.18

func WithOrganization(org resource.ID) RenderPageOption

func WithPostContent added in v0.5.18

func WithPostContent(comp templ.Component) RenderPageOption

func WithPreContent added in v0.5.18

func WithPreContent(comp templ.Component) RenderPageOption

func WithWorkspace added in v0.5.18

func WithWorkspace(ws *workspace.Workspace, authorizer authz.Interface) RenderPageOption

type SearchDropdownProps

type SearchDropdownProps struct {
	// Name to send along with value in the POST form
	Name string
	// Existing values to NOT show in the dropdown
	Existing []string
	// Available values to show in the dropdown
	Available []string
	// Action is the form action URL
	Action templ.SafeURL
	// Placeholder to show in the input element.
	Placeholder string
	// Width: "narrow" or "wide"
	Width DropDownUIWidth
}

type TablePopulator

type TablePopulator[T any] interface {
	Header() templ.Component
	Row(T) templ.Component
}

TablePopulator populates a table component with resources of type T.

Jump to

Keyboard shortcuts

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