feature

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: Apache-2.0 Imports: 27 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAllTypedFeatures added in v0.2.0

func FindAllTypedFeatures[T interface{}](haystack Features) (found []T)

func FindTypedFeatureByTag added in v0.2.0

func FindTypedFeatureByTag[T interface{}](needle Tag, haystack Features) (found T)

Types

type ApplyMiddleware added in v0.1.0

type ApplyMiddleware interface {
	Apply(s System) (err error)
}

type Buildable

type Buildable interface {
	Builder

	// MakeEnvKey returns name with EnvPrefix (SCREAMING_SNAKE formatted)
	MakeEnvKey(name string) (key string)

	// MakeEnvKeys returns name with EnvPrefix (SCREAMING_SNAKE formatted)
	MakeEnvKeys(names ...string) (key []string)
}

type Builder

type Builder interface {
	SiteTag(key string) Builder
	SiteName(name string) Builder
	SiteTagLine(title string) Builder
	SiteLanguageMode(mode lang.Mode) Builder
	SiteCopyrightName(name string) Builder
	SiteCopyrightNotice(notice string) Builder
	SiteDefaultLanguage(tag language.Tag) Builder
	SiteSupportedLanguages(tags ...language.Tag) Builder
	SiteLanguageDisplayNames(names map[language.Tag]string) Builder

	// Set a custom context key with value
	Set(key string, value interface{}) Builder

	// AddHtmlHeadTag adds a custom (singleton) HTML tag to the <head> section
	// of the page output, example meta tag:
	//   AddHtmlHeadTag("meta",map[string]string{"name":"og:thing","content":"stuff"})
	AddHtmlHeadTag(name string, attr map[string]string) Builder

	// AddDomains restricts inbound requests to only the domain names given
	AddDomains(domains ...string) Builder

	// AddFeatureNotes appends bullet-pointed notes to the CLI App's main
	// description field
	AddFeatureNotes(tag Tag, notes ...string) Builder

	// AddFlags adds custom command line flags
	AddFlags(flags ...cli.Flag) Builder

	// AddCommands adds custom command line commands
	AddCommands(commands ...*cli.Command) Builder

	// AddConsole adds custom command line go-curses consoles (ctk.Window)
	AddConsole(c Console) Builder

	// AddFeature includes the given feature within the built Enjin
	AddFeature(f Feature) Builder

	// AddRouteProcessor adds the given route processor to the Enjin route
	// processing middleware
	AddRouteProcessor(route string, processor ReqProcessFn) Builder

	// AddOutputTranslator adds the given output filter (for the given mime type)
	AddOutputTranslator(mime string, filter TranslateOutputFn) Builder

	// AddModifyHeadersFn adds the given headers.ModifyHeadersFn function to the
	// default headers enjin middleware layer
	AddModifyHeadersFn(fn headers.ModifyHeadersFn) Builder

	AddNotifyHook(name string, hook NotifyHook) Builder

	// AddPageFromString is a convenience wrapper around AddPage
	AddPageFromString(path, raw string) Builder

	// SetStatusPage overrides specific HTTP error pages, ie: 404
	SetStatusPage(status int, path string) Builder

	// AddTheme includes the given theme within the built Enjin
	AddTheme(t *theme.Theme) Builder

	// SetTheme configures the default theme
	SetTheme(name string) Builder

	// HotReload enables or disables hot-reloading theme templates and content files
	HotReload(enabled bool) Builder

	// SetPublicAccess specifies the list of actions unauthorized visitors have
	//
	// Note: not specifying any public access results in no public access given
	SetPublicAccess(actions ...userbase.Action) Builder

	// AddUserAction adds the given actions to the overall known list of
	// registered user actions across all features
	AddUserAction(actions ...userbase.Action) Builder

	// Build constructs an Enjin Runner from the Builder configuration
	Build() Runner
}

type CConsole

type CConsole struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*CConsole) Build

func (c *CConsole) Build(b Buildable) (err error)

func (*CConsole) Depends

func (c *CConsole) Depends() (deps Tags)

func (*CConsole) Init

func (c *CConsole) Init(this interface{})

func (*CConsole) Make

func (c *CConsole) Make() Console

func (*CConsole) Self

func (c *CConsole) Self() (self Console)

func (*CConsole) Tag

func (c *CConsole) Tag() (tag Tag)

func (*CConsole) This

func (c *CConsole) This() (this interface{})

type CEnjinBlock

type CEnjinBlock struct {
	CEnjinFeature
}

type CEnjinFeature

type CEnjinFeature struct {
	CFeature
}

func (*CEnjinFeature) NjnCheckClass

