reusableapp

package
v0.0.0-...-9431910 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package reusableapp contains types and functions for writing reusable Gondola apps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppData

func AppData(a *app.App) interface{}

AppData returns Options.Data from the Options type, as passed to New.

func AppDataWithKey

func AppDataWithKey(a *app.App, key interface{}) interface{}

AppDataWithKey works similarly to AppData, but uses the provided key instead. Also, if the data is not found in the *app.App passed in as the first argument, its children apps are also searched. This allows reusable apps to retrieve their additional data in contexts where the reusable app pointer is not available. (e.g. in template plugins which are called from the parent app). See gondola/apps/users for an example of this usage.

func Data

func Data(ctx *app.Context) interface{}

Data is a shorthand for AppData(ctx.App())

Types

type App

type App struct {
	app.App

	Prefix                string
	ContainerTemplateName string
	// contains filtered or unexported fields
}

App allows implementing apps which can be directly included in a gondola/app.App. Use New to create an App.

func New

func New(opts Options) *App

New returns a new App. Any errors will result in a panic, Since this function should be called only during app initialization.

func (*App) Attach

func (a *App) Attach(parent *app.App)

Attach attaches a reusable app into its parent app.

func (*App) Data

func (a *App) Data() interface{}

Data returns the Data field from the Options struct, as passed in to New.

func (*App) SetName

func (a *App) SetName(name string)

type Options

type Options struct {
	// The reusable app name. It must not be empty.
	Name string
	// Relative path (to the source file calling New()) to the assets directory.
	// If empty, defaults to "assets". See also the AssetsData field.
	AssetsDir string
	// The baked data string representing the assets.
	//
	// Since reusable apps need to have their non-go files baked, this field
	// is provided as a conveniency in order to simplify reusable app initialization.
	// This field will take precedence over AssetsDir when the following conditions
	// are met:
	//
	// - AssetsData is non-empty
	// - the environment variable GONDOLA_APP_NO_BAKED_DATA doesn't contain the app name (as passed to New in Options)
	//
	// Otherwise, AssetsDir will be used.
	// This is useful while writing reusable apps, so you can start the development server with:
	//
	//	GONDOLA_APP_NO_VFS=MyApp
	//
	// And then your app will use the assets from the filesystem. Once you're ready to
	// commit the changes, you can regenerate the baked assets via gondola bake
	// (usually called from go generate) and users of your app will be able to just
	// go get it.
	AssetsData string
	// Relative path (to the source file calling New()) to the templates directory.
	// If empty, defaults to "tmpl". See TemplatesData and AssetsData.
	TemplatesDir string
	// Same as AssetsData, but for templates.
	TemplatesData string

	// Arbirtrary data than can be retrieved either with Data or AppData
	Data interface{}
	// This field can be used to provide a custom key to store the Data. Note that
	// if this field is non-nil, you must always use AppDataWithKey to retrieve your
	// additional data (Data, AppData, etc... will always return nil).
	DataKey interface{}
}

Options specify the available options when creating an App.

Jump to

Keyboard shortcuts

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