Skip to content

Commit 420813a

Browse files
committed
update docs
1 parent 3d4719e commit 420813a

File tree

2 files changed

+103
-9
lines changed

2 files changed

+103
-9
lines changed

www/app/docs/examples.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ const templateFn = compile(
2323
src="/api/test"
2424
after="click:.getHTML"
2525
repeat=false
26-
indicators=[
27-
{
28-
trigger: "pending",
29-
content: "<p>Loading...</p>"
30-
}
31-
]
3226
}}
27+
{ {#indicator trigger="pending"}}
28+
<p>Loading...</p>
29+
{{/indicator}}
3330
{{/request}}
3431
</div>`
3532
);

www/spec/src/index.html

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
location: https://spec.hmpl-lang.dev
9090
copyright: false
9191
contributors: Anthony Max
92-
date: 2025-05-12
92+
date: 2025-05-21
9393
</pre>
9494
<link
9595
rel="icon"
@@ -1259,12 +1259,36 @@ <h1>indicators</h1>
12591259
</p>
12601260

12611261
<p>
1262-
The value of the <code>content</code> property is a string containing
1262+
The <code>content</code> property must be a plain string containing
12631263
static HTML markup. This markup is not interpreted or extended by the
12641264
HMPL module, and therefore does not support HMPL-specific syntax or
1265-
dynamic bindings.
1265+
dynamic bindings. Additionally, the value must be a single-line string —
1266+
line breaks (e.g., <code>\n</code>) or other control characters are not
1267+
allowed.
12661268
</p>
12671269

1270+
<emu-example>
1271+
<pre><code class="html">
1272+
{{#request
1273+
src="/api/test"
1274+
indicators=[
1275+
{
1276+
trigger: "pending",
1277+
content: "&lt;p&gt;Loading...&lt;/p&gt;"
1278+
},
1279+
{
1280+
trigger: "rejected",
1281+
content: "&lt;p&gt;Error&lt;/p&gt;&lt;button&gt;reload&lt;/button&gt;"
1282+
},
1283+
{
1284+
trigger: "403",
1285+
content: "&lt;p&gt;Access error.&lt;/p&gt;"
1286+
}
1287+
]
1288+
}}{{/request}}
1289+
</code></pre>
1290+
</emu-example>
1291+
12681292
<p>
12691293
The <code>trigger</code> property specifies the status condition under
12701294
which the associated <code>content</code> should be displayed. Its value
@@ -1647,6 +1671,79 @@ <h1>sanitize</h1>
16471671
</emu-clause>
16481672
</emu-clause>
16491673

1674+
<emu-clause id="request-nested-blocks">
1675+
<h1>Request Nested Blocks</h1>
1676+
<p>
1677+
In addition to using configuration properties, the
1678+
<code>{{#request}}</code> block may include nested blocks that define
1679+
behavior or content directly within the template markup. These nested
1680+
blocks offer a more readable and expressive alternative to structured JSON
1681+
properties, and are typically used for specifying state-driven UI or
1682+
request-related logic in a declarative way.
1683+
</p>
1684+
1685+
<emu-clause id="indicator-block">
1686+
<h1>indicator</h1>
1687+
<p>
1688+
The <code>{{#indicator}}</code> block is a template-level equivalent to
1689+
an
1690+
<a href="#sec-indicators-property"><code>HMPLIndicator</code></a> object
1691+
within the <code>indicators</code> array. It enables authors to define
1692+
the <code>trigger</code> and the corresponding
1693+
<code>content</code> inline in the HTML template.
1694+
</p>
1695+
1696+
<p>
1697+
This block must be placed directly within a
1698+
<code>{{#request}}</code> block. Multiple indicator blocks can be used
1699+
to represent different request states.
1700+
</p>
1701+
1702+
<p>
1703+
The <code>trigger</code> attribute is required and supports the same
1704+
values as described in the
1705+
<a href="#sec-indicators-property">indicators section</a>.
1706+
</p>
1707+
1708+
<emu-note>
1709+
Internally, the HMPL parser transforms each
1710+
<code>{{#indicator}}</code> block into a corresponding
1711+
<code>HMPLIndicator</code> object in the <code>indicators</code> array.
1712+
This means the two approaches are equivalent in behavior, and authors
1713+
may choose the one that best suits their use case or style.
1714+
</emu-note>
1715+
1716+
<p>
1717+
The content inside an <code>{{#indicator}}</code> block is treated as
1718+
static HTML and rendered when the specified trigger condition is met.
1719+
HMPL syntax and nested <code>{{#request}}</code> or
1720+
<code>{{#indicator}}</code> blocks are not allowed inside indicator
1721+
content.
1722+
</p>
1723+
1724+
<emu-example>
1725+
<pre><code class="html">
1726+
{{#request src="/api/data"}}
1727+
{{#indicator trigger="pending"}}
1728+
&lt;p&gt;Loading...&lt;/p&gt;
1729+
{{/indicator}}
1730+
{{#indicator trigger="rejected"}}
1731+
&lt;p&gt;An error occurred.&lt;/p&gt;
1732+
{{/indicator}}
1733+
{{/request}}
1734+
</code></pre>
1735+
</emu-example>
1736+
1737+
<emu-note>
1738+
If both the <code>indicators</code> property and one or more
1739+
<code>{{#indicator}}</code> blocks are present in a single
1740+
<code>{{#request}}</code> block, the inline
1741+
<code>{{#indicator}}</code> blocks will take precedence and override the
1742+
<code>indicators</code> property.
1743+
</emu-note>
1744+
</emu-clause>
1745+
</emu-clause>
1746+
16501747
<emu-clause id="sec-types">
16511748
<h1>Type Definitions</h1>
16521749

0 commit comments

Comments
 (0)