From 81e59f7b069da67f6889fa0d5d4ca1d39c1fa1f0 Mon Sep 17 00:00:00 2001 From: Antony Harfield Date: Thu, 24 Aug 2017 20:56:44 +0700 Subject: [PATCH 1/4] Leaf - correct usage of #index is with string only (int does not work) --- 2.0/docs/leaf/leaf.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/2.0/docs/leaf/leaf.md b/2.0/docs/leaf/leaf.md index 38776e32..1210e7ae 100644 --- a/2.0/docs/leaf/leaf.md +++ b/2.0/docs/leaf/leaf.md @@ -84,13 +84,15 @@ Hello, #(name)! Hello, #(friend.name)! } ``` -#### Index: `#index(object, _ index: Int|String)` +#### Index: `#index(array, _ index: String)` ``` -Hello, #index(friends, 0)! +Hello, #index(friends, "0")! Hello, #index(friends, "best")! ``` +Note: array indexes are always strings. + #### If - Else: `#if(bool) ##else() { this }` ``` From 8c829b9fe5278e5e681a87abc234aba9a1885b60 Mon Sep 17 00:00:00 2001 From: Antony Harfield Date: Thu, 24 Aug 2017 20:59:27 +0700 Subject: [PATCH 2/4] Leaf - added note that #loop can access an index and an offset variable --- 2.0/docs/leaf/leaf.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/2.0/docs/leaf/leaf.md b/2.0/docs/leaf/leaf.md index 1210e7ae..1c157ab9 100644 --- a/2.0/docs/leaf/leaf.md +++ b/2.0/docs/leaf/leaf.md @@ -77,13 +77,16 @@ The double token: `##` indicates a chain. It can be applied to any standard Tag. Hello, #(name)! ``` -#### Loop: `#loop(object, "index")` +#### Loop: `#loop(array, "item") {}` ``` #loop(friends, "friend") { - Hello, #(friend.name)! + #(offset). #(friend.name) } ``` + +The body of a `#loop` can access an `index` variable corresponding to the index of the array. There is also an `offset` variable which is the index plus 1. + #### Index: `#index(array, _ index: String)` ``` From dea0ad20680109615050650454f622b9d1277b2f Mon Sep 17 00:00:00 2001 From: Antony Harfield Date: Thu, 24 Aug 2017 21:00:37 +0700 Subject: [PATCH 3/4] Leaf - give an example of a switch statement using #equal and #else --- 2.0/docs/leaf/leaf.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/2.0/docs/leaf/leaf.md b/2.0/docs/leaf/leaf.md index 1c157ab9..5d42f728 100644 --- a/2.0/docs/leaf/leaf.md +++ b/2.0/docs/leaf/leaf.md @@ -108,6 +108,18 @@ Note: array indexes are always strings. } ``` +Note that `#if` requires a boolean variable. If you need to do a comparison then `#equal` is more appropriate. You can chain `#equal` in the same way as `#if`: + +``` +#equal(state, "0") { + Normal +} ##equal(state, "1") { + Warning +} ##else() { + Alert +} +``` + #### Import: `#import("template")` #### Export: `#export("template") { Leaf/HTML }` #### Extend: `#extend("template")` From 02bd18b12c8e71684c2dfba9395979e31b0a88d6 Mon Sep 17 00:00:00 2001 From: Antony Harfield Date: Thu, 24 Aug 2017 21:08:06 +0700 Subject: [PATCH 4/4] Minor grammar improvement --- 2.0/docs/leaf/leaf.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2.0/docs/leaf/leaf.md b/2.0/docs/leaf/leaf.md index 5d42f728..42674365 100644 --- a/2.0/docs/leaf/leaf.md +++ b/2.0/docs/leaf/leaf.md @@ -1,9 +1,9 @@ !!! warning This section may contain outdated information. - + # Leaf -Welcome to Leaf. Leaf's goal is to be a simple templating language that can make generating views easier. There's a lot of great templating languages, use what's best for you, maybe that's Leaf! The goals of Leaf are as follows: +Welcome to Leaf. Leaf's goal is to be a simple templating language that can make generating views easier. There are plenty of great templating languages, so use what's best for you -- maybe that's Leaf! The goals of Leaf are: - Small set of strictly enforced rules - Consistency