assets

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 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/odbc.38d394c2.js"></script><script src="/assets/odbc.2845d50f.js" nomodule="" defer></script><script type="module" src="/assets/hangover.b56ed8cb.js"></script><script src="/assets/hangover.726809f4.js" nomodule="" defer></script>`,
	Styles:  `<link rel="stylesheet" href="/assets/hangover.b145512e.css">`,
}

Assetshangover contains assets for the 'hangover' entrypoint.

View Source
var Assetsodbc = Assets{
	Scripts: `<script type="module" src="/assets/odbc.38d394c2.js"></script><script src="/assets/odbc.2845d50f.js" nomodule="" defer></script><script type="module" src="/assets/odbc.07ea4a36.js"></script><script src="/assets/odbc.1ce8c8fb.js" nomodule="" defer></script>`,
	Styles:  `<link rel="stylesheet" href="/assets/odbc.0acd24a7.css">`,
}

Assetsodbc contains assets for the 'odbc' entrypoint.

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