func (f *CEnjinFeature) NjnCheckClass(tagClass NjnClass) (allow bool)

func (*CEnjinFeature) NjnCheckTag

func (f *CEnjinFeature) NjnCheckTag(tagName string) (allow bool)

func (*CEnjinFeature) NjnClassAllowed

func (f *CEnjinFeature) NjnClassAllowed() (allowed NjnClass, ok bool)

func (*CEnjinFeature) NjnTagsAllowed

func (f *CEnjinFeature) NjnTagsAllowed() (allowed []string, ok bool)

func (*CEnjinFeature) NjnTagsDenied

func (f *CEnjinFeature) NjnTagsDenied() (denied []string, ok bool)

type CEnjinField

type CEnjinField struct {
	CEnjinFeature
}

type CFeature

type CFeature struct {
	FeatureTag Tag

	Enjin Internals

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*CFeature) Build

func (f *CFeature) Build(b Buildable) (err error)

func (*CFeature) CloneBaseFeature added in v0.2.5

func (f *CFeature) CloneBaseFeature() (cloned CFeature)

func (*CFeature) Depends

func (f *CFeature) Depends() (deps Tags)

func (*CFeature) Init

func (f *CFeature) Init(this interface{})

func (*CFeature) Make

func (f *CFeature) Make() Feature

func (*CFeature) Self

func (f *CFeature) Self() (self Feature)

func (*CFeature) Setup

func (f *CFeature) Setup(enjin Internals)

func (*CFeature) Shutdown

func (f *CFeature) Shutdown()

func (*CFeature) Startup

func (f *CFeature) Startup(ctx *cli.Context) (err error)

func (*CFeature) Tag

func (f *CFeature) Tag() (tag Tag)

func (*CFeature) This

func (f *CFeature) This() (this interface{})

type CanSetupInternals

type CanSetupInternals interface {
	Setup(enjin Internals)
}

type Console

type Console interface {
	Tag() (tag Tag)
	Init(this interface{})
	This() (this interface{})
	Self() (self Console)
	Build(c Buildable) (err error)
	Depends() (deps Tags)
}

type ContentSecurityPolicyModifier

type ContentSecurityPolicyModifier interface {
	ModifyContentSecurityPolicy(policy csp.Policy, r *http.Request) (modified csp.Policy)
}

type DataRestrictionHandler

type DataRestrictionHandler interface {
	RestrictServeData(data []byte, mime string, w http.ResponseWriter, r *http.Request) (modReq *http.Request, allow bool)
}

type Database

type Database interface {
	Feature

	// ListDB returns a sorted list of connected db tags for use with DB and
	// MustDB
	ListDB() (tags []string)

	// DB returns the database connection or an error
	DB(tag string) (db interface{}, err error)

	// MustDB returns the database connection or panics on error
	MustDB(tag string) (db interface{})
}

type EmailProvider added in v0.1.0

type EmailProvider interface {
	NewEmail(basename string, bodyCtx beContext.Context) (message *gomail.Message, err error)
	MakeEmailBody(path string, ctx beContext.Context) (matter beContext.Context, body string, err error)
}

type EmailSender added in v0.1.0

type EmailSender interface {
	HasEmailAccount(account string) (present bool)
	SendEmail(account string, message *gomail.Message) (err error)
}

type EnjinBlock

type EnjinBlock interface {
	EnjinFeature

	NjnBlockType() (name string)

	ProcessBlock(re EnjinRenderer, blockType string, data map[string]interface{}) (html template.HTML, redirect string, err error)

	PrepareBlock(re EnjinRenderer, blockType string, data map[string]interface{}) (block map[string]interface{}, redirect string, err error)
	RenderPreparedBlock(re EnjinRenderer, block map[string]interface{}) (html template.HTML, err error)
}

type EnjinFeature

type EnjinFeature interface {
	Feature

	NjnClass() (tagClass NjnClass)
	NjnCheckTag(tagName string) (allow bool)
	NjnCheckClass(tagClass NjnClass) (allow bool)
	NjnTagsAllowed() (allowed []string, ok bool)
	NjnTagsDenied() (denied []string, ok bool)
	NjnClassAllowed() (allowed NjnClass, ok bool)
}

type EnjinField

type EnjinField interface {
	EnjinFeature

	NjnFieldNames() (tagNames []string)

	PrepareNjnData(re EnjinRenderer, tagName string, field map[string]interface{}) (data map[string]interface{}, err error)
}

type EnjinRenderer

