htmx 3.3.0 → 4.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28115f83adf78c0ed1bbe634ab80d285859757595507610b5f39b10cd5280e9d
4
- data.tar.gz: 3e53ba954560c33e2067871cac00e9bbda41448f4f0fee881dc83309498fbeb6
3
+ metadata.gz: e5de5f961d32dc6dd0f37383f653b9dfefda215b75ed7cfb4a900fef784e961b
4
+ data.tar.gz: '096c3c5324e0c579428fad5141dca109a924579362575ef184f15886a21c5ea1'
5
5
  SHA512:
6
- metadata.gz: 541aa7f34eb8d3c213d389f51393f584ee5f4ac0a91f7e2dd23a95c6789fbef69353533eb55c655b55d4175d69ad05a0a76f994322f18eda890906134ff20fe0
7
- data.tar.gz: 5c45ef55e4f449829676084bba0d0439dfa94db341f071fec883ac8490c9f662694e3d594287a9b20acde820075bfa65858d8b584bed2acd9fc26d9a8ed81e3b
6
+ metadata.gz: 013fe91826e688042afd0251fc3782485bb5b1fba73362afc2d7fcea2e4e523c11263da7ca7cad2ff79abf63f0ed8c0b0226135af5ae1158a4bc2ab2a4b4bb7c
7
+ data.tar.gz: 7e90025f0b7bf908ad8f0b02eb324250f041b82e73ca7d1bfe94bb29b80bc1d01b5f135528f728e6870e004597589c48ed52648d3683f42ce75a34e28227510d
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
- :hanami_link: link:https://hanamirb.org[Hanami]
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
- - Speeds up {htmx_link} development.
40
- - Compatible with {hanami_link}, {roda_link}, and other web frameworks.
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 to tackle, when working with the {htmx_link} library, is building htmx specific HTML attributes. This can be accomplished by using the `.[]` method. For example, when implementing a {hanami_views_link} part, you could use the following:
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
- tag.button(
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
- The above would produce the following:
95
-
96
- [source,html]
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 `hx-target` and `hx-delete` 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-` prefix. You can use symbols, strings, or a mix of both as well.
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 `data-` prefix, which the {htmx_link} library supports, you can customize by using the following:
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 "data-hx"
95
+ prefixer = HTMX::Prefixer.new "hx"
96
+ prefixer.call(target: "closest .task", delete: "/tasks/1")
112
97
 
113
- tag.button(
114
- "Delete",
115
- class: "button decline",
116
- type: "submit",
117
- **prefixer.call(target: "closest .task", delete: "/tasks/#{value.id}")
118
- )
98
+ # {
99
+ # "hx-target" => "closest .task",
100
+ # "hx-delete" => "/tasks/1"
101
+ # }
119
102
  ----
120
103
 
121
- This will produce the following HTML code:
122
-
123
- [source,html]
124
- ----
125
- <button class="button decline"
126
- type="submit"
127
- data-hx-target="closest .task"
128
- data-hx-delete="/tasks/1"
129
- >
130
- Delete
131
- </button>
132
- ----
133
-
134
- As you can see, the `data-hx-target` and `data-hx-delete` keys are used. These are definitely more verbose than the `hx-` keys. By the way, the `HTMX::Prefixer` is called when using the htmx `.[]` as shown earlier. This means the following are equivalent:
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 "bogus"
148
- # Invalid prefix: "bogus". Use: "hx" or "data-hx". (HTMX::Error)
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
- # {"hx-swap-oob"=>true, "hx-push-url"=>"/demo/123"}
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
- # <data HTMX::Headers::Request boosted=nil,
172
- # current_url=nil,
173
- # history_restore_request=nil,
174
- # prompt=nil,
175
- # request=nil,
176
- # target=nil,
177
- # trigger_name=nil,
178
- # trigger=nil
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
- "HTTP_HX_TARGET" => "demo",
192
- "HTTP_HX_TRIGGER_NAME" => "save",
164
+ "HTTP_HX_REQUEST_TYPE" => "partial",
165
+ "HTTP_HX_SOURCE" => "button",
193
166
  "HTTP_HX_TRIGGER" => "demo"
194
167
 
195
- # <data HTMX::Headers::Request boosted="true",
196
- # current_url="/demo",
197
- # history_restore_request="false",
198
- # prompt="Yes",
199
- # request="true",
200
- # target="demo",
201
- # trigger_name="save",
202
- # trigger="demo"
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
- "HTTP_HX_TARGET" => "demo",
218
- "HTTP_HX_TRIGGER_NAME" => "save",
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
- Use of `#confirmed?` is the only unique predicate method since it answers a boolean based on the truthiness of the `HTTP_HX_PROMPT` header. For further details, see `String#truthy?` as provided by the link:https://alchemists.io/projects/refinements#_truthy[Refinements] gem.
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,19 @@ 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, prompt: "Yes"
245
- # {"HTTP_HX_BOOSTED" => true, "HTTP_HX_PROMPT" => "Yes"}
213
+ HTMX.request! headers, boosted: true, source: "button"
214
+ # {
215
+ # "HTTP_HX_BOOSTED" => true,
216
+ # "HTTP_HX_SOURCE" => "button"
217
+ # }
246
218
 
247
- HTMX.request? headers, :prompt, "Yes" # true
248
- HTMX.request? headers, :prompt, "On" # false
219
+ HTMX.request? headers, :source, "button" # true
220
+ HTMX.request? headers, :source, /but/ # true
221
+ HTMX.request? headers, :source, "input" # false
222
+ HTMX.request? headers, :source, /input/ # false
249
223
  ----
250
224
 
251
- 💡 `HTMX.request!` is designed to mutate your original headers. Unknown attributes are merged as is.
225
+ 💡 `HTMX.request!` mutates your original headers. Unknown attributes are merged as is.
252
226
 
253
227
  ==== Responses
254
228
 
@@ -258,16 +232,16 @@ The response object allows you to obtain a {data_link} object to interact with w
258
232
  ----
259
233
  HTMX.response
260
234
 
261
- # <data HTMX::Headers::Response location=nil,
262
- # push_url=nil,
263
- # redirect=nil,
264
- # refresh=nil,
265
- # replace_url=nil,
266
- # reswap=nil,
267
- # retarget=nil,
268
- # trigger=nil,
269
- # trigger_after_settle=nil,
270
- # trigger_after_swap=nil
235
+ # #<data HTMX::Headers::Response:0x00001830
236
+ # location = nil,
237
+ # push_url = nil,
238
+ # redirect = nil,
239
+ # refresh = nil,
240
+ # replace_url = nil,
241
+ # reselect = nil,
242
+ # reswap = nil,
243
+ # retarget = nil,
244
+ # trigger = nil
271
245
  # >
272
246
  ----
273
247
 
@@ -280,22 +254,21 @@ HTMX.response "HX-Location" => "/",
280
254
  "HX-Redirect" => "/demo",
281
255
  "HX-Refresh" => "true",
282
256
  "HX-Replace-Url" => "/demo",
257
+ "HX-Reselect" => "#demo",
283
258
  "HX-Reswap" => "none",
284
259
  "HX-Retarget" => ".demo",
285
- "HX-Trigger" => "demo",
286
- "HX-Trigger-After-Settle" => "demo",
287
- "HX-Trigger-After-Swap" => "demo"
288
-
289
- # <data HTMX::Headers::Response location="/",
290
- # push_url="/demo",
291
- # redirect="/demo",
292
- # refresh="true",
293
- # replace_url="/demo",
294
- # reswap="none",
295
- # retarget=".demo",
296
- # trigger="demo",
297
- # trigger_after_settle="demo",
298
- # trigger_after_swap="demo"
260
+ "HX-Trigger" => "demo"
261
+
262
+ # #<data HTMX::Headers::Response:0x00001850
263
+ # location = "/",
264
+ # push_url = "/demo",
265
+ # redirect = "/demo",
266
+ # refresh = "true",
267
+ # replace_url = "/demo",
268
+ # reselect = "#demo",
269
+ # reswap = "none",
270
+ # retarget = ".demo",
271
+ # trigger = "demo"
299
272
  # >
300
273
  ----
301
274
 
@@ -325,14 +298,19 @@ Should you not want to use `HTMX::Headers::Response`, you can use the response p
325
298
  ----
326
299
  headers = {}
327
300
 
328
- HTMX.response! headers, location: "/", push_url: "/test"
329
- # {"HX-Location" => "/", "HX-Push-Url" => "/test"}
301
+ HTMX.response! headers, location: "/", push_url: "/demo"
302
+ # {
303
+ # "HX-Location" => "/",
304
+ # "HX-Push-Url" => "/demo"
305
+ # }
330
306
 
331
- HTMX.response? headers, :push_url, "/test" # true
332
- HTMX.response? headers, :push_url, "/other" # false
307
+ HTMX.response? headers, :push_url, "/demo" # true
308
+ HTMX.response? headers, :push_url, /emo/ # true
309
+ HTMX.response? headers, :push_url, "/about" # false
310
+ HTMX.response? headers, :push_url, /about/ # false
333
311
  ----
334
312
 
335
- 💡 `HTMX.response!` is designed to mutate your original headers. Unknown attributes are merged as is.
313
+ 💡 `HTMX.response!` mutates your original headers. Unknown attributes are merged as is.
336
314
 
337
315
  === Errors
338
316
 
data/htmx.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "htmx"
5
- spec.version = "3.3.0"
5
+ spec.version = "4.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/htmx"
@@ -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
- target: nil,
25
- trigger_name: nil,
26
- trigger: nil
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"
@@ -17,11 +17,10 @@ module HTMX
17
17
  redirect: nil,
18
18
  refresh: nil,
19
19
  replace_url: nil,
20
+ reselect: nil,
20
21
  reswap: nil,
21
22
  retarget: nil,
22
- trigger: nil,
23
- trigger_after_settle: nil,
24
- trigger_after_swap: nil
23
+ trigger: nil
25
24
  super
26
25
  end
27
26
 
data/lib/htmx/prefixer.rb CHANGED
@@ -9,7 +9,7 @@ module HTMX
9
9
 
10
10
  ALLOWED = %w[hx data-hx].freeze
11
11
 
12
- def initialize default = "hx", allowed: ALLOWED
12
+ def initialize default = "data-hx", allowed: ALLOWED
13
13
  @default = default
14
14
  @allowed = allowed
15
15
  validate
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
- target: "HTTP_HX_TARGET",
21
- trigger_name: "HTTP_HX_TRIGGER_NAME",
22
- trigger: "HTTP_HX_TRIGGER"
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
@@ -48,7 +46,10 @@ module HTMX
48
46
 
49
47
  def self.request!(headers, **attributes) = headers.merge! attributes.transform_keys!(REQUEST_MAP)
50
48
 
51
- def self.request?(headers, key, value) = headers[REQUEST_MAP[key]] == value
49
+ def self.request? headers, key, value
50
+ resolved_value = headers[REQUEST_MAP[key]]
51
+ value.is_a?(Regexp) ? resolved_value.match?(value) : resolved_value == value
52
+ end
52
53
 
53
54
  def self.response(**) = Headers::Response.for(**)
54
55
 
@@ -56,5 +57,8 @@ module HTMX
56
57
  headers.merge! attributes.transform_keys!(RESPONSE_MAP)
57
58
  end
58
59
 
59
- def self.response?(headers, key, value) = headers[RESPONSE_MAP[key]] == value
60
+ def self.response? headers, key, value
61
+ resolved_value = headers[RESPONSE_MAP[key]]
62
+ value.is_a?(Regexp) ? resolved_value.match?(value) : resolved_value == value
63
+ end
60
64
  end
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: 3.3.0
4
+ version: 4.1.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.15
107
+ rubygems_version: 4.0.21
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