Skip to content

Commit 7296bca

Browse files
committed
latte 3.1.4
1 parent 35f5b9c commit 7296bca

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

latte/cs/custom-tags.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Když Latte narazí na `{datetime}` v šabloně, zavolá parsovací funkci `crea
160160

161161
Metoda `print()` generuje PHP kód, který bude spuštěn při vykreslování šablony. Voláme metodu `$context->format()`, která sestavuje výsledný řetězec PHP kódu pro kompilovanou šablonu. První argument, `'echo date('Y-m-d H:i:s') %line;'`, je maska, do které jsou doplněny následující parametry. Zástupný symbol `%line` říká metodě `format()`, aby použila druhý argument, kterým je `$this->position`, a vložila komentář jako `/* line 15 */`, který propojuje vygenerovaný PHP kód zpět na původní řádek šablony, což je klíčové pro ladění.
162162

163-
Vlastnost `$this->position` je zděděna ze základní třídy `Node` a je automaticky nastavena parserem Latte. Obsahuje objekt [api:Latte\Compiler\Position], který indikuje, kde byl tag nalezen ve zdrojovém souboru `.latte`.
163+
Vlastnost `$this->position` je zděděna ze základní třídy `Node` a je automaticky nastavena parserem Latte. Obsahuje objekt [api:Latte\Compiler\Range] (potomek třídy `Position` rozšířený o vlastnost `length` v bajtech), který udává, kde se tag v souboru `.latte` nachází. U párových tagů pokrývá rozsah od otevíracího po uzavírací tag a potomci `StatementNode` navíc nabízejí pole `$this->tagRanges` s objekty `Range` pro každý dílčí tag (otevírací, mezilehlé jako `{else}`/`{case}` i uzavírací).
164164

165165
Metoda `getIterator()` je zásadní pro kompilační průchody. Musí poskytovat všechny dětské uzly, ale náš jednoduchý `DatetimeNode` aktuálně nemá žádné argumenty ani obsah, tedy žádné dětské uzly. Nicméně metoda musí stále existovat a být generátorem, tj. klíčové slovo `yield` musí být nějakým způsobem přítomno v těle metody.
166166

@@ -1003,7 +1003,7 @@ Zástupné symboly `PrintContext::format()`
10031003
- **`%args`**: Argument musí být `Expression\ArrayNode`. Vypíše položky pole formátované jako argumenty pro volání funkce nebo metody (oddělené čárkami, zpracovává pojmenované argumenty, pokud jsou přítomny).
10041004
- `$argsNode = new ArrayNode([...]);`
10051005
- `$context->format('myFunc(%args);', $argsNode)` -> `myFunc(1, name: 'Joe');`
1006-
- **`%line`**: Argument musí být objekt `Position` (obvykle `$this->position`). Vkládá PHP komentář `/* line X */` indikující číslo řádku zdroje.
1006+
- **`%line`**: Argument musí být objekt `Position` (nebo `Range`, obvykle `$this->position`). Vkládá PHP komentář `/* line X */` indikující číslo řádku zdroje.
10071007
- `$context->format('echo "Hi" %line;', $this->position)` -> `echo "Hi" /* line 42:1 */;`
10081008
- **`%escape(...)`**: Generuje PHP kód, který *za běhu* escapuje vnitřní výraz pomocí aktuálních kontextově uvědomělých pravidel escapování.
10091009
- `$context->format('echo %escape(%node);', $variableNode)`

latte/cs/filters.texy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ V šablonách můžeme používat funkce, které pomáhají upravit nebo přefor
1212
| `clamp` | [ohraničí hodnotu do daného rozsahu |#clamp]
1313
| `column` | [extrahuje jeden sloupec z pole |#column]
1414
| `commas` | [spojí pole čárkami |#commas]
15+
| `limit` | [omezí délku pole, řetězce nebo iterátoru |#limit]
1516
| `dataStream` | [konverze pro Data URI protokol |#dataStream]
1617
| `date` | [formátuje datum a čas |#date]
1718
| `explode` | [rozdělí řetězec na pole podle oddělovače |#explode]
@@ -812,6 +813,21 @@ Pokud je zadaný parametr length a je kladný, posloupnost bude obsahovat tolik
812813

813814
Ve výchozím nastavení filtr změní pořadí a resetuje celočíselného klíče pole. Toto chování lze změnit nastavením preserveKeys na true. Řetězcové klíče jsou vždy zachovány, bez ohledu na tento parametr.
814815

816+
Viz také [#limit].
817+
818+
819+
limit(int $length) .[filter]{data-version:3.1.3}
820+
------------------------------------------------
821+
Omezí délku pole, řetězce nebo iterátoru. U polí a iterátorů zachovává klíče. U řetězců respektuje UTF-8.
822+
823+
```latte
824+
{foreach ($items|limit: 5) as $item}
825+
...
826+
{/foreach}
827+
828+
{$text|limit: 100}
829+
```
830+
815831

816832
sort(?Closure $comparison, string|int|\Closure|null $by=null, string|int|\Closure|bool $byKey=false) .[filter]
817833
--------------------------------------------------------------------------------------------------------------

latte/en/custom-tags.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ When Latte encounters `{datetime}` in a template, it calls the tag parsing funct
160160

161161
The `print()` method generates the PHP code that will be executed when the template is rendered. We call the `$context->format()` method, which assembles the resulting PHP code string for the compiled template. The first argument, `'echo date('Y-m-d H:i:s') %line;'`, is the mask into which the subsequent parameters are substituted. The `%line` placeholder tells the `format()` method to take the second following argument, which is `$this->position`, and inserts a comment like `/* line 15 */` that links the generated PHP code back to the original template line, which is crucial for debugging.
162162

163-
Property `$this->position` is inherited from the base `Node` class, and is automatically set by Latte's parser. It holds a [api:Latte\Compiler\Position] object indicating where the tag was found in the source `.latte` file.
163+
Property `$this->position` is inherited from the base `Node` class, and is automatically set by Latte's parser. It holds a [api:Latte\Compiler\Range] object (a subclass of `Position` extended with a `length` in bytes) indicating where the tag is located in the source `.latte` file. For paired tags the range spans from the opening to the closing tag, and `StatementNode` descendants additionally expose `$this->tagRanges` listing the `Range` of every constituent tag (opening, intermediate like `{else}`/`{case}`, and closing).
164164

165165
The `getIterator()` method is vital for compiler passes. It must yield all child nodes, but our simple `DatetimeNode` currently has no arguments or content, thus no child nodes. However, the method must still exist and be a generator, i.e. the `yield` keyword must be somehow present in the method body.
166166

@@ -1003,7 +1003,7 @@ We've frequently used `PrintContext::format()` to generate PHP code in the `prin
10031003
- **`%args`**: Argument must be an `Expression\ArrayNode`. It prints the array items formatted as arguments for a function or method call (comma-separated, handling named arguments if present).
10041004
- `$argsNode = new ArrayNode([...]);`
10051005
- `$context->format('myFunc(%args);', $argsNode)` -> `myFunc(1, name: 'Joe');`
1006-
- **`%line`**: Argument must be a `Position` object (usually `$this->position`). It inserts a PHP comment `/* line X */` indicating the source line number.
1006+
- **`%line`**: Argument must be a `Position` (or `Range`) object (usually `$this->position`). It inserts a PHP comment `/* line X */` indicating the source line number.
10071007
- `$context->format('echo "Hi" %line;', $this->position)` -> `echo "Hi" /* line 42:1 */;`
10081008
- **`%escape(...)`**: It generates PHP code that, *at runtime*, will escape the inner expression using the current context-aware escaping rules.
10091009
- `$context->format('echo %escape(%node);', $variableNode)`

