render

package
v0.0.0-...-88ae880 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(a, b int) int

Add returns the sum of two integers.

func CreateTemplateCache

func CreateTemplateCache() (map[string]*template.Template, error)

CreateTemplateCache creates a map of pre-parsed templates by parsing all the page templates and their corresponding layout templates. It returns a map of template names to their corresponding *template.Template pointers. It also returns an error if any error occurs while parsing the templates.

func DefaultData

func DefaultData(td *models.TemplateData, r *http.Request) *models.TemplateData

DefaultData populates the default data for templates. It takes a pointer to a TemplateData struct and a pointer to an http.Request struct. It returns a pointer to a TemplateData struct.

func FormatDate

func FormatDate(t time.Time, f string) string

FormatDate formats a given time.Time object to a string using the provided format string. The format string should be in the same format as the standard library's time package.

func HumanDate

func HumanDate(t time.Time) string

HumanDate takes a time.Time object and returns a string representation of the date in the format "2006-01-02".

func Iterate

func Iterate(count int) []int

Iterate generates a slice of integers from 0 to count-1.

func NewRenderer

func NewRenderer(a *config.AppConfig)

NewRenderer creates a new renderer with the given AppConfig.

func Template

func Template(w http.ResponseWriter, r *http.Request, tmpl string, td *models.TemplateData) error

Template executes a given template with the provided TemplateData and writes the output to the http.ResponseWriter. If app.UseCache is true, it uses the template cache from app.TemplateCache, otherwise it creates a new cache using CreateTemplateCache(). It returns an error if the template cannot be found in the cache or if there is an error writing the template to the response writer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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