Documentation ¶
Overview ¶
Package templates provides types, template data and a render function for gohtml templates.
Index ¶
- Constants
- Variables
- func RenderEmail(name string, data any) string
- type AboutData
- type AdminData
- type Backup
- type CookbookFeature
- type CookbookView
- type Data
- type EmailData
- type EmailTemplate
- type FunctionsData
- type Pagination
- type PaginationHtmx
- type PaginationSearch
- type RegisterData
- type ReportsData
- type SearchbarData
- type SettingsData
- type ShareData
- type ViewRecipeData
Constants ¶
const ( ResultsPerPage = 15 ResultsPerPageStr = "15" )
ResultsPerPage is the number of results to display per pagination page.
Variables ¶
var ErrorTokenExpired = Data{
Title: "Token Expired",
Content: `The token associated with the URL expired.
The problem has been forwarded to our team automatically. We will look into it and come
back to you. We apologise for this inconvenience.`,
}
ErrorTokenExpired encapsulates the information displayed to the user when a token is expired.
Functions ¶
func RenderEmail ¶
RenderEmail is a wrapper for template.ExecuteTemplate on email templates.
Types ¶
type AboutData ¶
type AboutData struct { IsCheckUpdate bool IsUpdateAvailable bool LastCheckedUpdateAt time.Time LastUpdatedAt time.Time Version semver.Version }
AboutData holds general application data.
func NewAboutData ¶ added in v1.1.0
func NewAboutData() AboutData
NewAboutData creates a new instance of AboutData.
type CookbookFeature ¶
type CookbookFeature struct { Cookbooks []models.Cookbook Cookbook CookbookView MakeCookbook func(index int64, cookbook models.Cookbook, page uint64) CookbookView ViewMode models.ViewMode }
CookbookFeature is the data to pass related to the cookbook feature.
type CookbookView ¶ added in v1.1.0
type CookbookView struct { ID int64 Image uuid.UUID IsImageExists bool NumRecipes int64 Recipes models.Recipes PageNumber uint64 PageItemID int64 Title string }
CookbookView holds data related to viewing a cookbook.
func MakeCookbookView ¶ added in v1.1.0
func MakeCookbookView(c models.Cookbook, index int64, page uint64) CookbookView
MakeCookbookView creates a templates.CookbookView from the Cookbook. The index is the position of the cookbook in the list of cookbooks presented to the user.
type Data ¶
type Data struct { IsAdmin bool // IsAdmin indicates whether the user is an administration. IsAuthenticated bool // IsAuthenticated indicates whether the user is authenticated. IsAutologin bool // IsAutologin indicates whether the user enabled autologin. IsDemo bool // IsDemo indicates whether running instance is the demo version. IsNoSignups bool // IsNoSignups indicates whether account registrations are disabled. IsHxRequest bool // IsHxRequest indicates whether the request is an HX one. It is used for oop swaps. IsToastWSVisible bool // IsToastWSVisible indicates whether to display the notification for websocket tasks. Title string // Title is the text inserted <title> tag's text. Content string // Content is text to insert into the template. About AboutData Admin AdminData CookbookFeature CookbookFeature Functions FunctionsData[int64] Pagination Pagination Recipes models.Recipes Reports ReportsData Searchbar SearchbarData Settings SettingsData View *ViewRecipeData }
Data holds data to pass on to the templates.
type EmailData ¶
type EmailData struct { Text string // Text is the text for the email. Token string // Token is used to store JWT tokens. UserName string // UserName is the name of the user. URL string // URL is the url of the website. }
EmailData holds data for email templates.
type EmailTemplate ¶
type EmailTemplate string
EmailTemplate represents the name of a .mjml email template.
const ( EmailErrorAdmin EmailTemplate = "error-admin.mjml" EmailForgotPassword EmailTemplate = "forgot-password.mjml" EmailIntro EmailTemplate = "intro.mjml" )
These constants associate an EmailTemplate with its MJML file.
func (EmailTemplate) String ¶
func (e EmailTemplate) String() string
String represents the email template as a string, being the file name.
func (EmailTemplate) Subject ¶
func (e EmailTemplate) Subject() string
Subject returns the subject of the email according to the type of email being sent.
type FunctionsData ¶
type FunctionsData[T int64 | uint64] struct { CutString func(s string, numCharacters int) string IsImageExists func(u uuid.UUID) bool IsUUIDValid func(u uuid.UUID) bool MulAll func(vals ...T) T }
FunctionsData provides functions for use in the templates.
func NewFunctionsData ¶
func NewFunctionsData[T int64 | uint64]() FunctionsData[T]
NewFunctionsData initializes a new FunctionsData.
type Pagination ¶
type Pagination struct {
Left, Middle, Right []uint64
Prev, Selected, Next uint64
NumPages, NumResults uint64
ResultsPerPage uint64
Functions FunctionsData[uint64]
IsHidden bool
Htmx PaginationHtmx
Search PaginationSearch
URL string
URLQueries string
}
Pagination holds data related to pagination.
func NewPagination ¶
func NewPagination(page, numPages, numResults uint64, resultsPerPage uint64, url, queries string, htmx PaginationHtmx) Pagination
NewPagination initializes a pagination struct of n pages.
type PaginationHtmx ¶ added in v1.1.0
PaginationHtmx holds data related to htmx for pagination.
type PaginationSearch ¶ added in v1.1.0
type PaginationSearch struct {
CurrentPage uint64
}
PaginationSearch holds search data for the pagination.
type RegisterData ¶
RegisterData is the data to pass on to the user registration template.
type ReportsData ¶ added in v1.1.0
ReportsData holds data related to reports.
type SearchbarData ¶ added in v1.1.0
SearchbarData holds data related to the searchbar.
type SettingsData ¶
type SettingsData struct { Backups []Backup Config app.ConfigFile MeasurementSystems []units.System UserSettings models.UserSettings }
SettingsData holds template data related to the user settings.
type ViewRecipeData ¶
type ViewRecipeData struct { Categories []string FormattedTimes formattedTimes ID int64 Inc func(n int) int IsImagesExist []bool IsURL bool IsVideoExist []bool Keywords []string Recipe *models.Recipe }
ViewRecipeData holds template data related to viewing a recipe.
func NewViewRecipeData ¶
func NewViewRecipeData(id int64, recipe *models.Recipe, categories, keywords []string, isFromHost, isShared bool) *ViewRecipeData
NewViewRecipeData creates and populates a new ViewRecipeData.