Skip to content

Commit e6cbdc0

Browse files
authored
docs: updates for new markdown parser (#2149)
1 parent fae631d commit e6cbdc0

7 files changed

Lines changed: 75 additions & 14 deletions

File tree

docs/1-essentials/02-views.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ Since `:isset` is a shorthand for `:if="isset()"`, it can be combined with `:els
215215
<h1 :else>Title</h1>
216216
```
217217

218-
#### `:foreach` and `:{:hl-keyword:forelse:}`
218+
#### `{:hl-property::foreach:}` and `:{:hl-property:forelse:}`
219219

220-
The `:foreach` directive may be used to render the associated element multiple times based on the result of its expression. Combined with `:{:hl-keyword:forelse:}`, an empty state can be displayed when the data is empty.
220+
The `{:hl-property::foreach:}` directive may be used to render the associated element multiple times based on the result of its expression. Combined with `:{:hl-property:forelse:}`, an empty state can be displayed when the data is empty.
221221

222222
```html
223223
<li :foreach="$this->reports as $report">
@@ -249,26 +249,35 @@ The example above will only render the child `div` elements:
249249
### Tag override with the `as` prop
250250

251251
The `as` attribute allows you to transform the rendered tag of one element into another. This takes place on an instance of `GenericElement`, so for example this code:
252+
252253
```html
253254
<a as="button">My Link</a>
254255
```
256+
255257
Would render
258+
256259
```html
257260
<button>My Link</button>
258261
```
262+
259263
The power behind this is when you use an `Expression` to determine the element.
260264

261265
Say for example, you wish to have a `<x-link>` component which renders as an `<a>` when the `$href` attribute is provided. In your view, use the component like so:
266+
262267
```html
263268
<x-link href="https://tempestphp.com">Click to go to an awesome website</x-link>
264269

265270
<x-link>This is just a button</x-link>
266271
```
272+
267273
In your `<x-link>` component, define:
274+
268275
```html
269276
<a :as="$href ?? 'button'" :href="$href ?? ''"><x-slot /></a>
270277
```
271-
Your page will render two links, as follows
278+
279+
Your page will render two links, as follows:
280+
272281
```html
273282
<a href="https://tempestphp.com">Click to go to an awesome website</a>
274283

@@ -348,44 +357,57 @@ In previous releases (3.8.0 and prior), Tempest would attempt to *merge* these v
348357
:::
349358

350359
Assume you have a `button`, like so, with a default set of classes present:
360+
351361
```html x-button.view.php
352362
<button class="rounded-md px-2.5 py-1.5 text-sm">
353363
<x-slot />
354364
</button>
355365
```
366+
356367
Now, in your page, you may utilise the element:
368+
357369
```html index.view.php
358370
<x-button id="myBtn" style="color: red;" />
359371
```
372+
360373
As these attributes automatically apply, your button will be converted to this:
374+
361375
```html
362376
<button id="myBtn" style="color: red;" class="rounded-md px-2.5 py-1.5 text-sm" />
363377
```
364378

365379
#### Disabling automatic fallthrough
366380

367381
Tempest will attempt to apply `{html}class`, `{html}style`, and `{html}id` automatically, when they are passed to a view component. For example:
382+
368383
```html index.view.php
369384
<x-button id="myBtn" style="color: red;" />
370385
```
386+
371387
With the above, Tempest will attempt to apply `{html}style`, and `{html}id` automatically. As `{html}class` isn't configured, it isn't applied.
372388

373389
In the view component itself, you can configure `{html}class`, `{html}style`, and `{html}id` to anything you want, and Tempest will not overwrite them. You can of course, also then use these classes however you want to use them:
390+
374391
```html x-button.view.php
375392
<button :id="uniqid(($id ?? 'mybtn') . '_')" :class="$class ?? 'rounded-md px-2.5 py-1.5 text-sm'">
376393
<x-slot />
377394
</button>
378395
```
396+
379397
When you use this version of `<x-button />`:
398+
380399
- `{html}id` will now default to `mybtn_(sequence generated by uniqid)`,
381400
- `{html}style` will not appear automatically, as it was not supplied,
382401
- `{html}class` will have a default, you can of course instead concatenate these strings, or use a CVA utility for smart class merging, or anything you want.
383402

384403
For example, pass one or more classes:
404+
385405
```html
386406
<x-button id="myBtn" class="override" />
387407
```
408+
388409
And you'll get
410+
389411
```html
390412
<button class="override" id="myBtn_69cad27787c20"></button>
391413
```
@@ -403,39 +425,51 @@ You cannot mix `ApplyAttribute` with automatic fallthrough attributes. Opting to
403425
#### Excluding specific fallthrough attributes
404426

405427
To exclude specific attributes from falling through, configure your `button` view component like this:
428+
406429
```html x-button.view.php
407430
<button :apply="$attributes->removeKeys(['id', 'style'])">
408431
<x-slot />
409432
</button>
410433
```
434+
411435
:::info
412436
The `removeKeys` method returns all key=>value pairs, except for those specified. You can also use the `filter` method if you need to use a closure to filter.
413437
:::
438+
414439
Now, when utilising it in your page:
440+
415441
```html index.view.php
416442
<x-button id="myBtn" style="color: red;" class="rounded-md px-2.5 py-1.5 text-sm" />
417443
```
444+
418445
Will result in:
446+
419447
```html
420448
<button class="rounded-md px-2.5 py-1.5 text-sm" />
421449
```
422450

423451
#### Including only specific fallthrough attributes
424452

425453
To include only specific attributes, configure your `button` view component like this:
454+
426455
```html x-button.view.php
427456
<button :apply="$attributes->removeKeysExcept(['class', 'width', 'height'])">
428457
<x-slot />
429458
</button>
430459
```
460+
431461
:::info
432462
The `removeKeysExcept` method returns only the specified key=>value pairs. You can also use the `filter` method if you need to use a closure to filter.
433463
:::
464+
434465
Now, when utilising it in your page:
466+
435467
```html index.view.php
436468
<x-button id="myBtn" style="color: red;" class="rounded-md px-2.5 py-1.5 text-sm" width="1em" height="1em" />
437469
```
470+
438471
Tempest will apply only the specified attributes:
472+
439473
```html
440474
<button class="rounded-md px-2.5 py-1.5 text-sm" />
441475
```
@@ -445,21 +479,27 @@ Tempest will apply only the specified attributes:
445479
As the `ApplyAttribute` simply stringifies string and boolean values from the provided array, you can build the array however you like.
446480

447481
Consider this example `button`:
448-
```php x-button.view.php
482+
483+
```html x-button.view.php
449484
<?php
450485
$apply = [
451486
'class' => $class ?? null,
452487
'href' => $href ?? '',
453488
'target' => (isset($href) && str_contains($href, 'http')) ? '_blank' : null,
454489
];
455490
?>
491+
456492
<button :as="$apply['href'] !== '' ? 'a' : 'button'" :apply="$apply">{{ $label ?? '' }}</button>
457493
```
494+
458495
Now, when utilising it in your page:
496+
459497
```html index.view.php
460498
<x-button href="https://tempestphp.com" label="Tempest, the framework that gets out of your way" />
461499
```
500+
462501
Tempest will spread the supplied attributes, and as we also used the `AsAttribute` to convert it to a `{html}a` when `$href` is populated, you will get a hyperlink:
502+
463503
```html
464504
<a href="https://www.tempestphp.com" target="_blank">Tempest, the framework that gets out of your way</a>
465505
```
@@ -586,10 +626,12 @@ To override this behaviour and manually control in which view component your slo
586626
#### Extendable view component example using `define`
587627

588628
Let us assume you have an `x-container` view component, which is a `<div>` with formatting to act as a flex container for responsive sizing. You use this component repeatedly across your project, and it's effectively a macro to open and close the `<div>`; it doesn't have any slots or do anything special itself otherwise, with only a default `<x-slot/>` to render whatever it is given.
629+
589630
```html x-container.view.php
590631
<div class="w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"><x-slot/></div>
591632
```
592633
Now, assume we have an `x-header` in which we wish to use the `x-container`. Our `x-header` wishes to place slots `left` and `right` inside it; `x-header` owns these slots and wishes to expose these slots at the callsite in case they need custom content. Using the `define` keyword tells Tempest to treat these slots as *defined* by `x-header` instead of as a *slot to fill* inside `x-container`. Using `name` here instead of `define` would mean that Tempest falls back to the AST, and treats them as if they are slots of `<x-container>`.
634+
593635
```html x-header.view.php
594636
<header>
595637
<x-slot name="top" />
@@ -607,17 +649,21 @@ Now, assume we have an `x-header` in which we wish to use the `x-container`. Our
607649
<x-slot name="bottom" />
608650
</header>
609651
```
652+
610653
At the callsite, you still use the `name` attribute to define which slot you're placing content into:
654+
611655
```html callsite.view.php
612656
<x-header>
613657
<x-slot name="left">Some content I want to insert</x-slot>
614658
</x-header>
615659
```
660+
616661
This example would replace the default content `<x-header-left />` instead with the literal string `Some content I want to insert` - or whatever you provide.
617662

618663
#### Populating a child's name slot using `define`
619664

620665
You can also push content into a child's named slot, not just the default slot, by creating a `define`d slot as follows:
666+
621667
```html x-outer.view.php
622668
<div class="outer">
623669
<x-inner>
@@ -627,12 +673,15 @@ You can also push content into a child's named slot, not just the default slot,
627673
</x-inner>
628674
</div>
629675
```
676+
630677
Again, the `define` keyword registers a `left` slot against the view component `<x-outer>` irrespective of it's position in the AST, and means that at the callsite:
678+
631679
```html outercallsite.view.php
632680
<x-outer>
633681
<x-slot name="left">My override</x-slot>
634682
</x-outer>
635683
```
684+
636685
And so, this places the literal string `My override` into `<x-innner>`'s `left` slot.
637686

638687
### Dynamic view components
@@ -757,7 +806,9 @@ This component provides the ability to inject any icon from the [Iconify](https:
757806
```html
758807
<x-icon name="material-symbols:php" class="size-4 text-indigo-400" />
759808
```
809+
760810
will render
811+
761812
```html
762813
<svg class="size-4 text-indigo-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
763814
<path
@@ -772,7 +823,9 @@ This component includes some optional props you can use to control width and hei
772823
```html
773824
<x-icon name="material-symbols:php" />
774825
```
826+
775827
will render
828+
776829
```html
777830
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
778831
<path
@@ -787,7 +840,9 @@ Firstly, you can set width and height using Tailwind or custom classes. As long
787840
```html
788841
<x-icon name="material-symbols:php" class="w-[24px] h-[24px] text-indigo-400" />
789842
```
843+
790844
will render
845+
791846
```html
792847
<svg class="w-[24px] h-[24px] text-indigo-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
793848
<path
@@ -802,7 +857,9 @@ Secondly, if you aren't using Tailwind, or wish to set for a single icon without
802857
```html
803858
<x-icon name="material-symbols:php" style="width: 24px; height: 24px;" />
804859
```
860+
805861
will render
862+
806863
```html
807864
<svg style="width: 24px; height: 24px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
808865
<path
@@ -817,7 +874,9 @@ Finally, you may provide the width and height properties directly with the props
817874
```html
818875
<x-icon name="material-symbols:php" width="24px" height="24px" />
819876
```
877+
820878
will render
879+
821880
```html
822881
<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" viewBox="0 0 24 24">
823882
<path

docs/1-essentials/05-discovery.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Discovery comes with performance considerations. In production, it is always cac
3232

3333
To ensure that the discovery cache is up-to-date, add the `discovery:generate` command before any other Tempest command in your deployment pipeline.
3434

35-
```console ">_ ./tempest discovery:generate --no-interaction"
35+
```console
36+
./tempest discovery:generate --no-interaction
37+
3638
Clearing discovery cache <dim>.....................................</dim> <strong>2025-12-30 15:51:46</strong>
3739
Clearing discovery cache <dim>.....................................</dim> <strong>DONE</strong>
3840
Generating discovery cache using the `full` strategy <dim>.........</dim> <strong>2025-12-30 15:51:46</strong>

docs/2-features/13-static-pages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The only thing left to do is to generate the static pages:
113113

114114
## Crawling for dead links
115115

116-
Optionally, you can instruct the static generate to crawl your pages to scan for dead links. This is done by passing the `--crawl` option to the `static:generate` command:
116+
Optionally, you can instruct the static generate to crawl your pages to scan for dead links. This is done by passing the `--crawl` option to the `{txt}static:generate` command:
117117

118118
```console
119119
<dim>./tempest static:generate --crawl</dim>
@@ -127,6 +127,6 @@ By default, the crawler will only check for internal dead links. If you want to
127127

128128
## Production
129129

130-
Static pages are generated in the `/public` directory, as `index.html` files. Most web servers will automatically serve these static pages for you without any additional setup.
130+
Static pages are generated in the `{txt}/public` directory, as `index.html` files. Most web servers will automatically serve these static pages for you without any additional setup.
131131

132132
Note that static pages are meant to be generated as part of your deployment script. That means the `{txt}./tempest static:generate` command should be in your deployment pipeline.

docs/3-packages/01-highlight.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: "Tempest's highlighter is a package for server-side, high-performan
77

88
Require `tempest/highlight` with composer:
99

10-
```
10+
```console
1111
composer require tempest/highlight
1212
```
1313

docs/3-packages/03-responsive-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: "A standalone package to render responsive images"
66

77
## Quickstart
88

9-
```
9+
```console
1010
composer require tempest/responsive-image
1111
```
1212

docs/3-packages/04-markdown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: "Fast and extensible Markdown in PHP"
77

88
## Quickstart
99

10-
```sh
10+
```console
1111
composer require tempest/markdown
1212
```
1313

docs/5-extra-topics/04-contributing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ Even though we release on a non-fixed schedule, we do assign deadlines to the `n
326326

327327
### Colors
328328

329-
<span class="swatch" style="--color: #1b1429">#1b1429</span>
330-
<span class="swatch" style="--color: #29abe2">#29abe2</span>
331-
<span class="swatch" style="--color: #00e7ff">#00e7ff</span>
332-
<span class="swatch" style="--color: #0071bc">#0071bc</span>
329+
- <span class="swatch" style="--color: #1b1429">#1b1429</span>
330+
- <span class="swatch" style="--color: #29abe2">#29abe2</span>
331+
- <span class="swatch" style="--color: #00e7ff">#00e7ff</span>
332+
- <span class="swatch" style="--color: #0071bc">#0071bc</span>

0 commit comments

Comments
 (0)