type EnjinRenderer interface {
	RequestArgv() (reqArgv *argv.RequestArgv)
	RequestContext() (ctx context.Context)

	RenderNjnTemplate(tag string, data map[string]interface{}) (html template.HTML, err error)

	ProcessBlock(data map[string]interface{}) (html template.HTML, redirect string, err error)

	PrepareBlock(data map[string]interface{}) (block map[string]interface{}, redirect string, err error)
	RenderPreparedBlock(block map[string]interface{}) (html template.HTML, err error)

	PrepareGenericBlockData(contentData interface{}) (blockDataContent map[string]interface{}, err error)
	PrepareGenericBlock(typeName string, data map[string]interface{}) (preparedData map[string]interface{})

	GetData() (data interface{})
	GetBlockIndex() (index int)

	GetWithinAside() (within bool)
	SetWithinAside(within bool)

	GetCurrentDepth() (depth int)
	IncCurrentDepth() (depth int)
	DecCurrentDepth() (depth int)

	GetHeadingCount() (count int)
	SetHeadingCount(count int)
	IncHeadingCount()

	GetHeadingLevel() (level int)
	SetHeadingLevel(level int)
	IncHeadingLevel()
	DecHeadingLevel()

	AddFootnote(blockIndex int, field map[string]interface{}) (index int)
	PrepareFootnotes(blockIndex int) (footnotes []map[string]interface{}, err error)

	ParseTypeName(data map[string]interface{}) (name string, ok bool)
	ParseFieldAndTypeName(data interface{}) (field map[string]interface{}, name string, ok bool)

	PrepareStringTags(text string) (data []interface{}, err error)
	WalkStringTags(doc *html.Node) (prepared []interface{})

	PrepareBlockHeader(content map[string]interface{}) (combined []interface{}, ok bool)
	PrepareBlockFooter(content map[string]interface{}) (combined []interface{}, ok bool)

	ParseBlockHeadingLevel(count, current int, blockData map[string]interface{}) (level, headingReset, headingLevel int)
	RenderBlockHeader(content map[string]interface{}) (html template.HTML, ok bool)
	RenderBlockFooter(content map[string]interface{}) (html template.HTML, ok bool)

	PrepareInlineFieldText(field map[string]interface{}) (combined []interface{}, err error)
	PrepareInlineFieldList(list []interface{}) (combined []interface{}, err error)
	PrepareInlineFields(fields []interface{}) (combined []interface{}, err error)
	PrepareInlineField(field map[string]interface{}) (prepared map[string]interface{}, err error)

	PrepareContainerFieldText(field map[string]interface{}) (fields []interface{}, err error)
	PrepareContainerFieldList(list []interface{}) (fields []interface{}, err error)
	PrepareContainerFields(fields []interface{}) (combined []map[string]interface{}, err error)
	PrepareContainerField(field map[string]interface{}) (prepared map[string]interface{}, err error)

	RenderInlineField(field map[string]interface{}) (combined []template.HTML, err error)
	RenderInlineFields(fields []interface{}) (combined []template.HTML, err error)
	RenderInlineFieldList(list []interface{}) (html template.HTML, err error)
	RenderInlineFieldText(field map[string]interface{}) (text template.HTML, err error)

	RenderContainerField(field map[string]interface{}) (combined []template.HTML, err error)
	RenderContainerFields(fields []interface{}) (combined []template.HTML, err error)
	RenderContainerFieldList(list []interface{}) (html template.HTML, err error)
	RenderContainerFieldText(field map[string]interface{}) (text template.HTML, err error)
}

type EnjinRunner

type EnjinRunner interface {
	Runner

	StartupString() (info string)

	Shutdown()

	Notify(tag string)
	NotifyF(tag, format string, argv ...interface{})
}

type EnjinSystem

type EnjinSystem interface {
	InlineFields() (field map[string]EnjinField)
	ContainerFields() (field map[string]EnjinField)
	InlineBlocks() (field map[string]EnjinBlock)
	ContainerBlocks() (field map[string]EnjinBlock)
	StringTags() (names []string)
	FindField(tagClass NjnClass, fieldType string) (field EnjinField, ok bool)
	FindBlock(tagClass NjnClass, blockType string) (block EnjinBlock, ok bool)
}

type Feature

type Feature interface {
	Init(this interface{})
	Tag() (tag Tag)
	This() (this interface{})
	Self() (f Feature)
	Depends() (deps Tags)
	Build(c Buildable) (err error)
	Setup(enjin Internals)
	Startup(ctx *cli.Context) (err error)
	Shutdown()
}

type Features added in v0.2.0

type Features []Feature

func (Features) Find added in v0.2.0

func (f Features) Find(tag Tag) (found Feature)

type FileProvider added in v0.1.0

type FileProvider interface {
	FindFile(url string) (data []byte, mime string, err error)
}

