1
0
Fork 0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-06-01 09:36:06 +02:00

docs: Document strings functions

This commit is contained in:
Adnan Maolood 2021-05-17 12:25:51 -04:00
parent a1d220f13f
commit 73acb06c43

View File

@ -266,26 +266,26 @@ Templates have certain data and functions available to them.
All templates have the following functions available to them:
*site*
Returns site metadata
*path.Base* _path_
Returns the last element of _path_.
*path.Clean* _path_
Returns the shortest path name equivalent to _path_.
*path.Dir* _path_
Returns all but the last element of _path_, typically the path's directory.
*path.Ext* _path_
Returns the filename extension used by _path_.
*path.Join* _elem..._
Joins any number of path elements into a single path.
*reverse* _list_
Returns a reversed copy of the provided slice or array.
*path.Base* _path_
Returns the last element of path.
*path.Clean* _path_
Returns the shortest path name equivalent to path.
*path.Dir* _path_
Returns all but the last element of path, typically the path's directory.
*path.Ext* _path_
Returns the filename extension used by path.
*path.Join* _elem..._
Joins any number of path elements into a single path.
*safeCSS* _css_
Encapsulates known safe CSS content.
*safeHTML* _html_
Encapsulates a known safe HTML document fragment.
@ -293,15 +293,101 @@ All templates have the following functions available to them:
*safeHTMLAttr* _attr_
Encapsulates an HTML attribute from a trusted source.
*safeCSS* _css_
Encapsulates known safe CSS content.
*safeJS* _js_
Encapsulates a known safe JavaScript expression.
*safeURL* _url_
Encapsulates a known safe URL or URL substring.
*site*
Returns site metadata (see *SITE METADATA*).
*strings.Count* _string_, _substr_
Counts the number of non-overlapping instances of _substr_ in _string_.
If _substr_ is an empty string, Count returns 1 + the number of Unicode code
points in _string_.
*strings.HasPrefix* _string_, _prefix_
Reports whether _string_ begins with _prefix_.
*strings.HasSuffix* _string_, _suffix_
Reports whether _string_ ends with _suffix_.
*strings.Join* _elems_, _sep_
Concatenates the elements of its first argument to create a single string.
The separator string _sep_ is placed between elements in the resulting
string.
*strings.Repeat* _string_, _count_
Returns a new string consisting of _count_ copies of _string_.
It panics if _count_ is negative or if the result of
(len(_string_) \* _count_) overflows.
*strings.Replace* _string_, _old_, _new_, _n_
Returns a copy of _string_ with the first _n_ non-overlapping instances of
_old_ replaced by _new_. If _old_ is empty, it matches at the beginning of
the string and after each UTF-8 sequence, yielding up to k+1 replacements
for a k-rune string. If _n_ < 0, there is no limit on the number of
replacements.
*strings.ReplaceAll* _string_, _old_, _new_
Returns a copy of _string_ with all non-overlapping instances of _old_
replaced by _new_. If _old_ is empty, it matches at the beginning of the
string and after each UTF-8 sequence, yielding up to k+1 replacements for a
k-rune string.
*strings.Split* _string_, _sep_
Slices _string_ into all substrings separated by _sep_ and returns a slice
of the substrings between those separators.
If _string_ does not contain _sep_ and _sep_ is not empty, Split returns a
slice of length 1 whose only element is _string_.
If _sep_ is empty, Split splits after each UTF-8 sequence. If both _string_
and _sep_ are empty, Split returns an empty slice.
*strings.Title* _string_
Returns a copy of the string with all Unicode letters that begin words
mapped to their Unicode title case.
*BUG:* The rule Title uses for word boundaries does not handle Unicode
punctuation properly.
*strings.ToLower* _string_
Returns _string_ with all Unicode letters mapped to their lower case.
*strings.ToUpper* _string_
Returns _string_ with all Unicode letters mapped to their upper case.
*strings.Trim* _string_, _cutset_
Returns a slice of _string_ with all leading and trailing Unicode code
points contained in _cutset_ removed.
*strings.TrimLeft* _string_, _cutset_
Returns a slice of _string_ with all leading Unicode code points contained
in _cutset_ removed.
To remove a prefix, use *strings.TrimPrefix* instead.
*strings.TrimPrefix* _string_, _prefix_
Returns _string_ without the provided leading _prefix_ string. If _string_
doesn't start with _prefix_, it is returned unchanged.
*strings.TrimRight* _string_, _cutset_
Returns a slice of _string_ with all trailing Unicode code points contained
in _cutset_ removed.
To remove a suffix, use *strings.TrimSuffix* instead.
*strings.TrimSpace* _string_
Returns a slice of _string_ with all leading and trailing white space
removed, as defined by Unicode.
*strings.TrimSuffix* _string_, _suffix_
Returns _string_ without the provided trailing _suffix_ string. If _string_
doesn't end with _suffix_, it is returned unchanged.
## SITE METADATA
Site metadata contains the following data: