htmx 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +83 -112
- data/htmx.gemspec +1 -1
- data/lib/htmx/headers/request.rb +3 -6
- data/lib/htmx/headers/response.rb +2 -3
- data/lib/htmx/prefixer.rb +1 -1
- data/lib/htmx.rb +5 -7
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50c33b7b7ca6ae9489a2eb63351895fdc864cf05781a414ac73cfdb68e31f0ce
|
|
4
|
+
data.tar.gz: 46cebdcd6a7b3aa2d49579d1c9f7265ea58e61eff0deb8cf0543a32bc81cb826
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92b3738d23693abea58cfaf2bda24de25a2a6d4665de3d704b9d1b6a602a0a21847a1d4b66d35af78b0c6c1f958a72dd3f7459cccdbd9ff4cdb415fb95b8c828
|
|
7
|
+
data.tar.gz: 6756800fe20f0bbdc67897108e11e5ce43c65830d07f8fa6ecbae315446445cdbf3ef21a1a41f3e9fa6c00f31c314dc26e972cf44a44543c4875cf4da5ac83ee
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -3,12 +3,8 @@
|
|
|
3
3
|
:figure-caption!:
|
|
4
4
|
|
|
5
5
|
:data_link: link:https://alchemists.io/articles/ruby_data[Data]
|
|
6
|
-
:
|
|
7
|
-
:hanami_views_link: link:https://alchemists.io/articles/hanami_views[Hanami Views]
|
|
8
|
-
:hanamismith_link: link:https://alchemists.io/projects/hanamismith[Hanamismith]
|
|
9
|
-
:htmx_link: link:https://htmx.org[htmx]
|
|
6
|
+
:htmx_link: link:https://four.htmx.org[htmx]
|
|
10
7
|
:hypermedia_systems_link: link:https://hypermedia.systems[Hypermedia Systems]
|
|
11
|
-
:roda_link: link:http://roda.jeremyevans.net[Roda]
|
|
12
8
|
|
|
13
9
|
= HTMX
|
|
14
10
|
|
|
@@ -26,18 +22,15 @@ ____
|
|
|
26
22
|
The goal of [htmx] is not less JavaScript, but less code, more readable and hypermedia-friendly code.
|
|
27
23
|
____
|
|
28
24
|
|
|
29
|
-
|
|
30
25
|
This gem provides native Ruby support for the {htmx_link} JavaScript library so you can build sophisticated web applications using pure Hypermedia REST APIs while avoiding unnecessary bloat and complexity common with the JavaScript ecosystem. By building upon the original foundations of Hypermedia REST APIs, you can build rich web applications with no additional JavaScript!
|
|
31
26
|
|
|
32
|
-
💡 This is used with the {hanamismith_link} gem when building {hanami_link} applications.
|
|
33
|
-
|
|
34
27
|
toc::[]
|
|
35
28
|
|
|
36
29
|
== Features
|
|
37
30
|
|
|
38
31
|
- Augments the {htmx_link} JavaScript library.
|
|
39
|
-
-
|
|
40
|
-
- Compatible with
|
|
32
|
+
- Enhances {htmx_link} development.
|
|
33
|
+
- Compatible with any web framework.
|
|
41
34
|
|
|
42
35
|
== Requirements
|
|
43
36
|
|
|
@@ -79,73 +72,50 @@ require "htmx"
|
|
|
79
72
|
|
|
80
73
|
== Usage
|
|
81
74
|
|
|
82
|
-
One of the first tasks
|
|
75
|
+
One of the first tasks, when working with the {htmx_link} library, is building htmx specific HTML attributes. This can be accomplished by using the `.[]` method. Example:
|
|
83
76
|
|
|
84
77
|
[source,ruby]
|
|
85
78
|
----
|
|
86
|
-
|
|
87
|
-
"Delete",
|
|
88
|
-
class: "button decline",
|
|
89
|
-
type: "submit",
|
|
90
|
-
**HTMX[target: "closest .task", delete: "/tasks/#{value.id}"]
|
|
91
|
-
)
|
|
92
|
-
----
|
|
79
|
+
HTMX[target: "closest .task", delete: "/tasks/1"]
|
|
93
80
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<button class="button decline" type="submit" hx-target="closest .task" hx-delete="/tasks/1">
|
|
99
|
-
Delete
|
|
100
|
-
</button>
|
|
81
|
+
# {
|
|
82
|
+
# "data-hx-target" => "closest .task",
|
|
83
|
+
# "data-hx-delete" => "/tasks/1"
|
|
84
|
+
# }
|
|
101
85
|
----
|
|
102
86
|
|
|
103
|
-
Notice the appropriate htmx
|
|
87
|
+
Notice the appropriate htmx `+data-hx*+` attributes are built which are compatible with the {htmx_link} library while not having to manually prefix each one of these attributes with the `hx-data-` prefix. You can use symbols, strings, or a mix of both as well.
|
|
104
88
|
|
|
105
89
|
=== HTML Attribute Prefixes
|
|
106
90
|
|
|
107
|
-
As shown above, building htmx attributes takes minimal effort but if you'd prefer the HTML `
|
|
91
|
+
As shown above, building htmx attributes takes minimal effort but if you'd prefer to only use the HTML `hx-` prefix, which the {htmx_link} library supports, you can customize by using the following:
|
|
108
92
|
|
|
109
93
|
[source,ruby]
|
|
110
94
|
----
|
|
111
|
-
prefixer = HTMX::Prefixer.new "
|
|
112
|
-
|
|
113
|
-
tag.button(
|
|
114
|
-
"Delete",
|
|
115
|
-
class: "button decline",
|
|
116
|
-
type: "submit",
|
|
117
|
-
**prefixer.call(target: "closest .task", delete: "/tasks/#{value.id}")
|
|
118
|
-
)
|
|
119
|
-
----
|
|
120
|
-
|
|
121
|
-
This will produce the following HTML code:
|
|
95
|
+
prefixer = HTMX::Prefixer.new "hx"
|
|
96
|
+
prefixer.call(target: "closest .task", delete: "/tasks/1")
|
|
122
97
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
data-hx-target="closest .task"
|
|
128
|
-
data-hx-delete="/tasks/1"
|
|
129
|
-
>
|
|
130
|
-
Delete
|
|
131
|
-
</button>
|
|
98
|
+
# {
|
|
99
|
+
# "hx-target" => "closest .task",
|
|
100
|
+
# "hx-delete" => "/tasks/1"
|
|
101
|
+
# }
|
|
132
102
|
----
|
|
133
103
|
|
|
134
|
-
As you can see,
|
|
104
|
+
As you can see, only `+hx-*+` keys are produced. By the way, the `HTMX::Prefixer` is called when using the htmx `.[]` as shown earlier. This means the following are equivalent:
|
|
135
105
|
|
|
136
106
|
[source,ruby]
|
|
137
107
|
----
|
|
138
108
|
HTMX[delete: "/tasks/1"]
|
|
139
109
|
HTMX::Prefixer.new.call delete: "/tasks/1"
|
|
140
|
-
HTMX::Prefixer.new("hx").call delete: "/tasks/1"
|
|
110
|
+
HTMX::Prefixer.new("data-hx").call delete: "/tasks/1"
|
|
141
111
|
----
|
|
142
112
|
|
|
143
113
|
All three of the above will produce the same output which means you'll most likely want to use the `.[]` method since it has the shortest syntax. If you attempt to use an unsupported prefix, you'll get an error:
|
|
144
114
|
|
|
145
115
|
[source,ruby]
|
|
146
116
|
----
|
|
147
|
-
HTMX::Prefixer.new
|
|
148
|
-
# Invalid prefix:
|
|
117
|
+
HTMX::Prefixer.new :bogus
|
|
118
|
+
# Invalid prefix: :bogus. Use: "hx" or "data-hx". (HTMX::Error)
|
|
149
119
|
----
|
|
150
120
|
|
|
151
121
|
Some {htmx_link} attributes use dashes. For those situations, you can use strings for keys or underscored symbols to produce the correct htmx syntax. Here's an example using both a string and symbol for keys:
|
|
@@ -153,7 +123,11 @@ Some {htmx_link} attributes use dashes. For those situations, you can use string
|
|
|
153
123
|
[source,ruby]
|
|
154
124
|
----
|
|
155
125
|
HTMX["swap-oob" => true, push_url: "/demo/123"]
|
|
156
|
-
|
|
126
|
+
|
|
127
|
+
# {
|
|
128
|
+
# "data-hx-swap-oob" => true,
|
|
129
|
+
# "data-hx-push-url" => "/demo/123"
|
|
130
|
+
# }
|
|
157
131
|
----
|
|
158
132
|
|
|
159
133
|
=== HTTP Headers
|
|
@@ -168,14 +142,14 @@ The request object allows you to obtain a {data_link} object to interact with wh
|
|
|
168
142
|
----
|
|
169
143
|
HTMX.request
|
|
170
144
|
|
|
171
|
-
#
|
|
172
|
-
#
|
|
173
|
-
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
145
|
+
# #<data HTMX::Headers::Request:0x00000a10
|
|
146
|
+
# boosted = nil,
|
|
147
|
+
# current_url = nil,
|
|
148
|
+
# history_restore_request = nil,
|
|
149
|
+
# request = nil,
|
|
150
|
+
# request_type = nil,
|
|
151
|
+
# source = nil,
|
|
152
|
+
# target = nil
|
|
179
153
|
# >
|
|
180
154
|
----
|
|
181
155
|
|
|
@@ -186,20 +160,19 @@ Notice you get a {data_link} instance where all members have the `HX-` prefix re
|
|
|
186
160
|
HTMX.request "HTTP_HX_BOOSTED" => "true",
|
|
187
161
|
"HTTP_HX_CURRENT_URL" => "/demo",
|
|
188
162
|
"HTTP_HX_HISTORY_RESTORE_REQUEST" => "false",
|
|
189
|
-
"HTTP_HX_PROMPT" => "Yes",
|
|
190
163
|
"HTTP_HX_REQUEST" => "true",
|
|
191
|
-
"
|
|
192
|
-
"
|
|
164
|
+
"HTTP_HX_REQUEST_TYPE" => "partial",
|
|
165
|
+
"HTTP_HX_SOURCE" => "button",
|
|
193
166
|
"HTTP_HX_TRIGGER" => "demo"
|
|
194
167
|
|
|
195
|
-
#
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
168
|
+
# #<data HTMX::Headers::Request:0x00000a80
|
|
169
|
+
# boosted = "true",
|
|
170
|
+
# current_url = "/demo",
|
|
171
|
+
# history_restore_request = "false",
|
|
172
|
+
# request = "true",
|
|
173
|
+
# request_type = "partial",
|
|
174
|
+
# source = "button",
|
|
175
|
+
# target = nil
|
|
203
176
|
# >
|
|
204
177
|
----
|
|
205
178
|
|
|
@@ -212,21 +185,17 @@ As an added convenience, you can use predicate methods for boolean values. Examp
|
|
|
212
185
|
headers = HTMX.request "HTTP_HX_BOOSTED" => "true",
|
|
213
186
|
"HTTP_HX_CURRENT_URL" => "/demo",
|
|
214
187
|
"HTTP_HX_HISTORY_RESTORE_REQUEST" => "false",
|
|
215
|
-
"HTTP_HX_PROMPT" => "Yes",
|
|
216
188
|
"HTTP_HX_REQUEST" => "true",
|
|
217
|
-
"
|
|
218
|
-
"
|
|
189
|
+
"HTTP_HX_REQUEST_TYPE" => "partial",
|
|
190
|
+
"HTTP_HX_SOURCE" => "button",
|
|
219
191
|
"HTTP_HX_TRIGGER" => "demo"
|
|
220
192
|
|
|
221
193
|
headers.boosted? # true
|
|
222
|
-
headers.confirmed? # true
|
|
223
194
|
headers.history_restore_request? # false
|
|
224
195
|
headers.request? # true
|
|
225
196
|
----
|
|
226
197
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
Due to `HTML.request` delegating to the `HTMX::Headers::Request`, this means you can use the object directly. Specifically, you can obtain the record, key, or header depending on your needs. Example:
|
|
198
|
+
Due to the `HTML.request` delegating to the `HTMX::Headers::Request`, this means you can use the object directly. Specifically, you can obtain the record, key, or header depending on your needs. Example:
|
|
230
199
|
|
|
231
200
|
[source,ruby]
|
|
232
201
|
----
|
|
@@ -241,14 +210,14 @@ Should you not want to use `HTMX::Headers::Request`, you can use the request pre
|
|
|
241
210
|
----
|
|
242
211
|
headers = {}
|
|
243
212
|
|
|
244
|
-
HTMX.request! headers, boosted: true,
|
|
245
|
-
# {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
213
|
+
HTMX.request! headers, boosted: true, source: "button"
|
|
214
|
+
# {
|
|
215
|
+
# "HTTP_HX_BOOSTED" => true,
|
|
216
|
+
# "HTTP_HX_SOURCE" => "button"
|
|
217
|
+
# }
|
|
249
218
|
----
|
|
250
219
|
|
|
251
|
-
💡 `HTMX.request!`
|
|
220
|
+
💡 `HTMX.request!` mutates your original headers. Unknown attributes are merged as is.
|
|
252
221
|
|
|
253
222
|
==== Responses
|
|
254
223
|
|
|
@@ -258,16 +227,16 @@ The response object allows you to obtain a {data_link} object to interact with w
|
|
|
258
227
|
----
|
|
259
228
|
HTMX.response
|
|
260
229
|
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
230
|
+
# #<data HTMX::Headers::Response:0x00001830
|
|
231
|
+
# location = nil,
|
|
232
|
+
# push_url = nil,
|
|
233
|
+
# redirect = nil,
|
|
234
|
+
# refresh = nil,
|
|
235
|
+
# replace_url = nil,
|
|
236
|
+
# reselect = nil,
|
|
237
|
+
# reswap = nil,
|
|
238
|
+
# retarget = nil,
|
|
239
|
+
# trigger = nil
|
|
271
240
|
# >
|
|
272
241
|
----
|
|
273
242
|
|
|
@@ -280,22 +249,21 @@ HTMX.response "HX-Location" => "/",
|
|
|
280
249
|
"HX-Redirect" => "/demo",
|
|
281
250
|
"HX-Refresh" => "true",
|
|
282
251
|
"HX-Replace-Url" => "/demo",
|
|
252
|
+
"HX-Reselect" => "#demo",
|
|
283
253
|
"HX-Reswap" => "none",
|
|
284
254
|
"HX-Retarget" => ".demo",
|
|
285
|
-
"HX-Trigger" => "demo"
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
293
|
-
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
296
|
-
#
|
|
297
|
-
# trigger_after_settle="demo",
|
|
298
|
-
# trigger_after_swap="demo"
|
|
255
|
+
"HX-Trigger" => "demo"
|
|
256
|
+
|
|
257
|
+
# #<data HTMX::Headers::Response:0x00001850
|
|
258
|
+
# location = "/",
|
|
259
|
+
# push_url = "/demo",
|
|
260
|
+
# redirect = "/demo",
|
|
261
|
+
# refresh = "true",
|
|
262
|
+
# replace_url = "/demo",
|
|
263
|
+
# reselect = "#demo",
|
|
264
|
+
# reswap = "none",
|
|
265
|
+
# retarget = ".demo",
|
|
266
|
+
# trigger = "demo"
|
|
299
267
|
# >
|
|
300
268
|
----
|
|
301
269
|
|
|
@@ -325,14 +293,17 @@ Should you not want to use `HTMX::Headers::Response`, you can use the response p
|
|
|
325
293
|
----
|
|
326
294
|
headers = {}
|
|
327
295
|
|
|
328
|
-
HTMX.response! headers, location: "/", push_url: "/
|
|
329
|
-
# {
|
|
296
|
+
HTMX.response! headers, location: "/", push_url: "/demo"
|
|
297
|
+
# {
|
|
298
|
+
# "HX-Location" => "/",
|
|
299
|
+
# "HX-Push-Url" => "/demo"
|
|
300
|
+
# }
|
|
330
301
|
|
|
331
|
-
HTMX.response? headers, :push_url, "/
|
|
302
|
+
HTMX.response? headers, :push_url, "/demo" # true
|
|
332
303
|
HTMX.response? headers, :push_url, "/other" # false
|
|
333
304
|
----
|
|
334
305
|
|
|
335
|
-
💡 `HTMX.response!`
|
|
306
|
+
💡 `HTMX.response!` mutates your original headers. Unknown attributes are merged as is.
|
|
336
307
|
|
|
337
308
|
=== Errors
|
|
338
309
|
|
data/htmx.gemspec
CHANGED
data/lib/htmx/headers/request.rb
CHANGED
|
@@ -19,18 +19,15 @@ module HTMX
|
|
|
19
19
|
def initialize boosted: nil,
|
|
20
20
|
current_url: nil,
|
|
21
21
|
history_restore_request: nil,
|
|
22
|
-
prompt: nil,
|
|
23
22
|
request: nil,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
request_type: nil,
|
|
24
|
+
source: nil,
|
|
25
|
+
target: nil
|
|
27
26
|
super
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def boosted? = boosted == "true"
|
|
31
30
|
|
|
32
|
-
def confirmed? = prompt ? prompt.truthy? : false
|
|
33
|
-
|
|
34
31
|
def history_restore_request? = history_restore_request == "true"
|
|
35
32
|
|
|
36
33
|
def request? = request == "true"
|
data/lib/htmx/prefixer.rb
CHANGED
data/lib/htmx.rb
CHANGED
|
@@ -15,11 +15,10 @@ module HTMX
|
|
|
15
15
|
boosted: "HTTP_HX_BOOSTED",
|
|
16
16
|
current_url: "HTTP_HX_CURRENT_URL",
|
|
17
17
|
history_restore_request: "HTTP_HX_HISTORY_RESTORE_REQUEST",
|
|
18
|
-
prompt: "HTTP_HX_PROMPT",
|
|
19
18
|
request: "HTTP_HX_REQUEST",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
request_type: "HTTP_HX_REQUEST_TYPE",
|
|
20
|
+
source: "HTTP_HX_SOURCE",
|
|
21
|
+
target: "HTTP_HX_TARGET"
|
|
23
22
|
}.freeze
|
|
24
23
|
|
|
25
24
|
RESPONSE_MAP = {
|
|
@@ -28,11 +27,10 @@ module HTMX
|
|
|
28
27
|
redirect: "HX-Redirect",
|
|
29
28
|
refresh: "HX-Refresh",
|
|
30
29
|
replace_url: "HX-Replace-Url",
|
|
30
|
+
reselect: "HX-Reselect",
|
|
31
31
|
reswap: "HX-Reswap",
|
|
32
32
|
retarget: "HX-Retarget",
|
|
33
|
-
trigger: "HX-Trigger"
|
|
34
|
-
trigger_after_settle: "HX-Trigger-After-Settle",
|
|
35
|
-
trigger_after_swap: "HX-Trigger-After-Swap"
|
|
33
|
+
trigger: "HX-Trigger"
|
|
36
34
|
}.freeze
|
|
37
35
|
|
|
38
36
|
def self.loader registry = Zeitwerk::Registry
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: htmx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brooke Kuhlmann
|
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
104
104
|
- !ruby/object:Gem::Version
|
|
105
105
|
version: '0'
|
|
106
106
|
requirements: []
|
|
107
|
-
rubygems_version: 4.0.
|
|
107
|
+
rubygems_version: 4.0.20
|
|
108
108
|
specification_version: 4
|
|
109
109
|
summary: An augmenter and companion to the HTMX JavaScript library.
|
|
110
110
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|