Documentation ¶
Overview ¶
Package assets implements serving of fully static resources
Index ¶
- Variables
- func NewSharedTemplate(name string, funcMap template.FuncMap) *template.Template
- type Assets
- func (assets *Assets) MustMakeFunc(name string, value string, funcMap template.FuncMap, ...) http.HandlerFunc
- func (assets *Assets) MustParse(t *template.Template, value string) *template.Template
- func (assets *Assets) MustParseShared(name string, value string, funcMap template.FuncMap) *template.Template
- func (assets *Assets) RegisterAssoc(t *template.Template)
Constants ¶
This section is empty.
Variables ¶
var AssetHandler http.Handler
AssetHandler handles serving static files under the /assets/ route
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.
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 ¶
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) MustParse ¶
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 ¶
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.