jawsboot

package
v0.106.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 5 Imported by: 3

README

jawsboot

Provides a statically served and embedded version of Bootstrap.

Example usage that loads your templates, favicon and Bootstrap. Also uses a templatereloader so that when running with -tags debug or -race templates are reloaded from disk as needed.

//go:embed assets
var assetsFS embed.FS

func setupRoutes(jw *jaws.Jaws, mux *http.ServeMux) (faviconuri string, err error) {
	var tmpl jaws.TemplateLookuper
	if tmpl, err = templatereloader.New(assetsFS, "assets/ui/*.html", ""); err == nil {
		jw.AddTemplateLookuper(tmpl)
		if faviconuri, err = staticserve.HandleFS(assetsFS, "assets", "static/images/favicon.png", mux.Handle); err == nil {
			if err = jawsboot.Setup(jw, mux.Handle, faviconuri); err == nil {
				mux.Handle("/jaws/", jw) // ensure the JaWS routes are handled
				// set up your other routes
			}
		}
	}
	return
}

The example expects an assets directory in the source tree:

assets
├── static
│   └── images
│       └── favicon.png
└── ui
    ├── somepage.html
    ├── otherpage.html
    └── index.html

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Files added in v0.80.0

func Files() (files []*staticserve.StaticServe, err error)

Files returns the staticserve.StaticServe entries for the embedded Bootstrap JS and CSS.

func GenerateHeadHTML added in v0.80.0

func GenerateHeadHTML(jw *jaws.Jaws, prefix string, files []*staticserve.StaticServe, extra ...string) (err error)

GenerateHeadHTML calls jw.GenerateHeadHTML with URL's for the staticserve files prefixed with the given path prefix and any extra URL's you provide.

func Setup

func Setup(jw *jaws.Jaws, handleFn HandleFunc, extra ...string) (err error)

Setup calls SetupUsing with a prefix of "/static".

func SetupUsing

func SetupUsing(jw *jaws.Jaws, prefix string, handleFn HandleFunc, extra ...string) (err error)

SetupUsing sets up Jaws to serve the Bootstrap files from the prefix path, calling handleFn for each URI and staticserve.StaticServe. If handleFn is nil, http.DefaultServeMux.Handle is used instead. Any extra URL's given are passed to GenerateHeadHTML.

Types

type HandleFunc added in v0.80.0

type HandleFunc = func(uri string, handler http.Handler)

HandleFunc matches the signature of http.ServeMux.Handle(), but is called without method or parameters for the pattern. E.g. ("/static/filename.1234567.js").

Jump to

Keyboard shortcuts

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