pongo2addons

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2023 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

pongo2-addons

Build Status Gratipay

Official filter and tag add-ons for pongo2. Since this package uses 3rd-party-libraries, it's in its own package.

How to install and use

Install via go get -u github.com/flosch/pongo2-addons. All dependencies will be automatically fetched and installed.

Simply add the following import line after importing pongo2:

_ "github.com/flosch/pongo2-addons"
// or github.com/iostrovok/pongo2-addons for extend version

All additional filters/tags will be registered automatically.

Addons

Filters
  • Regulars

    • filesizeformat (human-readable filesize; takes bytes as input)
    • slugify (creates a slug for a given input)
    • truncatesentences / truncatesentences_html (returns the first X sentences [like truncatechars/truncatewords]; please provide X as a parameter)
    • random (returns a random element of the input slice)
  • Markup

    • markdown
  • Humanize

    • intcomma (put decimal marks into the number)
    • ordinal (convert integer to its ordinal as string)
    • naturalday (converts time.Time -object into today/yesterday/tomorrow if possible; otherwise it will use naturaltime)
    • timesince /timeuntil /naturaltime (human-readable time [duration] indicator)
  • Numeric

    • iplus (adds an integer to the number)
    • iminus (removes an integer from a number)
    • imultiply (multiples an integer by a number)
  • Line Breakers

    • solidlinebreaksbr adds value is passed pass second parameter (
      by default) each N symbols to line
  • Print error

    • printerror prints error.Error() if gets error object. Other ways it prints the string
  • Integer range

    • range returns range integers (slice) for 1 to N.
    • range0 returns range integers (slice) for 0 to N-1
  • Json

    • json|safe returns JSON.Marshal(...) string for value.
  • Join with "\n"

    • jsonBr returns the merged array as a string with "\n" as the delimiter.
Tags

(nothing yet)

TODO

  • Support i18n/i10n

Used libraries

I want to thank the authors of these libraries (which are being used in pongo2-addons):

Example


// result "1-2-3-4-5-6-"
{% for t in ''|range: '6' %}{{ t }}-{% endfor %}

// result "0a1a2a3a4a5a"
{% for t in ''|range0: '6' %}{{ t }}a{% endfor %}

// from -> to ranges
// result "-1.0.1.2.3.4.5.6."
{% for t in ''|range: '-1,6' %}{{ t }}.{% endfor %}

// result "-1.0.1.2.3.4.5."
{% for t in ''|range0: '-1,6' %}{{ t }}.{% endfor %}

// result "one 🐘 <br/>and th<br/>ree πŸ‹"
{{ 'one 🐘 and three πŸ‹'|solidlinebreaksbr: '6'|safe }}

// result "one 🐘 <s>and th<s>ree πŸ‹"
    {{ 'one 🐘 and three πŸ‹'|solidlinebreaksbr: '6,<s>'|safe }}

// result "A\nB\nC\nD\nE"
    // T => []string{"A", "B", "C", "D", "E"}
    {{ T|joinBr }}

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 捒网址