Skip to content

Commit 23b25c1

Browse files
committed
Copied changes from hmpl/app
1 parent 1be9196 commit 23b25c1

File tree

6 files changed

+106
-2
lines changed

6 files changed

+106
-2
lines changed

astro.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ export default defineConfig({
137137
label: "indicators",
138138
link: "/block-helpers/request#indicators"
139139
},
140+
{
141+
label: "bind",
142+
link: "/block-helpers/request#bind",
143+
badge: { text: "new", variant: "note" }
144+
},
140145
{
141146
label: "autoBody",
142147
link: "/block-helpers/request#autobody"

src/components/HomePage.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
>Demo Sandbox</a
247247
>
248248
</div>
249+
<!--
249250
<a
250251
href="https://www.producthunt.com/products/hmpl-js?embed=true&utm_source=badge-featured&utm_medium=badge&utm_source=badge-hmpl&#0045;js"
251252
target="_blank"
@@ -256,7 +257,7 @@
256257
style="width: 250px; height: 54px"
257258
width="250"
258259
height="54"
259-
/></a>
260+
/></a> -->
260261
</div>
261262
</div>
262263
</div>

src/content/docs/block-helpers/request.mdx

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,74 @@ The content property must be a plain string containing static HTML markup. This
295295
296296
Additionally, the value must be a single-line string — line breaks (e.g., `\n`) or other control characters are not allowed.
297297
298+
## bind
299+
300+
The bind property binds the request status with the attribute value of the corresponding tag.
301+
302+
The property accepts either a string value or an [HMPLBindOptions](/types#hmplbindoptions) object that describes how the value for the attribute will be generated.
303+
304+
```hmpl
305+
<div class="{{requestStatus}} class1">Text</div>
306+
{{#request
307+
src="/api/getHTML"
308+
bind="{{requestStatus}}"
309+
}}{{/request}}
310+
```
311+
312+
The value itself is generated in the following form `${prefix}${target}-${status}`:
313+
314+
```hmpl
315+
<div class="hmpl-status-requestStatus-200 class1">Text</div>
316+
```
317+
318+
### Bind options
319+
320+
Settings object for each attribute value generation.
321+
322+
| Property | Type | Description | Required |
323+
| -------- | ------ | ------------------------------------------------------------------ | -------- |
324+
| target | string | A value that specifies which specific attribute to bind to | Yes |
325+
| prefix | string | A string that is added to the attribute value before target-status | No |
326+
327+
#### target
328+
329+
Specifies the binding target. The value is a string without spaces and unique for each block helper.
330+
331+
```hmpl
332+
<div class="{{requestStatus1}} {{requestStatus2}}">Text</div>
333+
<div class="{{requestStatus1}} {{requestStatus2}}">Text</div>
334+
{{#request
335+
src="/api/getHTML"
336+
bind={ target: "requestStatus1" }
337+
}}{{/request}}
338+
{{#request
339+
src="/api/getHTML"
340+
bind={ target: "requestStatus2" }
341+
}}{{/request}}
342+
```
343+
344+
Values ​​can be assigned to multiple attributes of multiple tags.
345+
346+
#### prefix
347+
348+
A string appended to the target and status in the attribute value. The value is not unique.
349+
350+
```hmpl
351+
<div class="{{requestStatus}}">Text</div>
352+
{{#request
353+
src="/api/getHTML"
354+
bind={ target: "requestStatus", prefix: "custom-prefix-" }
355+
}}{{/request}}
356+
```
357+
358+
The result of generating the value will be like this:
359+
360+
```hmpl
361+
<tag attr="custom-prefix-requestStatus-200">...</tag>
362+
```
363+
364+
The default value is `"hmpl-status-"`.
365+
298366
## autoBody
299367
300368
The autoBody property specifies automatic generation of the `body` property within a [RequestInit](/functions/template#requestinit) object.
@@ -357,7 +425,7 @@ As of the current specification, automatic body generation exclusively supports
357425
358426
### AutoBody options
359427
360-
Settings object for each automatic generation
428+
Settings object for each automatic generation.
361429
362430
| Property | Type | Description | Required |
363431
| -------- | ------- | -------------------------------------- | -------- |

src/content/docs/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ title: Changelog
33
description: Version history and updates for HMPL
44
---
55

6+
## 3.2.0 (2025-11-12)
7+
8+
- Adding the `bind` property
9+
- Correcting syntax errors
10+
- Adding `{{name}}` values ​​to attributes
11+
612
## 3.1.0 (2025-10-24)
713

814
- For the `get` function, instead of 4 arguments, we made a props object, which is convenient to work with.

src/content/docs/syntax/attribute.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,17 @@ The following types are supported in values: `string`, `array`, `boolean`, `obje
4747
## Peculiarities
4848

4949
Some attributes can be overwritten in block helpers. So, for example, if you write indicators as an attribute, and then specify nested indicators.
50+
51+
## External attribute values
52+
53+
Since version 3.2.0, the template language now supports the ability to create constructs with double quotes outside of block helpers. Now, tag attributes can specify names that are functionally related to server requests.
54+
55+
```hmpl
56+
<div class="{{requestStatus}} text">Some text</div>
57+
{{#request
58+
src="/api/hello"
59+
after="submit:#form"
60+
repeat=false
61+
bind="{{requestStatus}}"
62+
}}{{/request}}
63+
```

src/content/docs/types.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ interface HMPLRequestInfo {
9494
sanitize?: HMPLSanitize;
9595
disallowedTags?: HMPLDisallowedTags;
9696
autoBody?: boolean | HMPLAutoBodyOptions;
97+
bind?: string | HMPLBindOptions;
9798
}
9899
```
99100

@@ -144,6 +145,15 @@ interface HMPLAutoBodyOptions {
144145
}
145146
```
146147

148+
## HMPLBindOptions
149+
150+
```ts
151+
interface HMPLBindOptions {
152+
target: string;
153+
prefix?: string;
154+
}
155+
```
156+
147157
## HMPLInitalStatus
148158

149159
```ts

0 commit comments

Comments
 (0)