html

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package html contains code relating specifically to the web UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddStaticHandler

func AddStaticHandler(logger logr.Logger, r *mux.Router) error

AddStaticHandler adds a handler to router serving static assets (JS, CSS, etc) from within go binary. Enabling developer mode sources files from local disk instead and starts a live reload server, which reloads the browser whenever static files change.

func Error

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 FlashError

func FlashError(w http.ResponseWriter, msg string)

FlashError helper writes a single flash error message

func FlashSuccess

func FlashSuccess(w http.ResponseWriter, msg string)

FlashSuccess helper writes a single flash success message

func FlashWarning

func FlashWarning(w http.ResponseWriter, msg string)

FlashWarning helper writes a single flash warning message

func MarkdownToHTML

func MarkdownToHTML(md []byte) template.HTML

func MergeQuery added in v0.3.14

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 Render added in v0.3.14

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

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

func RenderSnippet added in v0.3.15

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

func RequestFromContext added in v0.3.14

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

func ResponseFromContext added in v0.3.14

func ResponseFromContext(ctx context.Context) http.ResponseWriter

func ReturnUserOriginalPage

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 SendUserToLoginPage

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

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.

Types

type CacheBuster added in v0.3.14

type CacheBuster struct {
	fs.FS
}

CacheBuster provides a cache-busting filesystem wrapper, mapping paths with a specific format containing a sha256 hash to paths without the hash in the wrapped filesystem. i.e. mapping

/css/main.1fc822f99a2cfb6b5f316f00107a7d2770d547b64f3e0ea69baec12001a95f9f.css -> /css/main.css

var (
	AssetsFS *CacheBuster
)

func (*CacheBuster) Open added in v0.3.14

func (cb *CacheBuster) Open(fname string) (http.File, error)

Open strips the hash from the name before opening it in the wrapped filesystem.

func (*CacheBuster) Path added in v0.3.14

func (cb *CacheBuster) Path(fname string) (string, error)

Path inserts a hash of the named file into its filename, before the filename extension: <path>.<ext> -> <path>.<hash>.<ext>, where <hash> is the hex format of the SHA256 hash of the contents of the file.

type DropDownUIWidth string
const (
	NarrowDropDown DropDownUIWidth = "narrow"
	WideDropDown   DropDownUIWidth = "wide"
)
type DropdownUI 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 string
	// Placeholder to show in the input element.
	Placeholder string
	// Width: "narrow" or "wide"
	Width DropDownUIWidth
}

DropdownUI populates a search/dropdown UI component.

type ErrorOption added in v0.4.7

type ErrorOption func(*errorConfig)

func WithStatus added in v0.4.7

func WithStatus(statusCode int) ErrorOption

type Flash added in v0.3.18

type Flash struct {
	Type    FlashType
	Message string
}

Flash is a Flash message for the web UI

func PopFlashes

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

PopFlashes pops all flash messages off the stack

type FlashStack

type FlashStack []Flash

FlashStack is a stack of flash messages

func (*FlashStack) Push

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

func (FlashStack) Write

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

type FlashType added in v0.3.14

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

func (FlashType) String added in v0.3.14

func (f FlashType) String() string

Directories

Path Synopsis
templ: version: v0.3.943
templ: version: v0.3.943
paths
Package paths are paths for use in templ templates.
Package paths are paths for use in templ templates.
Package paths provides rails-style path helpers for use with the web app.
Package paths provides rails-style path helpers for use with the web app.

Jump to

Keyboard shortcuts

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