Documentation ¶
Index ¶
- Constants
- Variables
- func FormatWeekRelative(start time.Time) string
- func FormatWeekRelativeTo(start, now time.Time) string
- func GetRequesterIP(c *structs.Config, r *http.Request) (net.IP, error)
- func IsoWeekToDate(year, week int, weekday time.Weekday) (time.Time, error)
- func MostRecentMonday(d time.Time) time.Time
- func ParseIsoWeek(isoyear, isoweek, isoweekday string) (year int, week int, weekday time.Weekday, err error)
- func PrefixURL(url, p string) string
- func RenderTemplate(w http.ResponseWriter, context structs.PageContext, data interface{}, ...) error
- func StartOfDayOn(date time.Time) time.Time
- func StripHTML(htmls string) string
- type StartOffset
Constants ¶
const TemplatePrefix = "views"
TemplatePrefix is the constant containing the filepath prefix for templates.
Variables ¶
var BaseTemplates = []string{
"partials/header.tmpl",
"partials/footer.tmpl",
"elements/navbar.tmpl",
"partials/base.tmpl",
}
BaseTemplates is the array of 'base' templates used in each template render.
var StartHour = 6
StartHour is the hour of the day (local time) at which the scheduled day begins.
Functions ¶
func FormatWeekRelative ¶
FormatWeekRelative pretty-prints the name of a week starting on start, relative to today. start must be a Monday.
func FormatWeekRelativeTo ¶
FormatWeekRelativeTo pretty-prints the name of the current week of start, relative to the current week of now.
func IsoWeekToDate ¶
IsoWeekToDate interprets year, week, and weekday strings as an ISO weekday. The time is set to local midnight.
func MostRecentMonday ¶
MostRecentMonday returns the most recent Monday before d. The resulting date has the same time as d.
func ParseIsoWeek ¶
func ParseIsoWeek(isoyear, isoweek, isoweekday string) (year int, week int, weekday time.Weekday, err error)
ParseIsoWeek parses an ISO weekday from year, week, and weekday strings. It performs bounds checking. weekday must be an integer from 1 (Monday) to 7 (Sunday).
func PrefixURL ¶
PrefixURL prefixes a URL url with prefix p. If url begins with a single slash, it is treated as relative and prefixed with prefix. If p does not begin with a slash and end in zero slashes, it is changed to do so.
func RenderTemplate ¶
func RenderTemplate(w http.ResponseWriter, context structs.PageContext, data interface{}, mainTmpl string, addTmpls ...string) error
RenderTemplate renders a 2016site template on the ResponseWriter w.
This function automatically adds in the 2016site base templates, performs error handling, and builds a global context.
The PageContext context gives the context for the page to be rendered, sent to the template as PageContext. The interface{} data gives the data to be sent to the template as PageData.
The string mainTmpl gives the name, relative to views, of the main template to render. The variadic argument addTmpls names any additional templates mainTmpl depends on.
RenderTemplate returns any error that occurred when rendering the template.
func StartOfDayOn ¶
StartOfDayOn gets the schedule start-of-day on a given date. This is in terms of StartHour.
Types ¶
type StartOffset ¶
type StartOffset int
StartOffset is the type of offsets from the start hour of a schedule.
func HourToStartOffset ¶
func HourToStartOffset(hour int) (StartOffset, error)
HourToStartOffset takes an hour (0-23) and gives the number of hours elapsed since the last day start. It returns an error if the hour is invalid.
func (StartOffset) ToHour ¶
func (h StartOffset) ToHour() (int, error)
ToHour takes a number of hours h since the last day start (0-23) and gives the actual hour. It returns an error if the hour is invalid.
func (StartOffset) Valid ¶
func (h StartOffset) Valid() bool
Valid returns whether a StartOffset is within the 0-23 range required for it to index a schedule hour.