ui

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Purpose: This file implements the Tempose Ahead-of-Time (AOT) component compilation engine.

Philosophy: GoStack treats frontend components (HTML, CSS, JS) as first-class Go citizens. Rather than parsing template files at runtime (which introduces disk I/O latency and defers syntax errors to production), the compiler transforms all component assets into static Go source code during the build step.

This means the generated file (gostack_components_gen.go) is a standard Go file that is compiled directly into the application binary. The result is:

  • Zero disk I/O on every HTTP request for view rendering.
  • Compile-time guarantees that all registered components exist.
  • A single, portable binary with all assets embedded.

COMPONENT STRUCTURE: Each component lives in its own subdirectory under the components path:

components/
  counter/
    counter.html   ← markup template (supports {{ .Field }} bindings)
    counter.css    ← component-scoped styles
    counter.js     ← component-specific client scripts

The compiler scans this directory structure, processes each asset type, and emits a single Go registration file containing all compiled outputs.

Purpose: This file contains the Glide client-side reactive directive engine, embedded as a Go string constant so the entire runtime ships inside the binary — zero HTTP round-trips to load a JS file.

Philosophy: Glide is GoStack's browser-side reactivity layer. Like Alpine.js, it works directly on existing HTML via data attributes. Unlike Alpine, it is purpose-built for GoStack components and carries zero third-party footprint.

Architecture:

  • GlideJS is a self-contained IIFE (Immediately Invoked Function Expression).
  • It finds all [gs-data] root elements, creates reactive Proxy scopes, then wires all directive attributes (gs-text, gs-click, gs-model, gs-if, gs-each, gs-class, gs-html, gs-submit, gs-change, gs-attr) to live DOM updates.
  • Updates are batched through requestAnimationFrame to avoid thrashing.
  • MutationObserver watches for server-rendered or lazily appended scopes.

Directives:

gs-data="{ key: value }"   — declares a reactive state scope
gs-text="expr"              — binds expression to element text content
gs-html="expr"              — binds expression to element innerHTML
gs-model="key"              — two-way binds <input>/<select>/<textarea> to state key
gs-click="stmt"             — executes statement on click
gs-submit="stmt"            — executes statement on form submit (prevents default)
gs-change="stmt"            — executes statement on input change
gs-if="expr"                — shows/hides element based on truthy expression
gs-show="expr"              — toggles CSS visibility (keeps element in flow)
gs-each="item in list"      — repeats element for each item in a state array
gs-class="{ cls: expr }"    — toggles CSS classes based on an object expression
gs-attr="{ attr: expr }"    — sets element attributes from an object expression

Package ui (Tempose + Glide) coordinates AOT component compilation, scoped asset collection, and the Glide client-side reactive directive engine runtime injection.

Index

Constants

View Source
const CoreBaseCSS = `` /* 2220-byte string literal not displayed */

CoreBaseCSS provides the global semantic styles for elements opting-in via [gs-css].

View Source
const GlideJS = `` /* 14647-byte string literal not displayed */

GlideJS is the Glide reactive directive engine runtime, injected into every GoStack page via WriteMasterAssetBlock. It is written as a pure JavaScript IIFE with zero external dependencies and works in any modern browser.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(data any, field string) any

Evaluate performs a safe runtime reflection lookup of a field name on a given data object.

func RegisterComponentScript

func RegisterComponentScript(name, js string)

RegisterComponentScript registers component-scoped JS scripts during system boot passes.

func RegisterComponentStyle

func RegisterComponentStyle(name, prefixedCSS string)

RegisterComponentStyle saves isolated, prefixed component CSS configurations during system boot passes.

func WriteMasterAssetBlock

func WriteMasterAssetBlock(w io.Writer)

WriteMasterAssetBlock streams the GoStack core styles, the Glide reactive runtime, and all registered component-scoped styles and scripts into the HTTP response writer. It is called once per page render, typically just before the closing </head> tag. No arguments are required — the Glide engine is embedded directly from GlideJS.

Types

type AssetCompiler

type AssetCompiler struct {
	ComponentsPath string
	OutputPath     string
}

AssetCompiler orchestrates the full component compilation pipeline. It scans the components source directory, processes all assets (HTML, CSS, JS), and writes a fully compiled, Go-formatted registration file to the output path.

Fields:

  • ComponentsPath: Absolute or relative path to the components source directory.
  • OutputPath: Absolute or relative path where the generated Go file will be written.

func NewAssetCompiler

func NewAssetCompiler(componentsPath, outputPath string) *AssetCompiler

NewAssetCompiler constructs an AssetCompiler configured with the given source and output paths.

Parameters:

  • componentsPath: The directory containing component subdirectories (e.g. "templates/components").
  • outputPath: The directory where "gostack_components_gen.go" will be written (e.g. "cmd/app").

func (*AssetCompiler) Run

func (c *AssetCompiler) Run() error

Run executes the directory sweep and generates a static Go bootstrap asset file.

Jump to

Keyboard shortcuts

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