site

package module
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 11 Imported by: 0

README ¶

tinywasm/site

Project Badges

Site rendering engine for Go (WASM-friendly).

A lightweight rendering layer built on top of tinywasm/dom, designed to generate web pages with minimal overhead. Provides small, efficient primitives for composing views, routing, and rendering UI structures while keeping WebAssembly binaries tiny and dependency-free.

📚 Documentation

  1. Architecture & Developer Guide: Comprehensive LLM-optimized guide covering the isomorphic rendering engine, routing, modules, components, asset bundling, and RBAC access control.

🔄 Migration

See MIGRATION.md for changes in API (v0.2+).

✨ New Features

  • Nested Routes: Support for #module/param/action.
  • Lifecycle Hooks: BeforeNavigateAway and AfterNavigateTo.
  • Simplified API: site.Serve(":8080") and site.Mount("app").
  • Navigation Component: Navigation UI moved to components/nav.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Mount ¶

func Mount(parentID string) error

Mount hydrates the initial module and blocks forever.

func Navigate(parentID string, hash string) error

Navigate switches to a different module based on the hash.

func RegisterHandlers ¶

func RegisterHandlers(handlers ...any) error

RegisterHandlers registers all handlers with site and crudp

func Render ¶ added in v0.0.17

func Render() error

Render registers the site handlers with the provided mux and prepares assets. DEPRECATED: Use Mount(parentID) instead.

func SetCacheSize ¶ added in v0.0.17

func SetCacheSize(size int)

SetCacheSize configures module cache size (default: 3)

func SetDefaultRoute ¶ added in v0.0.17

func SetDefaultRoute(route string)

SetDefaultRoute configures default route (default: "home")

func SetDevMode ¶ added in v0.0.17

func SetDevMode(enabled bool)

SetDevMode configures development mode (default: false)

func SetOutputDir ¶ added in v0.0.17

func SetOutputDir(dir string)

SetOutputDir configures the output directory for assets (default: "./public")

func Start ¶ added in v0.0.17

func Start(parentID string) error

Start initializes the site by hydrating the current module.

func TestGetModules ¶ added in v0.0.46

func TestGetModules() []*registeredModule

TestGetModules returns the list of registered modules. For testing purposes only.

func TestIsDevMode ¶ added in v0.0.46

func TestIsDevMode() bool

TestIsDevMode returns the current DevMode state of the handler. For testing purposes only.

func TestParseRoute ¶ added in v0.0.46

func TestParseRoute(hash string) (module string, params []string)

TestParseRoute exposes the internal parseRoute function for testing. For testing purposes only.

func TestResetHandler ¶ added in v0.0.46

func TestResetHandler()

TestResetHandler resets the global handler state for testing. For testing purposes only.

func TestResetWasm ¶ added in v0.0.46

func TestResetWasm()

TestResetWasm resets the active module and cache for testing. For testing purposes only.

Types ¶

type Config ¶ added in v0.0.17

type Config struct {
	CacheSize    int
	DefaultRoute string
	OutputDir    string
	DevMode      bool
}

func TestGetConfig ¶ added in v0.0.46

func TestGetConfig() *Config

TestGetConfig returns the global configuration. For testing purposes only.

type Module ¶ added in v0.0.17

type Module interface {
	dom.Component
	HandlerName() string
	ModuleTitle() string
}

Module represents a top-level site module. It combines a DOM component with site-specific identifiers.

type ModuleLifecycle ¶ added in v0.0.17

type ModuleLifecycle interface {
	BeforeNavigateAway() bool // Return false to cancel navigation
	AfterNavigateTo()         // Called after module is mounted
}

ModuleLifecycle provides hooks for navigation events

type Parameterized ¶ added in v0.0.17

type Parameterized interface {
	SetParams(params []string)
}

Parameterized modules can receive route parameters

Directories ¶

Path Synopsis
cmd
sitebuild command
sitebuild compiles a tinywasm/site project and generates static HTML/CSS/JS/SVG output.
sitebuild compiles a tinywasm/site project and generates static HTML/CSS/JS/SVG output.
example
web command

Jump to

Keyboard shortcuts

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