assets

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package assets implements serving of fully static resources

Index

Constants

This section is empty.

Variables

View Source
var AssetHandler http.Handler

AssetHandler handles serving static files under the /assets/ route

View Source
var Assetshangover = Assets{
	Scripts: `<script type="module" src="/assets/hangover.c7abdb94.js"></script><script src="/assets/hangover.b0ea6023.js" nomodule defer></script><script type="module" src="/assets/hangover.50213d9b.js"></script><script src="/assets/hangover.521713a9.js" nomodule defer></script>`,
	Styles:  `<link rel="stylesheet" href="/assets/hangover.e8e5e272.css">`,
}

Assetshangover contains assets for the 'hangover' entrypoint.

View Source
var Assetshangover_fallback = Assets{
	Scripts: `<script nomodule defer src="/assets/hangover.521713a9.js"></script><script type="module" src="/assets/hangover.50213d9b.js"></script><script type="module" src="/assets/hangover.c7abdb94.js"></script><script src="/assets/hangover.b0ea6023.js" nomodule defer></script><script type="module" src="/assets/hangover_fallback.948ee401.js"></script><script src="/assets/hangover_fallback.111191b2.js" nomodule defer></script>`,
	Styles:  `<link rel="stylesheet" href="/assets/hangover.e8e5e272.css"><link rel="stylesheet" href="/assets/hangover_fallback.38d394c2.css">`,
}

Assetshangover_fallback contains assets for the 'hangover_fallback' entrypoint.

View Source
var Disclaimer string

Disclaimer contains a legal disclaimer about all frontend components.

Functions

func NewSharedTemplate

func NewSharedTemplate(name string, funcMap template.FuncMap) *template.Template

NewSharedTemplate creates a new template with the given name. It will be able to make use of shared templates as well as functions.

Types

type Assets

type Assets struct {
	Scripts string // <script> tags inserted by the asset
	Styles  string // <link> tags inserted by the asset
}

Assets represents a group of assets to be included inside a template.

Assets are generated using the 'build.mjs' script. The script is called using 'go:generate', which stores variables in the form of 'Assets{{Name}}' inside this package.

The build script roughly works as follows: - Delete any previously generated distribution directory. - Bundle the entrypoint sources under 'src/entry/{{Name}}/index.{ts,css}' together with the base './src/base/index.{ts,css}' - Store the output inside the 'dist' directory - Generate new constants of the form {{Name}}

Each asset group should be registered as a parameter to the 'go:generate' line.

func (*Assets) MustMakeFunc

func (assets *Assets) MustMakeFunc(name string, value string, funcMap template.FuncMap, context func(r *http.Request) any) http.HandlerFunc

func (*Assets) MustParse

func (assets *Assets) MustParse(t *template.Template, value string) *template.Template

MustParse parses a new template from the given source and calls [RegisterAssoc] on it.

func (*Assets) MustParseShared

func (assets *Assets) MustParseShared(name string, value string, funcMap template.FuncMap) *template.Template

MustParseShared is like [MustParse], but creates a new SharedTemplate instead

func (*Assets) RegisterAssoc

func (assets *Assets) RegisterAssoc(t *template.Template)

RegisterAssoc registers two new associated templates with t.

The template "scripts" will render all script tags required. The template "styles" will render all style tags required.

If either template already exists, it will be overwritten.

Jump to

Keyboard shortcuts

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