lavish

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 7 Imported by: 0

README

A Lavish HTML Templating System for Go

For when Plush just isn't nice enough.

Have you ever wished that you could write a monolithic web application in Go, with server-side rendering, but you kinda like JSX for HTML templates?

Finally, the day has come* where this can be a reality!

*if you count alpha-quality software without API stability guarantees

Lavish is built on the incredible foundation laid by esbuild and goja to compile JSX to vanilla Javascript and execute it in a pure Go runtime.

It's faster than you might think - not as fast as Plush, of course, but only a few thousand times slower! Surely those handfuls of milliseconds are worth the more comfortable developer experience.

Rendering Engines

Lavish comes bundled with Preact v10 to turn the JSX into an HTML string.

In theory, any JSX framework which also ships a server-side rendering package could be used instead - although you can't have any client-side state, anyway, so what else could you want? Maybe there's a runtime that's even smaller after tree shaking?

Reminder that Lavish is currently in an alpha state

I got the basic idea working in a few hours late one evening and then spent a Saturday setting up this barely presentable package. Use this package at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileJSX

func CompileJSX(name, jsx string, options api.TransformOptions) (program *goja.Program, err error)

CompileJSX to a goja Program.

Types

type Bundle

type Bundle struct {
	// contains filtered or unexported fields
}

func NewBundle

func NewBundle(engine RenderEngine, modules ...Loader) Bundle

func (Bundle) Render

func (b Bundle) Render(program *goja.Program, data any) (rendered string, err error)

func (*Bundle) RenderJSX

func (b *Bundle) RenderJSX(name, jsx string, data any) (rendered string, err error)

func (Bundle) WithDataVariable

func (b Bundle) WithDataVariable(varName string) Bundle

func (Bundle) WithProgramCache

func (b Bundle) WithProgramCache(cache ProgramCache) Bundle

func (Bundle) WithRenderCache

func (b Bundle) WithRenderCache(cache RenderCache) Bundle

func (Bundle) WithRenderFunction

func (b Bundle) WithRenderFunction(funcName string) Bundle

type Hashable

type Hashable interface {
	Hash64() uint64
}

type Loader

type Loader interface {
	// Load module into runtime environment.
	Load(*goja.Runtime) error
}

A Loader loads a module into a runtime environment.

func ComponentJSX

func ComponentJSX(name, source string, options api.TransformOptions) Loader

type LoaderFunc

type LoaderFunc func(*goja.Runtime) error

func (LoaderFunc) Load

func (f LoaderFunc) Load(vm *goja.Runtime) error

type ProgramCache

type ProgramCache interface {
	AddProgram(k uint64, v *goja.Program)
	GetProgram(k uint64) (cached *goja.Program)
}

type RenderCache

type RenderCache interface {
	AddRender(program uint64, data uint64, v string)
	GetRender(program uint64, data uint64) (cached string, ok bool)
}

type RenderEngine

type RenderEngine interface {
	Loader

	// GetJSXOptions to transpile to vanilla JS.
	GetJSXOptions() api.TransformOptions

	// GetRenderFunction after it has been loaded into the runtime environment.
	// This function should take exactly 1 argument and produce a string.
	GetRenderFunction(*goja.Runtime) (goja.Callable, error)
}

type TransformError

type TransformError struct {
	Name     string
	Errors   []api.Message
	Warnings []api.Message
}

func (TransformError) Error

func (err TransformError) Error() string

Directories

Path Synopsis
engine
preact10
Package preact10 is the public interface for the Preact v10.x render engine.
Package preact10 is the public interface for the Preact v10.x render engine.
examples
internal

Jump to

Keyboard shortcuts

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