From fa7d37f0c818bf715394f833beb0402373c6956c Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sat, 13 Dec 2025 09:32:26 -0800 Subject: [PATCH] tpl: Add missing functions to init files Closes #14249 --- docs/data/docs.yaml | 468 +++++++++++++++++++++++++++------------- tpl/cast/init.go | 14 +- tpl/collections/init.go | 118 +++++----- tpl/compare/init.go | 20 +- tpl/crypto/init.go | 20 +- tpl/css/css.go | 19 +- tpl/data/init.go | 2 + tpl/debug/init.go | 28 +++ tpl/diagrams/init.go | 5 + tpl/fmt/init.go | 47 ++-- tpl/hash/hash.go | 12 +- tpl/images/init.go | 10 + tpl/js/init.go | 10 + tpl/lang/init.go | 37 ++-- tpl/math/init.go | 15 ++ tpl/os/init.go | 15 +- tpl/partials/init.go | 10 +- tpl/path/init.go | 35 ++- tpl/resources/init.go | 62 +++++- tpl/strings/init.go | 115 +++++----- tpl/templates/init.go | 16 +- tpl/time/init.go | 29 +-- tpl/transform/init.go | 25 +++ tpl/urls/init.go | 62 ++++-- 24 files changed, 819 insertions(+), 375 deletions(-) diff --git a/docs/data/docs.yaml b/docs/data/docs.yaml index 40b701d9b..75daaf6ac 100644 --- a/docs/data/docs.yaml +++ b/docs/data/docs.yaml @@ -1499,7 +1499,6 @@ config: tdewolff: css: inline: false - keepCSS2: false precision: 0 version: 0 html: @@ -1522,7 +1521,6 @@ config: keepNumbers: false precision: 0 svg: - inline: false keepComments: false precision: 0 xml: @@ -1891,7 +1889,7 @@ config: disable: false googleAnalytics: disable: false - respectDoNotTrack: false + respectDoNotTrack: true instagram: disable: false simple: false @@ -2174,9 +2172,12 @@ tpl: - '[a f]' D: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - seed + - 'n' + - hi + Description: 'D returns a sorted slice of unique random integers in the half-open interval\n[0, hi) using the provided seed value. The number of elements in the\nresulting slice is n or hi, whichever is less.\n\nIf n <= hi, it returns a sorted random sample of size n using J. S. Vitter’s\nMethod D for sequential random sampling.\n\nIf n > hi, it returns the full, sorted range [0, hi) of size hi.\n\nIf n == 0 or hi == 0, it returns an empty slice.\n\nReference:\n\n\tJ. S. Vitter, "An efficient algorithm for sequential random sampling," ACM Trans. Math. Softw., vol. 11, no. 1, pp. 37–57, 1985.\n\tSee also: https://getkerf.wordpress.com/2016/03/30/the-best-algorithm-no-one-knows-about/' + Examples: [] Delimit: Aliases: - delimit @@ -2327,9 +2328,10 @@ tpl: - bar=2&foo=1 Reverse: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - l + Description: Reverse creates a copy of the list l and reverses it. + Examples: [] Seq: Aliases: - seq @@ -2495,9 +2497,15 @@ tpl: Examples: [] LtCollate: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - collator + - first + - others + Description: |- + LtCollate returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4. + The provided collator will be used for string comparisons. + This is for internal use. + Examples: [] Ne: Aliases: - ne @@ -2509,9 +2517,10 @@ tpl: crypto: FNV32a: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - v + Description: 'FNV32a hashes v using fnv32a algorithm.\n{"newIn": "0.98.0" }' + Examples: [] HMAC: Aliases: - hmac @@ -2563,9 +2572,10 @@ tpl: Examples: [] Quoted: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - v + Description: Quoted returns a string that needs to be quoted in CSS. + Examples: [] Sass: Aliases: - toCSS @@ -2575,14 +2585,16 @@ tpl: Examples: [] TailwindCSS: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: TailwindCSS processes the given Resource with tailwindcss. + Examples: [] Unquoted: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - v + Description: Unquoted returns a string that does not need to be quoted in CSS. + Examples: [] data: GetCSV: Aliases: @@ -2627,35 +2639,44 @@ tpl: - '{\n "Hugo": "Rocks!"\n}' TestDeprecationErr: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - item + - alternative + Description: Internal template func, used in tests only. + Examples: [] TestDeprecationInfo: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - item + - alternative + Description: Internal template func, used in tests only. + Examples: [] TestDeprecationWarn: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - item + - alternative + Description: Internal template func, used in tests only. + Examples: [] Timer: Aliases: null - Args: null + Args: + - name Description: '' - Examples: null + Examples: [] VisualizeSpaces: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - val + Description: VisualizeSpaces returns a string with spaces replaced by a visible string. + Examples: [] diagrams: Goat: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - v + Description: Goat creates a new SVG diagram from input v. + Examples: [] encoding: Base64Decode: Aliases: @@ -2722,9 +2743,12 @@ tpl: - '' Errormf: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - m + - format + - args + Description: Errormf is experimental and subject to change at any time. + Examples: [] Print: Aliases: - print @@ -2782,9 +2806,12 @@ tpl: - '' Warnmf: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - m + - format + - args + Description: Warnmf is experimental and subject to change at any time. + Examples: [] hash: FNV32a: Aliases: null @@ -2906,9 +2933,10 @@ tpl: Examples: null Filter: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: Filter applies the given filters to the image given as the last element in args. + Examples: [] Gamma: Aliases: null Args: null @@ -2966,9 +2994,12 @@ tpl: Examples: null QR: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: |- + QR encodes the given text into a QR code using the specified options, + returning an image resource. + Examples: [] Saturation: Aliases: null Args: null @@ -3042,14 +3073,20 @@ tpl: Examples: [] Batch: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - id + Description: |- + Batch creates a new Batcher with the given ID. + Repeated calls with the same ID will return the same Batcher. + The ID will be used to name the root directory of the batch. + Forward slashes in the ID is allowed. + Examples: [] Build: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: Build processes the given Resource with ESBuild. + Examples: [] lang: FormatAccounting: Aliases: null @@ -3121,9 +3158,11 @@ tpl: - 512.50% Merge: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - p2 + - p1 + Description: Merge creates a union of pages from two languages. + Examples: [] Translate: Aliases: - i18n @@ -3204,8 +3243,8 @@ tpl: Counter: Aliases: null Args: null - Description: '' - Examples: null + Description: 'Counter increments and returns a global counter.\nThis was originally added to be used in tests where now.UnixNano did not\nhave the needed precision (especially on Windows).\nNote that given the parallel nature of Hugo, you cannot use this to get sequences of numbers,\nand the counter will reset on new builds.\n{"identifiers": ["now.UnixNano"] }' + Examples: [] Div: Aliases: - div @@ -3302,9 +3341,10 @@ tpl: - '8' Product: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - inputs + Description: Product returns the product of all numbers in inputs. Any slices in inputs are flattened. + Examples: [] Rand: Aliases: null Args: null @@ -3347,9 +3387,10 @@ tpl: - '1' Sum: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - inputs + Description: Sum returns the sum of all numbers in inputs. Any slices in inputs are flattened. + Examples: [] Tan: Aliases: null Args: @@ -3422,9 +3463,10 @@ tpl: - Hugo Rocks! Stat: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - i + Description: Stat returns the os.FileInfo structure describing file. + Examples: [] partials: Include: Aliases: @@ -3457,29 +3499,63 @@ tpl: path: Base: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - path + Description: |- + Base returns the last element of path. + Trailing slashes are removed before extracting the last element. + If the path is empty, Base returns ".". + If the path consists entirely of slashes, Base returns "/". + The input path is passed into filepath.ToSlash converting any Windows slashes + to forward slashes. + Examples: [] BaseName: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - path + Description: |- + BaseName returns the last element of path, removing the extension if present. + Trailing slashes are removed before extracting the last element. + If the path is empty, Base returns ".". + If the path consists entirely of slashes, Base returns "/". + The input path is passed into filepath.ToSlash converting any Windows slashes + to forward slashes. + Examples: [] Clean: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - path + Description: |- + Clean replaces the separators used with standard slashes and then + extraneous slashes are removed. + Examples: [] Dir: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - path + Description: |- + Dir returns all but the last element of path, typically the path's directory. + After dropping the final element using Split, the path is Cleaned and trailing + slashes are removed. + If the path is empty, Dir returns ".". + If the path consists entirely of slashes followed by non-slash bytes, Dir + returns a single slash. In any other case, the returned path does not end in a + slash. + The input path is passed into filepath.ToSlash converting any Windows slashes + to forward slashes. + Examples: [] Ext: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - path + Description: |- + Ext returns the file name extension used by path. + The extension is the suffix beginning at the final dot + in the final slash-separated element of path; + it is empty if there is no dot. + The input path is passed into filepath.ToSlash converting any Windows slashes + to forward slashes. + Examples: [] Join: Aliases: null Args: @@ -3539,29 +3615,41 @@ tpl: resources: Babel: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: 'Babel processes the given Resource with Babel.\nDeprecated: Moved to the js namespace in Hugo 0.128.0.' + Examples: [] ByType: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - typ + Description: ByType returns resources of a given resource type (e.g. "image"). + Examples: [] Concat: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - targetPathIn + - r + Description: |- + Concat concatenates a slice of Resource objects. These resources must + (currently) be of the same Media Type. + Examples: [] Copy: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - s + - r + Description: Copy copies r to the new targetPath in s. + Examples: [] ExecuteAsTemplate: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - ctx + - args + Description: |- + ExecuteAsTemplate creates a Resource from a Go template, parsed and executed with + the given data, and published to the relative target path. + Examples: [] Fingerprint: Aliases: - fingerprint @@ -3573,9 +3661,11 @@ tpl: Examples: [] FromString: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - targetPathIn + - contentIn + Description: FromString creates a Resource from a string published to the relative target path. + Examples: [] Get: Aliases: null Args: @@ -3597,9 +3687,26 @@ tpl: Examples: [] Match: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - pattern + Description: |- + Match gets all resources matching the given base path prefix, e.g + "*.png" will match all png files. The "*" does not match path delimiters (/), + so if you organize your resources in sub-folders, you need to be explicit about it, e.g.: + "images/*.png". To match any PNG image anywhere in the bundle you can do "**.png", and + to match all PNG images below the images folder, use "images/**.jpg". + + The matching is case insensitive. + + Match matches by using the files name with path relative to the file system root + with Unix style slashes (/) and no leading slash, e.g. "images/logo.png". + + See https://github.com/gobwas/glob for the full rules set. + + It looks for files in the assets file system. + + See Match for a more complete explanation about the rules used. + Examples: [] Minify: Aliases: - minify @@ -3611,19 +3718,22 @@ tpl: Examples: [] PostCSS: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: 'PostCSS processes the given Resource with PostCSS.\nDeprecated: Moved to the css namespace in Hugo 0.128.0.' + Examples: [] PostProcess: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - r + Description: PostProcess processes r after the build. + Examples: [] ToCSS: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - args + Description: 'ToCSS converts the given Resource to CSS. You can optional provide an Options object\nas second argument. As an option, you can e.g. specify e.g. the target path (string)\nfor the converted CSS resource.\nDeprecated: Moved to the css namespace in Hugo 0.128.0.' + Examples: [] safe: CSS: Aliases: @@ -3907,9 +4017,10 @@ tpl: - 'false' ContainsNonSpace: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - s + Description: 'ContainsNonSpace reports whether s contains any non-space characters as defined\nby Unicode''s White Space property,\n{"newIn": "0.111.0" }' + Examples: [] Count: Aliases: null Args: @@ -3937,9 +4048,15 @@ tpl: Examples: [] Diff: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - oldname + - old + - newname + - new + Description: |- + Diff returns an anchored diff of the two texts old and new in the “unified + diff” format. If old and new are identical, Diff returns an empty string. + Examples: [] FindRE: Aliases: - findRE @@ -4172,9 +4289,12 @@ tpl: - aabb TrimSpace: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - s + Description: |- + TrimSpace returns the given string, removing leading and trailing whitespace + as defined by Unicode. + Examples: [] TrimSuffix: Aliases: null Args: @@ -4203,9 +4323,10 @@ tpl: templates: Current: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - ctx + Description: Get information about the currently executing template. + Examples: [] Defer: Aliases: null Args: @@ -4232,9 +4353,9 @@ tpl: Note that this is the Unix-styled relative path including filename suffix, e.g. partials/header.html Examples: - - - '{{ if (templates.Exists "partials/header.html") }}Yes!{{ end }}' + - - '{{ if (templates.Exists "_partials/header.html") }}Yes!{{ end }}' - Yes! - - - '{{ if not (templates.Exists "partials/doesnotexist.html") }}No!{{ end }}' + - - '{{ if not (templates.Exists "_partials/doesnotexist.html") }}No!{{ end }}' - No! time: AsTime: @@ -4274,9 +4395,15 @@ tpl: - 'dateFormat: Wednesday, Jan 21, 2015' In: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - timeZoneName + - t + Description: |- + In returns the time t in the IANA time zone specified by timeZoneName. + If timeZoneName is "" or "UTC", the time is returned in UTC. + If timeZoneName is "Local", the time is returned in the system's local time zone. + Otherwise, timeZoneName must be a valid IANA location name (e.g., "Europe/Oslo"). + Examples: [] Now: Aliases: - now @@ -4294,9 +4421,10 @@ tpl: transform: CanHighlight: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - language + Description: CanHighlight returns whether the given code language is supported by the Chroma highlighter. + Examples: [] Emojify: Aliases: - emojify @@ -4324,9 +4452,14 @@ tpl: - Cathal Garvey & The Sunshine Band HTMLToMarkdown: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - ctx + - args + Description: |- + This was added in Hugo v0.151.0 and should be considered experimental for now. + We need to test this out in the wild for a while before committing to this API, + and there will eventually be more options here. + Examples: [] HTMLUnescape: Aliases: - htmlUnescape @@ -4357,9 +4490,11 @@ tpl: Examples: [] HighlightCodeBlock: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - ctx + - opts + Description: HighlightCodeBlock highlights a code block on the form received in the codeblock render hooks. + Examples: [] Markdownify: Aliases: - markdownify @@ -4381,9 +4516,12 @@ tpl: - Hello world, gophers! PortableText: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - v + Description: |- + PortableText converts the portable text in v to Markdown. + We may add more options in the future. + Examples: [] Remarshal: Aliases: null Args: @@ -4401,9 +4539,13 @@ tpl: - '{\n "title": "Hello World"\n}\n' ToMath: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - ctx + - args + Description: |- + ToMath converts a LaTeX string to math in the given format, default MathML. + This uses KaTeX to render the math, see https://katex.org/. + Examples: [] Unmarshal: Aliases: - unmarshal @@ -4472,9 +4614,29 @@ tpl: - a/b Parse: Aliases: null - Args: null - Description: '' - Examples: null + Args: + - rawurl + Description: |- + Parse parses rawurl into a URL structure. The rawurl may be relative or + absolute. + Examples: [] + PathEscape: + Aliases: null + Args: + - s + Description: |- + PathEscape returns the given string, applying percent-encoding to special + characters and reserved delimiters so it can be safely used as a segment + within a URL path. + Examples: [] + PathUnescape: + Aliases: null + Args: + - s + Description: |- + PathUnescape returns the given string, replacing all percent-encoded + sequences with the corresponding unescaped characters. + Examples: [] Ref: Aliases: - ref diff --git a/tpl/cast/init.go b/tpl/cast/init.go index 84211a00b..d3ee7279e 100644 --- a/tpl/cast/init.go +++ b/tpl/cast/init.go @@ -31,6 +31,13 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.ToFloat, + []string{"float"}, + [][2]string{ + {`{{ "1234" | float | printf "%T" }}`, `float64`}, + }, + ) + ns.AddMethodMapping(ctx.ToInt, []string{"int"}, [][2]string{ @@ -45,13 +52,6 @@ func init() { }, ) - ns.AddMethodMapping(ctx.ToFloat, - []string{"float"}, - [][2]string{ - {`{{ "1234" | float | printf "%T" }}`, `float64`}, - }, - ) - return ns } diff --git a/tpl/collections/init.go b/tpl/collections/init.go index f89651326..e29053f30 100644 --- a/tpl/collections/init.go +++ b/tpl/collections/init.go @@ -36,6 +36,11 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.Append, + []string{"append"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Apply, []string{"apply"}, [][2]string{}, @@ -48,11 +53,9 @@ func init() { }, ) - ns.AddMethodMapping(ctx.SymDiff, - []string{"symdiff"}, - [][2]string{ - {`{{ slice 1 2 3 | symdiff (slice 3 4) }}`, `[1 2 4]`}, - }, + ns.AddMethodMapping(ctx.D, + nil, + [][2]string{}, ) ns.AddMethodMapping(ctx.Delimit, @@ -72,11 +75,9 @@ func init() { [][2]string{}, ) - ns.AddMethodMapping(ctx.KeyVals, - []string{"keyVals"}, - [][2]string{ - {`{{ keyVals "key" "a" "b" }}`, `key: [a b]`}, - }, + ns.AddMethodMapping(ctx.Group, + []string{"group"}, + [][2]string{}, ) ns.AddMethodMapping(ctx.In, @@ -101,11 +102,43 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.KeyVals, + []string{"keyVals"}, + [][2]string{ + {`{{ keyVals "key" "a" "b" }}`, `key: [a b]`}, + }, + ) + ns.AddMethodMapping(ctx.Last, []string{"last"}, [][2]string{}, ) + ns.AddMethodMapping(ctx.Merge, + []string{"merge"}, + [][2]string{ + { + `{{ dict "title" "Hugo Rocks!" | collections.Merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") | sort }}`, + `[Yes, Hugo Rocks! Hugo Rocks!]`, + }, + { + `{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") | sort }}`, + `[Yes, Hugo Rocks! Hugo Rocks!]`, + }, + { + `{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") (dict "extra" "For reals!") | sort }}`, + `[Yes, Hugo Rocks! For reals! Hugo Rocks!]`, + }, + }, + ) + + ns.AddMethodMapping(ctx.NewScratch, + []string{"newScratch"}, + [][2]string{ + {`{{ $scratch := newScratch }}{{ $scratch.Add "b" 2 }}{{ $scratch.Add "b" 2 }}{{ $scratch.Get "b" }}`, `4`}, + }, + ) + ns.AddMethodMapping(ctx.Querify, []string{"querify"}, [][2]string{ @@ -124,56 +157,46 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Shuffle, - []string{"shuffle"}, + ns.AddMethodMapping(ctx.Reverse, + nil, [][2]string{}, ) - ns.AddMethodMapping(ctx.Slice, - []string{"slice"}, + ns.AddMethodMapping(ctx.Seq, + []string{"seq"}, [][2]string{ - {`{{ slice "B" "C" "A" | sort }}`, `[A B C]`}, + {`{{ seq 3 }}`, `[1 2 3]`}, }, ) - ns.AddMethodMapping(ctx.Sort, - []string{"sort"}, + ns.AddMethodMapping(ctx.Shuffle, + []string{"shuffle"}, [][2]string{}, ) - ns.AddMethodMapping(ctx.Union, - []string{"union"}, + ns.AddMethodMapping(ctx.Slice, + []string{"slice"}, [][2]string{ - {`{{ union (slice 1 2 3) (slice 3 4 5) }}`, `[1 2 3 4 5]`}, + {`{{ slice "B" "C" "A" | sort }}`, `[A B C]`}, }, ) - ns.AddMethodMapping(ctx.Where, - []string{"where"}, - [][2]string{}, - ) - - ns.AddMethodMapping(ctx.Append, - []string{"append"}, - [][2]string{}, - ) - - ns.AddMethodMapping(ctx.Group, - []string{"group"}, + ns.AddMethodMapping(ctx.Sort, + []string{"sort"}, [][2]string{}, ) - ns.AddMethodMapping(ctx.Seq, - []string{"seq"}, + ns.AddMethodMapping(ctx.SymDiff, + []string{"symdiff"}, [][2]string{ - {`{{ seq 3 }}`, `[1 2 3]`}, + {`{{ slice 1 2 3 | symdiff (slice 3 4) }}`, `[1 2 4]`}, }, ) - ns.AddMethodMapping(ctx.NewScratch, - []string{"newScratch"}, + ns.AddMethodMapping(ctx.Union, + []string{"union"}, [][2]string{ - {`{{ $scratch := newScratch }}{{ $scratch.Add "b" 2 }}{{ $scratch.Add "b" 2 }}{{ $scratch.Get "b" }}`, `4`}, + {`{{ union (slice 1 2 3) (slice 3 4 5) }}`, `[1 2 3 4 5]`}, }, ) @@ -184,22 +207,9 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Merge, - []string{"merge"}, - [][2]string{ - { - `{{ dict "title" "Hugo Rocks!" | collections.Merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") | sort }}`, - `[Yes, Hugo Rocks! Hugo Rocks!]`, - }, - { - `{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") | sort }}`, - `[Yes, Hugo Rocks! Hugo Rocks!]`, - }, - { - `{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") (dict "extra" "For reals!") | sort }}`, - `[Yes, Hugo Rocks! For reals! Hugo Rocks!]`, - }, - }, + ns.AddMethodMapping(ctx.Where, + []string{"where"}, + [][2]string{}, ) return ns diff --git a/tpl/compare/init.go b/tpl/compare/init.go index 4d789af3b..c6e325de5 100644 --- a/tpl/compare/init.go +++ b/tpl/compare/init.go @@ -37,6 +37,13 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.Conditional, + []string{"cond"}, + [][2]string{ + {`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`}, + }, + ) + ns.AddMethodMapping(ctx.Default, []string{"default"}, [][2]string{ @@ -74,16 +81,15 @@ func init() { [][2]string{}, ) - ns.AddMethodMapping(ctx.Ne, - []string{"ne"}, + // For internal use only. + ns.AddMethodMapping(ctx.LtCollate, + nil, [][2]string{}, ) - ns.AddMethodMapping(ctx.Conditional, - []string{"cond"}, - [][2]string{ - {`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`}, - }, + ns.AddMethodMapping(ctx.Ne, + []string{"ne"}, + [][2]string{}, ) return ns diff --git a/tpl/crypto/init.go b/tpl/crypto/init.go index 0527fba06..52f722a02 100644 --- a/tpl/crypto/init.go +++ b/tpl/crypto/init.go @@ -31,6 +31,19 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + // Deprecated. Use hash.FNV32a instead. + ns.AddMethodMapping(ctx.FNV32a, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.HMAC, + []string{"hmac"}, + [][2]string{ + {`{{ hmac "sha256" "Secret key" "Hello world, gophers!" }}`, `b6d11b6c53830b9d87036272ca9fe9d19306b8f9d8aa07b15da27d89e6e34f40`}, + }, + ) + ns.AddMethodMapping(ctx.MD5, []string{"md5"}, [][2]string{ @@ -53,13 +66,6 @@ func init() { }, ) - ns.AddMethodMapping(ctx.HMAC, - []string{"hmac"}, - [][2]string{ - {`{{ hmac "sha256" "Secret key" "Hello world, gophers!" }}`, `b6d11b6c53830b9d87036272ca9fe9d19306b8f9d8aa07b15da27d89e6e34f40`}, - }, - ) - return ns } diff --git a/tpl/css/css.go b/tpl/css/css.go index 199deda69..ba21c8997 100644 --- a/tpl/css/css.go +++ b/tpl/css/css.go @@ -162,13 +162,28 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.PostCSS, + []string{"postCSS"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Quoted, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Sass, []string{"toCSS"}, [][2]string{}, ) - ns.AddMethodMapping(ctx.PostCSS, - []string{"postCSS"}, + ns.AddMethodMapping(ctx.TailwindCSS, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Unquoted, + nil, [][2]string{}, ) diff --git a/tpl/data/init.go b/tpl/data/init.go index 507e0d43e..47656d398 100644 --- a/tpl/data/init.go +++ b/tpl/data/init.go @@ -31,11 +31,13 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + // Deprecated. Use resources.GetRemote instead. ns.AddMethodMapping(ctx.GetCSV, []string{"getCSV"}, [][2]string{}, ) + // Deprecated. Use resources.GetRemote instead. ns.AddMethodMapping(ctx.GetJSON, []string{"getJSON"}, [][2]string{}, diff --git a/tpl/debug/init.go b/tpl/debug/init.go index 1232a4166..3c789d8c8 100644 --- a/tpl/debug/init.go +++ b/tpl/debug/init.go @@ -40,6 +40,34 @@ func init() { }, ) + // For internal use only. Used in tests. + ns.AddMethodMapping(ctx.TestDeprecationErr, + nil, + [][2]string{}, + ) + + // For internal use only. Used in tests. + ns.AddMethodMapping(ctx.TestDeprecationInfo, + nil, + [][2]string{}, + ) + + // For internal use only. Used in tests. + ns.AddMethodMapping(ctx.TestDeprecationWarn, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Timer, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.VisualizeSpaces, + nil, + [][2]string{}, + ) + return ns } diff --git a/tpl/diagrams/init.go b/tpl/diagrams/init.go index 0cbec7e1b..e1fc5d18b 100644 --- a/tpl/diagrams/init.go +++ b/tpl/diagrams/init.go @@ -34,6 +34,11 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.Goat, + nil, + [][2]string{}, + ) + return ns } diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go index 701bd3b6a..0b0e71749 100644 --- a/tpl/fmt/init.go +++ b/tpl/fmt/init.go @@ -31,17 +31,30 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } - ns.AddMethodMapping(ctx.Print, - []string{"print"}, + ns.AddMethodMapping(ctx.Errorf, + []string{"errorf"}, [][2]string{ - {`{{ print "works!" }}`, `works!`}, + {`{{ errorf "%s." "failed" }}`, ``}, }, ) - ns.AddMethodMapping(ctx.Println, - []string{"println"}, + ns.AddMethodMapping(ctx.Erroridf, + []string{"erroridf"}, [][2]string{ - {`{{ println "works!" }}`, "works!\n"}, + {`{{ erroridf "my-err-id" "%s." "failed" }}`, ``}, + }, + ) + + // Experimental. Not documented. + ns.AddMethodMapping(ctx.Errormf, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Print, + []string{"print"}, + [][2]string{ + {`{{ print "works!" }}`, `works!`}, }, ) @@ -52,17 +65,17 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Errorf, - []string{"errorf"}, + ns.AddMethodMapping(ctx.Println, + []string{"println"}, [][2]string{ - {`{{ errorf "%s." "failed" }}`, ``}, + {`{{ println "works!" }}`, "works!\n"}, }, ) - ns.AddMethodMapping(ctx.Erroridf, - []string{"erroridf"}, + ns.AddMethodMapping(ctx.Warnf, + []string{"warnf"}, [][2]string{ - {`{{ erroridf "my-err-id" "%s." "failed" }}`, ``}, + {`{{ warnf "%s." "warning" }}`, ``}, }, ) @@ -73,12 +86,12 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Warnf, - []string{"warnf"}, - [][2]string{ - {`{{ warnf "%s." "warning" }}`, ``}, - }, + // Experimental. Not documented. + ns.AddMethodMapping(ctx.Warnmf, + nil, + [][2]string{}, ) + return ns } diff --git a/tpl/hash/hash.go b/tpl/hash/hash.go index 00df4e3cd..b82fc3679 100644 --- a/tpl/hash/hash.go +++ b/tpl/hash/hash.go @@ -64,17 +64,17 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } - ns.AddMethodMapping(ctx.XxHash, - []string{"xxhash"}, + ns.AddMethodMapping(ctx.FNV32a, + nil, [][2]string{ - {`{{ hash.XxHash "The quick brown fox jumps over the lazy dog" }}`, `0b242d361fda71bc`}, + {`{{ hash.FNV32a "Hugo Rocks!!" }}`, `1515779328`}, }, ) - ns.AddMethodMapping(ctx.FNV32a, - nil, + ns.AddMethodMapping(ctx.XxHash, + []string{"xxhash"}, [][2]string{ - {`{{ hash.FNV32a "Hugo Rocks!!" }}`, `1515779328`}, + {`{{ hash.XxHash "The quick brown fox jumps over the lazy dog" }}`, `0b242d361fda71bc`}, }, ) diff --git a/tpl/images/init.go b/tpl/images/init.go index a350d5b9d..7398dc9ed 100644 --- a/tpl/images/init.go +++ b/tpl/images/init.go @@ -36,6 +36,16 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.Filter, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.QR, + nil, + [][2]string{}, + ) + return ns } diff --git a/tpl/js/init.go b/tpl/js/init.go index 97e76c33d..54ae1d29a 100644 --- a/tpl/js/init.go +++ b/tpl/js/init.go @@ -39,6 +39,16 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.Batch, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Build, + nil, + [][2]string{}, + ) + return ns } diff --git a/tpl/lang/init.go b/tpl/lang/init.go index 0c07daa38..1b2db6a47 100644 --- a/tpl/lang/init.go +++ b/tpl/lang/init.go @@ -32,22 +32,10 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } - ns.AddMethodMapping(ctx.Translate, - []string{"i18n", "T"}, - [][2]string{}, - ) - - ns.AddMethodMapping(ctx.FormatNumber, - nil, - [][2]string{ - {`{{ 512.5032 | lang.FormatNumber 2 }}`, `512.50`}, - }, - ) - - ns.AddMethodMapping(ctx.FormatPercent, + ns.AddMethodMapping(ctx.FormatAccounting, nil, [][2]string{ - {`{{ 512.5032 | lang.FormatPercent 2 }}`, `512.50%`}, + {`{{ 512.5032 | lang.FormatAccounting 2 "NOK" }}`, `NOK512.50`}, }, ) @@ -58,10 +46,10 @@ func init() { }, ) - ns.AddMethodMapping(ctx.FormatAccounting, + ns.AddMethodMapping(ctx.FormatNumber, nil, [][2]string{ - {`{{ 512.5032 | lang.FormatAccounting 2 "NOK" }}`, `NOK512.50`}, + {`{{ 512.5032 | lang.FormatNumber 2 }}`, `512.50`}, }, ) @@ -77,6 +65,23 @@ func init() { }, ) + ns.AddMethodMapping(ctx.FormatPercent, + nil, + [][2]string{ + {`{{ 512.5032 | lang.FormatPercent 2 }}`, `512.50%`}, + }, + ) + + ns.AddMethodMapping(ctx.Merge, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Translate, + []string{"i18n", "T"}, + [][2]string{}, + ) + return ns } diff --git a/tpl/math/init.go b/tpl/math/init.go index e34c892f0..f7e954bdb 100644 --- a/tpl/math/init.go +++ b/tpl/math/init.go @@ -95,6 +95,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Counter, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Div, []string{"div"}, [][2]string{ @@ -172,6 +177,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Product, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Rand, nil, [][2]string{ @@ -207,6 +217,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Sum, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Tan, nil, [][2]string{ diff --git a/tpl/os/init.go b/tpl/os/init.go index d7afba16f..a60a095e7 100644 --- a/tpl/os/init.go +++ b/tpl/os/init.go @@ -31,6 +31,13 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.FileExists, + []string{"fileExists"}, + [][2]string{ + {`{{ fileExists "foo.txt" }}`, `false`}, + }, + ) + ns.AddMethodMapping(ctx.Getenv, []string{"getenv"}, [][2]string{}, @@ -50,11 +57,9 @@ func init() { }, ) - ns.AddMethodMapping(ctx.FileExists, - []string{"fileExists"}, - [][2]string{ - {`{{ fileExists "foo.txt" }}`, `false`}, - }, + ns.AddMethodMapping(ctx.Stat, + nil, + [][2]string{}, ) return ns diff --git a/tpl/partials/init.go b/tpl/partials/init.go index 6f7c0ffc1..7d45f0eaf 100644 --- a/tpl/partials/init.go +++ b/tpl/partials/init.go @@ -38,6 +38,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.IncludeCached, + []string{"partialCached"}, + [][2]string{}, + ) + // TODO(bep) we need the return to be a valid identifiers, but // should consider another way of adding it. ns.AddMethodMapping(func() string { return "" }, @@ -45,11 +50,6 @@ func init() { [][2]string{}, ) - ns.AddMethodMapping(ctx.IncludeCached, - []string{"partialCached"}, - [][2]string{}, - ) - return ns } diff --git a/tpl/path/init.go b/tpl/path/init.go index 97a479d3f..5193ff790 100644 --- a/tpl/path/init.go +++ b/tpl/path/init.go @@ -33,12 +33,29 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } - ns.AddMethodMapping(ctx.Split, + ns.AddMethodMapping(ctx.Base, nil, - [][2]string{ - {`{{ "/my/path/filename.txt" | path.Split }}`, `/my/path/|filename.txt`}, - {fmt.Sprintf(`{{ %q | path.Split }}`, filepath.FromSlash("/my/path/filename.txt")), `/my/path/|filename.txt`}, - }, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.BaseName, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Clean, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Dir, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Ext, + nil, + [][2]string{}, ) testDir := filepath.Join("my", "path") @@ -55,6 +72,14 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Split, + nil, + [][2]string{ + {`{{ "/my/path/filename.txt" | path.Split }}`, `/my/path/|filename.txt`}, + {fmt.Sprintf(`{{ %q | path.Split }}`, filepath.FromSlash("/my/path/filename.txt")), `/my/path/|filename.txt`}, + }, + ) + return ns } internal.AddTemplateFuncsNamespace(f) diff --git a/tpl/resources/init.go b/tpl/resources/init.go index 5cea482ac..9048e3a46 100644 --- a/tpl/resources/init.go +++ b/tpl/resources/init.go @@ -53,28 +53,84 @@ func init() { }, } - ns.AddMethodMapping(ctx.Get, + // Deprecated. Use js.Babel instead. + ns.AddMethodMapping(ctx.Babel, nil, [][2]string{}, ) - ns.AddMethodMapping(ctx.GetRemote, + ns.AddMethodMapping(ctx.ByType, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Concat, nil, [][2]string{}, ) - // Add aliases for the most common transformations. + ns.AddMethodMapping(ctx.Copy, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.ExecuteAsTemplate, + nil, + [][2]string{}, + ) ns.AddMethodMapping(ctx.Fingerprint, []string{"fingerprint"}, [][2]string{}, ) + ns.AddMethodMapping(ctx.FromString, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Get, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Match, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.GetRemote, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Match, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Minify, []string{"minify"}, [][2]string{}, ) + // Deprecated. Use css.PostCSS instead. + ns.AddMethodMapping(ctx.PostCSS, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.PostProcess, + nil, + [][2]string{}, + ) + + // Deprecated. Use css.Sass instead. + ns.AddMethodMapping(ctx.ToCSS, + nil, + [][2]string{}, + ) + return ns } diff --git a/tpl/strings/init.go b/tpl/strings/init.go index b236d110a..75473e4c1 100644 --- a/tpl/strings/init.go +++ b/tpl/strings/init.go @@ -38,18 +38,24 @@ func init() { }, ) - ns.AddMethodMapping(ctx.CountRunes, - []string{"countrunes"}, - [][2]string{}, + ns.AddMethodMapping(ctx.Contains, + nil, + [][2]string{ + {`{{ strings.Contains "abc" "b" }}`, `true`}, + {`{{ strings.Contains "abc" "d" }}`, `false`}, + }, ) - ns.AddMethodMapping(ctx.RuneCount, + ns.AddMethodMapping(ctx.ContainsAny, nil, - [][2]string{}, + [][2]string{ + {`{{ strings.ContainsAny "abc" "bcd" }}`, `true`}, + {`{{ strings.ContainsAny "abc" "def" }}`, `false`}, + }, ) - ns.AddMethodMapping(ctx.CountWords, - []string{"countwords"}, + ns.AddMethodMapping(ctx.ContainsNonSpace, + nil, [][2]string{}, ) @@ -60,20 +66,19 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Contains, - nil, - [][2]string{ - {`{{ strings.Contains "abc" "b" }}`, `true`}, - {`{{ strings.Contains "abc" "d" }}`, `false`}, - }, + ns.AddMethodMapping(ctx.CountRunes, + []string{"countrunes"}, + [][2]string{}, ) - ns.AddMethodMapping(ctx.ContainsAny, + ns.AddMethodMapping(ctx.CountWords, + []string{"countwords"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Diff, nil, - [][2]string{ - {`{{ strings.ContainsAny "abc" "bcd" }}`, `true`}, - {`{{ strings.ContainsAny "abc" "def" }}`, `false`}, - }, + [][2]string{}, ) ns.AddMethodMapping(ctx.FindRE, @@ -96,6 +101,13 @@ func init() { }, ) + ns.AddMethodMapping(ctx.FirstUpper, + nil, + [][2]string{ + {`{{ "hugo rocks!" | strings.FirstUpper }}`, `Hugo rocks!`}, + }, + ) + ns.AddMethodMapping(ctx.HasPrefix, []string{"hasPrefix"}, [][2]string{ @@ -112,10 +124,10 @@ func init() { }, ) - ns.AddMethodMapping(ctx.ToLower, - []string{"lower"}, + ns.AddMethodMapping(ctx.Repeat, + nil, [][2]string{ - {`{{ lower "BatMan" }}`, `batman`}, + {`{{ "yo" | strings.Repeat 4 }}`, `yoyoyoyo`}, }, ) @@ -147,6 +159,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.RuneCount, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.SliceString, []string{"slicestr"}, [][2]string{ @@ -168,6 +185,28 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Title, + []string{"title"}, + [][2]string{ + {`{{ title "Bat man" }}`, `Bat Man`}, + {`{{ title "somewhere over the rainbow" }}`, `Somewhere Over the Rainbow`}, + }, + ) + + ns.AddMethodMapping(ctx.ToLower, + []string{"lower"}, + [][2]string{ + {`{{ lower "BatMan" }}`, `batman`}, + }, + ) + + ns.AddMethodMapping(ctx.ToUpper, + []string{"upper"}, + [][2]string{ + {`{{ upper "BatMan" }}`, `BATMAN`}, + }, + ) + ns.AddMethodMapping(ctx.Trim, []string{"trim"}, [][2]string{ @@ -197,26 +236,16 @@ func init() { }, ) - ns.AddMethodMapping(ctx.TrimSuffix, + ns.AddMethodMapping(ctx.TrimSpace, nil, - [][2]string{ - {`{{ "aabbaa" | strings.TrimSuffix "a" }}`, `aabba`}, - {`{{ "aabbaa" | strings.TrimSuffix "aa" }}`, `aabb`}, - }, - ) - - ns.AddMethodMapping(ctx.Title, - []string{"title"}, - [][2]string{ - {`{{ title "Bat man" }}`, `Bat Man`}, - {`{{ title "somewhere over the rainbow" }}`, `Somewhere Over the Rainbow`}, - }, + [][2]string{}, ) - ns.AddMethodMapping(ctx.FirstUpper, + ns.AddMethodMapping(ctx.TrimSuffix, nil, [][2]string{ - {`{{ "hugo rocks!" | strings.FirstUpper }}`, `Hugo rocks!`}, + {`{{ "aabbaa" | strings.TrimSuffix "a" }}`, `aabba`}, + {`{{ "aabbaa" | strings.TrimSuffix "aa" }}`, `aabb`}, }, ) @@ -228,20 +257,6 @@ func init() { }, ) - ns.AddMethodMapping(ctx.Repeat, - nil, - [][2]string{ - {`{{ "yo" | strings.Repeat 4 }}`, `yoyoyoyo`}, - }, - ) - - ns.AddMethodMapping(ctx.ToUpper, - []string{"upper"}, - [][2]string{ - {`{{ upper "BatMan" }}`, `BATMAN`}, - }, - ) - return ns } diff --git a/tpl/templates/init.go b/tpl/templates/init.go index 4e5251d0d..ac62194bb 100644 --- a/tpl/templates/init.go +++ b/tpl/templates/init.go @@ -31,12 +31,9 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } - ns.AddMethodMapping(ctx.Exists, + ns.AddMethodMapping(ctx.Current, nil, - [][2]string{ - {`{{ if (templates.Exists "_partials/header.html") }}Yes!{{ end }}`, `Yes!`}, - {`{{ if not (templates.Exists "_partials/doesnotexist.html") }}No!{{ end }}`, `No!`}, - }, + [][2]string{}, ) ns.AddMethodMapping(ctx.Defer, @@ -44,11 +41,20 @@ func init() { [][2]string{}, ) + // For internal use only. ns.AddMethodMapping(ctx.DoDefer, []string{"doDefer"}, [][2]string{}, ) + ns.AddMethodMapping(ctx.Exists, + nil, + [][2]string{ + {`{{ if (templates.Exists "_partials/header.html") }}Yes!{{ end }}`, `Yes!`}, + {`{{ if not (templates.Exists "_partials/doesnotexist.html") }}No!{{ end }}`, `No!`}, + }, + ) + return ns } diff --git a/tpl/time/init.go b/tpl/time/init.go index 525be2cf5..3f84d88a2 100644 --- a/tpl/time/init.go +++ b/tpl/time/init.go @@ -57,18 +57,6 @@ func init() { }, } - ns.AddMethodMapping(ctx.Format, - []string{"dateFormat"}, - [][2]string{ - {`dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}`, `dateFormat: Wednesday, Jan 21, 2015`}, - }, - ) - - ns.AddMethodMapping(ctx.Now, - []string{"now"}, - [][2]string{}, - ) - ns.AddMethodMapping(ctx.AsTime, nil, [][2]string{ @@ -83,6 +71,23 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Format, + []string{"dateFormat"}, + [][2]string{ + {`dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}`, `dateFormat: Wednesday, Jan 21, 2015`}, + }, + ) + + ns.AddMethodMapping(ctx.In, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Now, + []string{"now"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.ParseDuration, nil, [][2]string{ diff --git a/tpl/transform/init.go b/tpl/transform/init.go index e43960427..6aa95938a 100644 --- a/tpl/transform/init.go +++ b/tpl/transform/init.go @@ -31,6 +31,11 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.CanHighlight, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Emojify, []string{"emojify"}, [][2]string{ @@ -43,6 +48,11 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.HighlightCodeBlock, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.HTMLEscape, []string{"htmlEscape"}, [][2]string{ @@ -61,6 +71,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.HTMLToMarkdown, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.HTMLUnescape, []string{"htmlUnescape"}, [][2]string{ @@ -97,6 +112,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.PortableText, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Remarshal, nil, [][2]string{ @@ -104,6 +124,11 @@ func init() { }, ) + ns.AddMethodMapping(ctx.ToMath, + nil, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Unmarshal, []string{"unmarshal"}, [][2]string{ diff --git a/tpl/urls/init.go b/tpl/urls/init.go index cdc597f34..82208e538 100644 --- a/tpl/urls/init.go +++ b/tpl/urls/init.go @@ -31,49 +31,69 @@ func init() { Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, } + ns.AddMethodMapping(ctx.AbsLangURL, + []string{"absLangURL"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.AbsURL, []string{"absURL"}, [][2]string{}, ) - ns.AddMethodMapping(ctx.AbsLangURL, - []string{"absLangURL"}, + ns.AddMethodMapping(ctx.Anchorize, + []string{"anchorize"}, + [][2]string{ + {`{{ "This is a title" | anchorize }}`, `this-is-a-title`}, + }, + ) + + ns.AddMethodMapping(ctx.JoinPath, + nil, + [][2]string{ + {`{{ urls.JoinPath "https://example.org" "foo" }}`, `https://example.org/foo`}, + {`{{ urls.JoinPath (slice "a" "b") }}`, `a/b`}, + }, + ) + + ns.AddMethodMapping(ctx.Parse, + nil, [][2]string{}, ) - ns.AddMethodMapping(ctx.Ref, - []string{"ref"}, + + ns.AddMethodMapping(ctx.PathEscape, + nil, [][2]string{}, ) - ns.AddMethodMapping(ctx.RelURL, - []string{"relURL"}, + + ns.AddMethodMapping(ctx.PathUnescape, + nil, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.Ref, + []string{"ref"}, [][2]string{}, ) + ns.AddMethodMapping(ctx.RelLangURL, []string{"relLangURL"}, [][2]string{}, ) + ns.AddMethodMapping(ctx.RelRef, []string{"relref"}, [][2]string{}, ) - ns.AddMethodMapping(ctx.URLize, - []string{"urlize"}, - [][2]string{}, - ) - ns.AddMethodMapping(ctx.Anchorize, - []string{"anchorize"}, - [][2]string{ - {`{{ "This is a title" | anchorize }}`, `this-is-a-title`}, - }, + ns.AddMethodMapping(ctx.RelURL, + []string{"relURL"}, + [][2]string{}, ) - ns.AddMethodMapping(ctx.JoinPath, - nil, - [][2]string{ - {`{{ urls.JoinPath "https://example.org" "foo" }}`, `https://example.org/foo`}, - {`{{ urls.JoinPath (slice "a" "b") }}`, `a/b`}, - }, + ns.AddMethodMapping(ctx.URLize, + []string{"urlize"}, + [][2]string{}, ) return ns -- 2.39.5