|
89 | 89 | location: https://spec.hmpl-lang.dev
|
90 | 90 | copyright: false
|
91 | 91 | contributors: Anthony Max
|
92 |
| - date: 2025-05-12 |
| 92 | + date: 2025-05-21 |
93 | 93 | </pre>
|
94 | 94 | <link
|
95 | 95 | rel="icon"
|
@@ -1259,12 +1259,36 @@ <h1>indicators</h1>
|
1259 | 1259 | </p>
|
1260 | 1260 |
|
1261 | 1261 | <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 |
1263 | 1263 | static HTML markup. This markup is not interpreted or extended by the
|
1264 | 1264 | 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. |
1266 | 1268 | </p>
|
1267 | 1269 |
|
| 1270 | + <emu-example> |
| 1271 | + <pre><code class="html"> |
| 1272 | + {{#request |
| 1273 | + src="/api/test" |
| 1274 | + indicators=[ |
| 1275 | + { |
| 1276 | + trigger: "pending", |
| 1277 | + content: "<p>Loading...</p>" |
| 1278 | + }, |
| 1279 | + { |
| 1280 | + trigger: "rejected", |
| 1281 | + content: "<p>Error</p><button>reload</button>" |
| 1282 | + }, |
| 1283 | + { |
| 1284 | + trigger: "403", |
| 1285 | + content: "<p>Access error.</p>" |
| 1286 | + } |
| 1287 | + ] |
| 1288 | + }}{{/request}} |
| 1289 | + </code></pre> |
| 1290 | + </emu-example> |
| 1291 | + |
1268 | 1292 | <p>
|
1269 | 1293 | The <code>trigger</code> property specifies the status condition under
|
1270 | 1294 | which the associated <code>content</code> should be displayed. Its value
|
@@ -1647,6 +1671,79 @@ <h1>sanitize</h1>
|
1647 | 1671 | </emu-clause>
|
1648 | 1672 | </emu-clause>
|
1649 | 1673 |
|
| 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 | + <p>Loading...</p> |
| 1729 | + {{/indicator}} |
| 1730 | + {{#indicator trigger="rejected"}} |
| 1731 | + <p>An error occurred.</p> |
| 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 | + |
1650 | 1747 | <emu-clause id="sec-types">
|
1651 | 1748 | <h1>Type Definitions</h1>
|
1652 | 1749 |
|
|
0 commit comments