Flutter-Bounty-Hunters / static_shock

A static site generator for Dart.
MIT License
59 stars 5 forks source link

Make jinja filters and tests configurable, highlight active top level nav (Resolves #19) #73

Closed matthew-carroll closed 2 months ago

matthew-carroll commented 3 months ago

Make jinja filters and tests configurable.

Jinja templates have a concept of filters, which pretty much operate like arbitrary methods that are callable from templates. Jinja templates also have a concept of "tests", which are methods that return true/false.

Filters are called in templates by following some value with a "|" and the filter name: "someValue|myFilter".

Tests are called in templates by following some value with "is" and the test name: "someValue is defined".

This PR lets users add their own filters and tests to the Jinja plugin. The filters and tests are added as functions that create functions because we need an opportunity to inject Static Shock context data into the filters and tests. Otherwise, the filters and tests wouldn't have access to things like pages - because Jinja has no concept of pages or other Static Shock artifacts.