type HeadersModifier

type HeadersModifier interface {
	ModifyHeaders(w http.ResponseWriter, r *http.Request)
}

type Internals

type Internals interface {
	Service
	signaling.SignalsSupport
	site.Enjin

	Self() (self interface{})

	Features() (features Features)
	Pages() (pages map[string]*page.Page)
	Theme() (theme string)
	Theming() (theming map[string]*theme.Theme)
	Headers() (headers []headers.ModifyHeadersFn)
	Domains() (domains []string)
	Consoles() (consoles map[Tag]Console)
	Processors() (processors map[string]ReqProcessFn)
	Translators() (translators map[string]TranslateOutputFn)
	Transformers() (transformers map[string]TransformOutputFn)
	Slugsums() (enabled bool)

	DB(tag string) (db interface{}, err error)
	MustDB(tag string) (db interface{})
	SpecificDB(fTag Tag, tag string) (db interface{}, err error)
	MustSpecificDB(fTag Tag, tag string) (db interface{})
}

type MakeConsole

type MakeConsole interface {
	Make() Console
}

type MakeFeature

type MakeFeature interface {
	Make() Feature
}
type MenuProvider interface {
	Feature

	GetMenus(tag language.Tag) (found map[string]menu.Menu)
}

type MiddlewareFn

type MiddlewareFn = func(next http.Handler) (this http.Handler)

type NjnClass

type NjnClass uint
const (
	InlineNjnClass NjnClass = iota
	ContainerNjnClass
	AnyNjnClass
)

func (NjnClass) String

func (nc NjnClass) String() string

type NotifyHook

type NotifyHook = func(format string, argv ...interface{})

type OutputTransformer

type OutputTransformer interface {
	CanTransform(mime string, r *http.Request) (ok bool)
	TransformOutput(mime string, input []byte) (output []byte)
}

type OutputTranslator

type OutputTranslator interface {
	CanTranslate(mime string) (ok bool)
	TranslateOutput(s Service, input []byte, inputMime string) (output []byte, mime string, err error)
}

type PageContextFilterFn

type PageContextFilterFn = func(ctx context.Context, r *http.Request) (modCtx context.Context)

type PageContextModifier

type PageContextModifier interface {
	FilterPageContext(themeCtx, pageCtx context.Context, r *http.Request) (themeOut context.Context)
}

type PageProvider

type PageProvider interface {
	FindRedirection(url string) (p *page.Page)
	FindTranslations(url string) (pages []*page.Page)
	FindPage(tag language.Tag, url string) (p *page.Page)
	LookupPrefixed(prefix string) (pages []*page.Page)
}

type PageRestrictionHandler

type PageRestrictionHandler interface {
	RestrictServePage(ctx context.Context, w http.ResponseWriter, r *http.Request) (modCtx context.Context, modReq *http.Request, allow bool)
}

type PageTypeProcessor

type PageTypeProcessor interface {
	ProcessRequestPageType(r *http.Request, p *page.Page) (pg *page.Page, redirect string, processed bool, err error)
}

type PermissionsPolicyModifier

type PermissionsPolicyModifier interface {
	ModifyPermissionsPolicy(policy permissions.Policy, r *http.Request) (modified permissions.Policy)
}

type Processor

type Processor interface {
	Process(s Service, next http.Handler, w http.ResponseWriter, r *http.Request)
}

type ReqProcessFn

type ReqProcessFn = func(s Service, w http.ResponseWriter, r *http.Request) (ok bool)

type RequestFilter

type RequestFilter interface {
	FilterRequest(r *http.Request) (err error)
}

type RequestFilterFn

type RequestFilterFn = func(r *http.Request) (err error)

type RequestModifier

type RequestModifier interface {
	ModifyRequest(w http.ResponseWriter, r *http.Request)
}

type RequestRewriter

type RequestRewriter interface {
	RewriteRequest(w http.ResponseWriter, r *http.Request) (modified *http.Request)
}

type RootInternals

type RootInternals interface {
	Internals

	SetupRootEnjin(ctx *cli.Context) (err error)
}

type Runner

type Runner interface {
	String() string
	Run(argv []string) (err error)
}

type ServePathFeature added in v0.1.0

type ServePathFeature interface {
	ServePath(path string, s System, w http.ResponseWriter, r *http.Request) (err error)
}

type Service

