Documentation ¶
Index ¶
- Variables
- func CollapseParagraphs(s string) string
- func CombineFuncMaps(funcMaps ...template.FuncMap) template.FuncMap
- func DistanceOfTimeInWords(to, from time.Time) string
- func DistanceOfTimeInWordsFromNow(to time.Time) string
- func DownloadedImage(ctx context.Context, slug, imageURL string, width int) string
- func Figure(figCaption string, imgs ...*HTMLImage) template.HTML
- func FigureSingle(figCaption, src string) template.HTML
- func FigureSingleWithClass(figCaption, src, class string) template.HTML
- func FormatTime(t time.Time, format string) string
- func FormatTimeRFC3339UTC(t time.Time) string
- func FormatTimeSimpleDate(t time.Time) string
- func HTMLFuncMapToText(funcMap template.FuncMap) texttemplate.FuncMap
- func HTMLRender(elements ...HTMLElement) template.HTML
- func HTMLSafePassThrough(s string) template.HTML
- func Map(vals ...*mapVal) map[string]interface{}
- func MapVal(key string, val interface{}) *mapVal
- func MapValAdd(m map[string]interface{}, vals ...*mapVal) map[string]interface{}
- func QueryEscape(s string) string
- func RomanNumeral(num int) string
- func RoundToString(f float64) string
- func TimeIn(t time.Time, locationName string) time.Time
- func To2X(imagePath string) template.HTML
- type DownloadedImageContextContainer
- type DownloadedImageInfo
- type HTMLElement
- type HTMLImage
Constants ¶
This section is empty.
Variables ¶
var FuncMap = template.FuncMap{ "CollapseParagraphs": CollapseParagraphs, "DistanceOfTimeInWords": DistanceOfTimeInWords, "DistanceOfTimeInWordsFromNow": DistanceOfTimeInWordsFromNow, "DownloadedImage": DownloadedImage, "Figure": Figure, "FigureSingle": FigureSingle, "FigureSingleWithClass": FigureSingleWithClass, "FormatTime": FormatTime, "FormatTimeRFC3339UTC": FormatTimeRFC3339UTC, "FormatTimeSimpleDate": FormatTimeSimpleDate, "HTMLRender": HTMLRender, "HTMLSafePassThrough": HTMLSafePassThrough, "ImgSrcAndAlt": ImgSrcAndAlt, "ImgSrcAndAltAndClass": ImgSrcAndAltAndClass, "Map": Map, "MapVal": MapVal, "MapValAdd": MapValAdd, "QueryEscape": QueryEscape, "RomanNumeral": RomanNumeral, "RoundToString": RoundToString, "TimeIn": TimeIn, "To2X": To2X, }
FuncMap is a set of helper functions to make available in templates for the project.
Functions ¶
func CollapseParagraphs ¶
CollapseParagraphs strips paragraph tags out of rendered HTML. Note that it does not handle HTML with any attributes, so is targeted mainly for use with HTML generated from Markdown.
func CombineFuncMaps ¶
CombineFuncMaps combines a number of function maps into one. The combined version is a new function map so that none of the originals are tainted.
func DistanceOfTimeInWords ¶
DistanceOfTimeInWords returns a string describing the relative time passed between two times.
func DistanceOfTimeInWordsFromNow ¶
DistanceOfTimeInWordsFromNow returns a string describing the relative time passed between a time and the current moment.
func DownloadedImage ¶
DownloadedImage represents an image that's available remotely, and which will be downloaded and stored as the local target slug. This doesn't happen automatically though -- DownloadedImageContext must be called first to set a context container, and from there any downloaded image slugs and URLs can be extracted after all sources are rendered to be sent to mimage for processing.
func Figure ¶
Figure wraps a number of images into a figure and assigns them a caption as well as alt text.
func FigureSingle ¶
FigureSingle is a shortcut for creating a simple figure with a single image and with an alt that matches the caption.
func FigureSingleWithClass ¶
FigureSingleWithClass is a shortcut for creating a simple figure with a single image and with an alt that matches the caption, and with an HTML class..
func FormatTime ¶
FormatTime formats time according to the given format string.
func FormatTimeRFC3339UTC ¶
FormatTime formats time according to the given format string.
func FormatTimeSimpleDate ¶
FormatTimeSimpleDate formats time according to a relatively straightforward time format.
func HTMLFuncMapToText ¶
func HTMLFuncMapToText(funcMap template.FuncMap) texttemplate.FuncMap
HTMLFuncMapToText transforms an HTML func map to a text func map.
func HTMLRender ¶
func HTMLRender(elements ...HTMLElement) template.HTML
HTMLRender renders a series of mtemplate HTML elements.
func HTMLSafePassThrough ¶
HTMLSafePassThrough passes a string through to the final render. This is especially useful for code samples that contain Go template syntax which shouldn't be rendered.
func MapVal ¶
func MapVal(key string, val interface{}) *mapVal
MapVal generates a new map key/value for use with MapValAdd.
func MapValAdd ¶
MapValAdd is a convenience helper for adding a new key and value to a shallow copy of the given map and returning it.
func RomanNumeral ¶
func RoundToString ¶
RoundToString rounds a float to a presentation-friendly string.
Types ¶
type DownloadedImageContextContainer ¶
type DownloadedImageContextContainer struct {
Images []*DownloadedImageInfo
}
func DownloadedImageContext ¶
func DownloadedImageContext(ctx context.Context) (context.Context, *DownloadedImageContextContainer)
type DownloadedImageInfo ¶
type DownloadedImageInfo struct { Slug string URL *url.URL Width int // contains filtered or unexported fields }
func (*DownloadedImageInfo) OriginalExt ¶
func (p *DownloadedImageInfo) OriginalExt() string
type HTMLElement ¶
type HTMLElement interface {
// contains filtered or unexported methods
}
HTMLElement represents an HTML element that can be rendered.
type HTMLImage ¶
HTMLImage is a simple struct representing an HTML image to be rendered and some of the attributes it might have.
func ImgSrcAndAlt ¶
ImgSrcAndAlt is a shortcut for creating ImgSrcAndAlt.
func ImgSrcAndAltAndClass ¶
ImgSrcAndAltAndClass is a shortcut for creating ImgSrcAndAlt with a CSS class.