latte/en/filters.texy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ In templates, we can use functions that help modify or reformat data into its fi
1212
| `clamp` | [clamps a value to the given range |#clamp]
1313
| `column` | [extracts a single column from an array |#column]
1414
| `commas` | [joins an array with commas |#commas]
15+
| `limit` | [limits the length of an array, string, or iterator |#limit]
1516
| `dataStream` | [Data URI protocol conversion |#dataStream]
1617
| `date` | [formats the date and time |#date]
1718
| `explode` | [splits a string into an array by a delimiter |#explode]
@@ -812,6 +813,21 @@ If `length` is given and is positive, then the sequence will have up to that man
812813

813814
By default, the filter reorders and resets the integer array keys. This behavior can be changed by setting `preserveKeys` to true. String keys are always preserved, regardless of this parameter.
814815

816+
See also [#limit].
817+
818+
819+
limit(int $length) .[filter]{data-version:3.1.3}
820+
------------------------------------------------
821+
Limits the length of an array, string, or iterator. For arrays and iterators, keys are preserved. For strings, it respects UTF-8.
822+
823+
```latte
824+
{foreach ($items|limit: 5) as $item}
825+
...
826+
{/foreach}
827+
828+
{$text|limit: 100}
829+
```
830+
815831

816832
sort(?Closure $comparison, string|int|\Closure|null $by=null, string|int|\Closure|bool $byKey=false) .[filter]
817833
--------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)