util

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_MODULE        = "ace"
	APP                   = "app"
	PAGE                  = "page"
	FRAGMENT              = "fragment"
	STYLE                 = "style"
	REDIRECT              = "redirect"
	PERMISSION            = "permission"
	RESPONSE              = "response"
	LIBRARY               = "library"
	DEFAULT_REDIRECT_CODE = 303
)
View Source
const (
	APP_FILE_NAME         = "app.star"
	APP_CONFIG_KEY        = "app"
	DEFAULT_HANDLER       = "handler"
	METHODS_DELIMITER     = ","
	CONFIG_LOCK_FILE_NAME = "config_gen.lock"
	BUILTIN_PLUGIN_SUFFIX = "in"
	STARLARK_FILE_SUFFIX  = ".star"
	INDEX_FILE            = "index.go.html"
	INDEX_GEN_FILE        = "index_gen.go.html"
	CLACE_GEN_FILE        = "clace_gen.go.html"
)

Variables

This section is empty.

Functions

func CreateBuiltin

func CreateBuiltin() starlark.StringDict

func FileServer

func FileServer(fsys *AppFS) http.Handler

FileServer returns an http.Handler for serving FS files. It provides a simplified implementation of http.FileServer which is used to aggressively cache files on the client since the file hash is in the filename.

Because FileServer is focused on small known path files, several features of http.FileServer have been removed including canonicalizing directories, defaulting index.html pages, precondition checks, & content range headers.

func FormatName

func FormatName(filename, hash string) string

FormatName returns a hash name that inserts hash before the filename's extension. If no extension exists on filename then the hash is appended. Returns blank string the original filename if hash is blank. Returns a blank string if the filename is blank.

func GetBoolAttr

func GetBoolAttr(s *starlarkstruct.Struct, key string) (bool, error)

func GetIntAttr

func GetIntAttr(s *starlarkstruct.Struct, key string) (int64, error)

func GetListStringAttr

func GetListStringAttr(s *starlarkstruct.Struct, key string, optional bool) ([]string, error)

func GetStringAttr

func GetStringAttr(s *starlarkstruct.Struct, key string) (string, error)

func ParseName

func ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

Types

type AppConfig

type AppConfig struct {
	Routing RouteConfig `json:"routing"`
	Htmx    HtmxConfig  `json:"htmx"`
}

func NewAppConfig

func NewAppConfig() *AppConfig

NewAppConfig creates an AppConfig with default values. This config is used when lock file is not present. The config file load order is

DefaultAppConfig -> StarlarkAppConfig

func NewCompatibleAppConfig

func NewCompatibleAppConfig() *AppConfig

NewCompatibleAppConfig creates an AppConfig focused on maintaining backward compatibility. This is used when the app is created from a source url where the source has the config lock file present. The configs are read in the order

CompatibleAppConfig -> LockFile -> StarlarkAppConfig

The goal is that if the application has a lock file, then all settings will attempt to be locked such that there should not be any change in behavior when the Clace version is updated. Removing the lock file will result in new config defaults getting applied, which can be done when the app developer wants to do an application refresh. Refresh will require additional testing to ensure that UI functionality is not changed..

type AppFS

type AppFS struct {
	Root string
	// contains filtered or unexported fields
}

AppFS is the implementation of app file system

func NewAppFS

func NewAppFS(dir string, fs fs.FS, isDev bool, systemConfig *utils.SystemConfig) *AppFS

func (*AppFS) ClearCache

func (f *AppFS) ClearCache()

func (*AppFS) Glob

func (f *AppFS) Glob(pattern string) ([]string, error)

func (*AppFS) HashName

func (f *AppFS) HashName(name string) string

HashName returns the hash name for a path, if exists. Otherwise returns the original path.

func (*AppFS) Open

func (f *AppFS) Open(name string) (fs.File, error)

Open returns a reference to the named file. If name is a hash name then the underlying file is used.

func (*AppFS) ParseFS

func (f *AppFS) ParseFS(funcMap template.FuncMap, patterns ...string) (*template.Template, error)

func (*AppFS) ParseName

func (f *AppFS) ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

func (*AppFS) ReadFile

func (f *AppFS) ReadFile(name string) ([]byte, error)

func (*AppFS) Remove

func (f *AppFS) Remove(name string) error

func (*AppFS) Stat

func (f *AppFS) Stat(name string) (fs.FileInfo, error)

func (*AppFS) Write

func (f *AppFS) Write(name string, bytes []byte) error

type HtmxConfig

type HtmxConfig struct {
	Version string `json:"version"`
}

type RouteConfig

type RouteConfig struct {
	TemplateLocations []string `json:"template_locations"`
	StaticDir         string   `json:"static_dir"`
	PushEvents        bool     `json:"push_events"`
}

type WritableFS

type WritableFS interface {
	Write(name string, bytes []byte) error
	Remove(name string) error
	Stat(name string) (fs.FileInfo, error)
}

WritableFS is the interface for the writable underlying file system used by AppFS

Jump to

Keyboard shortcuts

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