templates

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package templates provides types, template data and a render function for gohtml templates.

Index

Constants

View Source
const (
	ResultsPerPage    = 15
	ResultsPerPageStr = "15"
)

ResultsPerPage is the number of results to display per pagination page.

Variables

View Source
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

func RenderEmail(name string, data any) string

RenderEmail is a wrapper for template.ExecuteTemplate on email templates.

Types

type AboutData

type AboutData struct {
	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 AdminData added in v1.1.0

type AdminData struct {
	Users []models.User
}

AdminData holds data for the admin page.

type Backup added in v1.1.0

type Backup struct {
	Display string
	Value   string
}

Backup holds data related to backups.

type CookbookFeature

type CookbookFeature struct {
	Cookbooks    []models.Cookbook
	Cookbook     CookbookView
	MakeCookbook func(index int64, cookbook models.Cookbook, page uint64) CookbookView
	ShareData    ShareData
	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
	IsUUIDValid 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"
	EmailRequestWebsite EmailTemplate = "request-website.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
	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

type PaginationHtmx struct {
	IsSwap bool
	Target string
}

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

type RegisterData struct {
	Email           string
	PasswordConfirm string
}

RegisterData is the data to pass on to the user registration template.

type ReportsData added in v1.1.0

type ReportsData struct {
	CurrentReport []models.ReportLog
	Imports       []models.Report
	Sort          string
}

ReportsData holds data related to reports.

type SearchbarData added in v1.1.0

type SearchbarData struct {
	Mode string
	Sort string
	Term string
}

SearchbarData holds data related to the searchbar.

type SettingsData

type SettingsData struct {
	Backups            []Backup
	MeasurementSystems []units.System
	UserSettings       models.UserSettings
}

SettingsData holds template data related to the user settings.

type ShareData

type ShareData struct {
	IsFromHost bool
	IsShared   bool
}

ShareData holds information on the entity being shared.

type ViewRecipeData

type ViewRecipeData struct {
	Categories     []string
	FormattedTimes formattedTimes
	ID             int64
	Inc            func(n int) int
	IsURL          bool
	IsUUIDValid    bool
	Recipe         *models.Recipe
	Share          ShareData
}

ViewRecipeData holds template data related to viewing a recipe.

func NewViewRecipeData

func NewViewRecipeData(id int64, recipe *models.Recipe, isFromHost, isShared bool) *ViewRecipeData

NewViewRecipeData creates and populates a new ViewRecipeData.

Jump to

Keyboard shortcuts

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