Create a Theme - aeridya/core GitHub Wiki
Creating a Theme for Aeridya
All Themes need to satisfy the following interface:
type themer interface {
Init(options ...theme.Option) error
Serve(resp *core.Response)
Error(resp *core.Response)
}
func Init(options ...theme.Option) error
This function is the initialization function for the theme that is used. Init(...)
should be called by the application on start before the Aeridya Server is running. This function should also register the theme with Aeridya by using the theme.Register(themer)
function.
Breakdown of theme.Option
The Init(...)
function accepts the data type of theme.Option
which is a variadic way of passing in data to the theme. This allows for each theme to be customizable by every user depending on the items that can be changed per theme. The theme.Option
is simply defined as the following:
type Option func()
This allows users to pass in as many options as they want to the theme on Init(...)
or optionally none.
Serve(resp *core.Response)
The Serve function in the theme is called on every connection and is meant to route the connection to the appropriate page. The Theme is responsible for maintaining how Pages are stored, and this function routes the connection to a URL match that is recognized in the Theme. If there is any error, it can be saved to the *core.Response
and processed via the Error()
function (see below).
Error(resp *core.Response)
The Error function only runs when an error is experienced via the Serve()
function. It is meant to display a themed Error page when it occurs.
theme.Theme
to help create a Theme
Using The Aeridya Theme package contains a Theme
struct that can be embedded into your own theme. This contains helper functions for Theme operations.
Current functions it includes:
ParseOpts(opts []theme.Option)
-- Used for running alltheme.Option
functions