jawsboot

package
v0.902.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 6 Imported by: 3

README

jawsboot

Embedded Bootstrap CSS and JavaScript for JaWS applications.

See Bootstrap assets for setup, asset provenance, and version updates.

Documentation

Overview

Package jawsboot provides embedded Bootstrap assets for JaWS applications.

The embedded assets are Bootstrap v5.3.8.

Example

Example wires jawsboot into an HTTP server. It is a compile-checked illustration only: it starts a blocking server, so it has no testable Output and is not executed by "go test".

package main

import (
	"embed"
	"log/slog"
	"net/http"
	"sync"

	"github.com/linkdata/jaws"
	"github.com/linkdata/jaws/jawsboot"
	"github.com/linkdata/jaws/lib/bind"
	"github.com/linkdata/jaws/lib/templatereloader"
	"github.com/linkdata/jaws/lib/ui"
	"github.com/linkdata/staticserve"
)

// This example assumes an 'assets' directory:
//
//.  assets/
//.    static/
//.      images/
//.        favicon.png
//.    ui/
//.      index.html

//go:embed assets
var assetsFS embed.FS

func setupJaws(jw *jaws.Jaws, mux *http.ServeMux) error {
	mux.Handle("GET /jaws/", jw) // Ensure the JaWS routes are handled
	tmpl, err := templatereloader.New(assetsFS, "assets/ui/*.html", "")
	if err != nil {
		return err
	}
	if err := jw.AddTemplateLookuper(tmpl); err != nil {
		return err
	}
	// Initialize jawsboot; we will serve the JavaScript and CSS from /static/*.[js|css].
	// All files under assets/static will be available under /static. Any favicon loaded
	// this way will have its URL available using jw.FaviconURL().
	if err := jw.Setup(
		mux.Handle, "/static",
		jawsboot.Setup,
		staticserve.MustNewFS(assetsFS, "assets/static", "images/favicon.png"),
	); err != nil {
		return err
	}
	// Add a route to our index template with a bound variable accessible as '.Dot' in the template
	var mu sync.Mutex
	var f float64
	mux.Handle("GET /{$}", ui.Handler(jw, "index.html", bind.New(&mu, &f)))
	return nil
}

// Example wires jawsboot into an HTTP server. It is a compile-checked
// illustration only: it starts a blocking server, so it has no testable Output
// and is not executed by "go test".
func main() {
	jw, err := jaws.New()
	if err != nil {
		panic(err)
	}
	defer jw.Close()
	jw.Logger = slog.Default()
	if err := setupJaws(jw, http.DefaultServeMux); err != nil {
		panic(err)
	}
	// start the JaWS processing loop and the HTTP server
	go jw.Serve()
	panic(http.ListenAndServe("localhost:8080", nil))
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(jw *jaws.Jaws, handleFn jaws.HandleFunc, prefix string) (urls []*url.URL, err error)

Setup registers embedded Bootstrap static assets under prefix.

It is intended to be passed to jaws.Jaws.Setup. Returned URLs should be included in the page head through jaws.Jaws.GenerateHeadHTML. The prefix may be absolute ("/static"), relative ("static") or empty. The prefix is rooted and cleaned before asset names are joined, so "../static" becomes "/static". The returned URL path and the path component of the registered handler pattern are kept identical in all cases. http.ServeMux pattern syntax in prefix is treated as literal URL path data.

Setup also registers http.NotFoundHandler (404) routes under prefix for the bundled bootstrap *.map sourcemap paths, quietly answering devtools probes for "bootstrap.bundle.min.js.map" and "bootstrap.min.css.map".

The returned URLs are always valid: they are built from clean, slash-rooted paths over content-hashed embedded asset names, so err only ever reflects a failure to walk the embedded filesystem.

Types

This section is empty.

Jump to

Keyboard shortcuts

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