type Service interface {
	Prefix() (prefix string)
	Context() (ctx context.Context)
	GetTheme() (t *theme.Theme, err error)
	MustGetTheme() (t *theme.Theme)
	ThemeNames() (names []string)
	ServerName() (name string)
	ServiceInfo() (listen string, port int)

	ContentSecurityPolicy() (handler *csp.PolicyHandler)
	PermissionsPolicy() (handler *permissions.PolicyHandler)

	ServeRedirect(destination string, w http.ResponseWriter, r *http.Request)

	Serve204(w http.ResponseWriter, r *http.Request)
	Serve400(w http.ResponseWriter, r *http.Request)
	Serve401(w http.ResponseWriter, r *http.Request)
	ServeBasic401(w http.ResponseWriter, r *http.Request)
	Serve403(w http.ResponseWriter, r *http.Request)
	Serve404(w http.ResponseWriter, r *http.Request)
	Serve405(w http.ResponseWriter, r *http.Request)
	Serve500(w http.ResponseWriter, r *http.Request)

	ServeNotFound(w http.ResponseWriter, r *http.Request)
	ServeInternalServerError(w http.ResponseWriter, r *http.Request)

	ServeStatusPage(status int, w http.ResponseWriter, r *http.Request)
	ServePage(p *page.Page, w http.ResponseWriter, r *http.Request) (err error)
	ServePath(urlPath string, w http.ResponseWriter, r *http.Request) (err error)
	ServeJSON(v interface{}, w http.ResponseWriter, r *http.Request) (err error)
	ServeStatusJSON(status int, v interface{}, w http.ResponseWriter, r *http.Request) (err error)
	ServeData(data []byte, mime string, w http.ResponseWriter, r *http.Request)

	MatchQL(query string) (pages []*page.Page)
	MatchStubsQL(query string) (stubs []*fs.PageStub)
	SelectQL(query string) (selected map[string]interface{})

	CheckMatchQL(query string) (pages []*page.Page, err error)
	CheckMatchStubsQL(query string) (stubs []*fs.PageStub, err error)
	CheckSelectQL(query string) (selected map[string]interface{}, err error)

	FindPage(tag language.Tag, url string) (p *page.Page)
	FindFile(path string) (data []byte, mime string, err error)

	FindEmailAccount(account string) (emailSender EmailSender)
	SendEmail(account string, message *gomail.Message) (err error)

	GetPublicAccess() (actions userbase.Actions)
	FindAllUserActions() (list userbase.Actions)

	Notify(tag string)
	NotifyF(tag, format string, argv ...interface{})

	signaling.EmitterSupport
}

type System

type System interface {
	Service
	signaling.SignalsSupport

	Router() (router *chi.Mux)
}

type Tag

type Tag string

Tag is the primary identifier type for enjin Feature implementations

const NotImplemented Tag = "not-implemented"

func (Tag) Camel added in v0.1.0

func (t Tag) Camel() string

Camel returns the Tag as a CamelCased string

func (Tag) Kebab added in v0.1.0

func (t Tag) Kebab() string

Kebab returns the Tag as a kebab-cased string

func (Tag) ScreamingKebab added in v0.1.0

func (t Tag) ScreamingKebab() string

ScreamingKebab returns the Tag as a SCREAMING-KEBAB-CASED string

func (Tag) ScreamingSnake added in v0.1.0

func (t Tag) ScreamingSnake() string

ScreamingSnake returns the Tag as a SCREAMING_SNAKE_CASED string

func (Tag) Snake added in v0.1.0

func (t Tag) Snake() string

Snake returns the tag as a snake_cased string

func (Tag) String

func (t Tag) String() string

String returns the Tag as a string

type Tags

type Tags []Tag

func SortedFeatureTags added in v0.1.0

func SortedFeatureTags[V interface{}](data map[Tag]V) (tags Tags)

SortedFeatureTags returns a sortorder.Natural list of Tag keys

func StringsAsTags added in v0.1.0

func StringsAsTags(names []string) (tags Tags)

StringsAsTags returns a list of Tags based on the names given

func (Tags) Append

func (t Tags) Append(tag Tag) Tags

Append returns a list with the given tag appended

func (Tags) Has

func (t Tags) Has(tag Tag) bool

Has returns true if the list of Tags includes the given tag

func (Tags) Len

func (t Tags) Len() int

Len returns the number of tags

func (Tags) Strings added in v0.1.0

func (t Tags) Strings() (names []string)

Strings returns the list of Tags as a string slice

func (Tags) Unique added in v0.1.0

func (t Tags) Unique() (tags Tags)

Unique returns a list of unique tags, maintaining their original order

type TransformOutputFn

type TransformOutputFn = func(input []byte) (output []byte)

type TranslateOutputFn

type TranslateOutputFn = func(input []byte) (output []byte, mime string)

type UseMiddleware added in v0.1.0

type UseMiddleware interface {
	Use(s System) MiddlewareFn
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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