= SprigX Brent Saner Last rendered {localdatetime} :doctype: book :docinfo: shared :data-uri: :imagesdir: images :sectlinks: :sectnums: :sectnumlevels: 7 :toc: preamble :toc2: left :idprefix: :toclevels: 7 :source-highlighter: rouge :docinfo: shared // BEGIN variable attributes :sprig_ver: 3 :psutil_ver: 4 :git_owner: r00t2 :git_repo: go_goutils :git_repo_full: {git_owner}/{git_repo} :mod_me: r00t2.io/goutils :pkg_me: tplx/sprigx :src_root: https://git.r00t2.io :godoc_root: https://pkg.go.dev :sprig_web: https://masterminds.github.io/sprig :mod_sprig: github.com/Masterminds/sprig/v{sprig_ver} :mod_psutil: github.com/shirou/gopsutil/v{psutil_ver} :import_sprig: {mod_sprig} :src_base: {src_root}/{git_repo_full} :src_git: {src_base}.git :src_tree: {src_base}/src/branch/master :src_raw: {src_base}/raw/branch/master :src_dir: {src_tree}/{pkg_me} :src_dir_raw: {src_raw}/{pkg_me} :import_me: {mod_me}/{pkg_me} :godoc_me: {godoc_root}/{import_me} :godoc_sprig: {godoc_root}/{import_sprig} // END variable attributes [id="wat"] == What is SprigX? SprigX is a suite of extensions to {sprig_web}/[the `sprig` library^] ({godoc_sprig}[Go docs^]). They provide functions that offer more enriched use cases and domain-specific data. [TIP] ==== If you are reading this README on the Go Module Directory documentation ({godoc_me}) or the directory landing page ({src_dir}), it may not render correctly. Anchor-links (links within this document to other sections of this document) will likely also not work. Be sure to view it at properly via {src_dir}/README.adoc[the in-repo AsciiDoc rendering^] or by downloading and viewing the {src_dir_raw}/README.html[HTML version^] in a browser locally and/or <>. ==== [id="rndr"] == How do I Render These Docs? This documentation is written in https://asciidoc.org/[AsciiDoc^] (with https://asciidoctor.org/[AsciiDoctor^] extensions). To re-render all docs (including <>): [source,bash, subs="attributes"] ---- git clone {src_git} cd {git_repo} .githooks/pre-commit/01-docgen ---- [id="rndr_html"] === HTML HTML output is re-rendered and included in git {src_dir}/.githooks/pre-commit/01-docgen[on each commit^] automatically (via https://github.com/gabyx/Githooks[`github:gabyx/Githooks`^]) but can be re-rendered on-demand locally via: [source,bash, subs="attributes"] ---- git clone {src_git} cd {git_repo} export orig_dir="$(pwd)" cd {pkg_me} asciidoctor -a ROOTDIR="${orig_dir}/" -o README.html README.adoc ---- [id="rndr_pdf"] === PDF This documentation can be rendered to PDF via https://docs.asciidoctor.org/pdf-converter/latest/[`asciidoctor-pdf`^]. It is not included in git automatically because binary files that change on each commit is not a good idea for git, especially for a repo that gets cloned as part of a library inclusion in a module/package dependency system (like `gomod`). To render as PDF: [source,bash,subs="attributes"] ---- git clone {src_git} cd {git_repo} export orig_dir="$(pwd)" cd {pkg_me} asciidoctor-pdf -a ROOTDIR="${orig_dir}/" -o README.pdf README.adoc ---- [id="use"] == How do I Use SprigX? The same way you would `sprig`! [%collapsible] .Like this. ==== [source,go,subs="attributes"] ---- package main import ( htmlTplLib "html/template" txtTplLib "text/template" "{import_me}" ) var ( txtTpl *txtTplLib.Template = txtTplLib. New(""). Funcs( sprigx.TxtFuncMap(), ) htmlTpl *htmlTplLib.Template = htmlTplLib. New(""). Funcs( sprigx.HtmlFuncMap(), ) ) ---- ==== They can even be combined/used together, [%collapsible] .like this. ==== [source,go,subs="attributes"] ---- package main import ( "text/template" "{import_sprig}" "{import_me}" ) var txtTpl *template.Template = template. New(""). Funcs( sprigx.TxtFuncMap(), ). Funcs( sprig.TxtFuncMap(), ) // Or: /* var txtTpl *template.Template = template. New(""). Funcs( sprig.TxtFuncMap(), ). Funcs( sprigx.TxtFuncMap(), ) */ ---- ==== Or, as a convenience, you can simply use the <> and/or <> functions. If a `