aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-04-02 21:24:51 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-04-12 20:01:54 +0200
commite6cf48e8490a15f293f55bf462fb7d0cb2f6400c (patch)
treef3912adf982563058776fc3dc477f088455ccf82
parente46e2d6b02394eea8ffe7ac723469b9b114e234c (diff)
downloadaskama-e6cf48e8490a15f293f55bf462fb7d0cb2f6400c.tar.gz
askama-e6cf48e8490a15f293f55bf462fb7d0cb2f6400c.tar.bz2
askama-e6cf48e8490a15f293f55bf462fb7d0cb2f6400c.zip
Write up some documentation for match blocks
-rw-r--r--askama/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index ec89998..3f0a267 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -205,6 +205,28 @@
//! {% endif %}
//! ```
//!
+//! ### Match
+//!
+//! In order to deal with Rust `enum`s in a type-safe way, templates support
+//! match blocks from version 0.6. Here is a simple example showing how to
+//! expand an `Option`:
+//!
+//! ```text
+//! {% match item %}
+//! {% when Some with ("foo") %}
+//! Found literal foo
+//! {% when Some with (val) %}
+//! Found {{ val }}
+//! {% when None %}
+//! {% endmatch %}
+//! ```
+//!
+//! That is, a `match` block can optionally contain some whitespace (but
+//! no other literal content), followed by a number of `when` blocks and
+//! and an optional `else` block. Each `when` block must name a list of
+//! matches (`(val)`), optionally introduced with a variant name. The
+//! `else` block is equivalent to matching on `_` (matching anything).
+//!
//! ### Include
//!
//! The *include* statement lets you split large or repetitive blocks into