clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

main
atlas / internal / workbench / assets.go
assets.go 1.8K
1package workbench23import (4 "bytes"5 "embed"6 "io/fs"7 "sync"8)910// The workbench's own chrome.11//12// Two files, embedded: the identity's token system and one stylesheet for the13// pages here. tokens.css is the reference implementation's own file, carried as14// an asset rather than as code (issue #5 ยง9) and identical to the copy the15// application serves -- the workbench is a different surface of one program and16// must not be a different colour. Everything below the tokens is this17// surface's: dense tables, score headlines, and a console pane, which the18// application has no use for.19//20// The hypermedia runtime is deliberately not here. htmx is vendored once, in21// the application's assets, and reaches this handler as bytes through22// [Options.Runtime]: one vendored copy, one licence file, and no import edge23// between two lanes that must not depend on each other. `atlas workbench` --24// which may import both -- is what hands it over.2526//go:embed templates/*.tmpl assets/*.css27var files embed.FS2829// stylesheets is the cascade, in order: the tokens first, because everything30// after them is spelled in their terms.31var stylesheets = []string{"assets/tokens.css", "assets/workbench.css"}3233var (34 sheetOnce sync.Once35 sheet []byte36)3738// stylesheet is the whole cascade as one document, assembled once from bytes39// that are already in the binary.40func stylesheet() []byte {41 sheetOnce.Do(func() {42 var out bytes.Buffer43 for _, name := range stylesheets {44 body, err := fs.ReadFile(files, name)45 if err != nil {46 // Both files are in this package and in the binary; a name47 // that will not read is a build mistake, and skipping it48 // loses styling rather than the page.49 continue50 }51 out.WriteString("/* " + name + " */\n")52 out.Write(body)53 out.WriteString("\n")54 }55 sheet = out.Bytes()56 })57 return sheet58}