htmx 3.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 061d840aba4723239a393b8c8c304f0e4d6dca4b844fc990722e7d2aea9c8faf
4
- data.tar.gz: acefbda40ffe891e202f8f815f5d1936f295bab933aac5d2ddf32354c5f5e201
3
+ metadata.gz: 50c33b7b7ca6ae9489a2eb63351895fdc864cf05781a414ac73cfdb68e31f0ce
4
+ data.tar.gz: 46cebdcd6a7b3aa2d49579d1c9f7265ea58e61eff0deb8cf0543a32bc81cb826
5
5
  SHA512:
6
- metadata.gz: 24986b4cb5afa08aa1a0dc5b50ab785a09907253f731b1564a27bf64443843c5c547c1c9936c33e325a2e9fa68e0f4067eee82bcee12c4314336c56297357453
7
- data.tar.gz: 7bfa9f77727829e8f07b59bb8c916954f6700b3a3d57eb2f6ec2d857925d32959e5fd1242e0811eb8b11422d7ecb61f3502470477f1fa63425459a929d8f1c7f
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
- :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"
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
- [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>
98
+ # {
99
+ # "hx-target" => "closest .task",
100
+ # "hx-delete" => "/tasks/1"
101
+ # }
132
102
  ----
133
103
 
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,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, prompt: "Yes"
245
- # {"HTTP_HX_BOOSTED" => true, "HTTP_HX_PROMPT" => "Yes"}
246
-
247
- HTMX.request? headers, :prompt, "Yes" # true
248
- HTMX.request? headers, :prompt, "On" # false
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!` is designed to mutate your original headers. Unknown attributes are merged as is.
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
- # <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
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
- "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"
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: "/test"
329
- # {"HX-Location" => "/", "HX-Push-Url" => "/test"}
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, "/test" # true
302
+ HTMX.response? headers, :push_url, "/demo" # true
332
303
  HTMX.response? headers, :push_url, "/other" # false
333
304
  ----
334
305
 
335
- 💡 `HTMX.response!` is designed to mutate your original headers. Unknown attributes are merged as is.
306
+ 💡 `HTMX.response!` mutates your original headers. Unknown attributes are merged as is.
336
307
 
337
308
  === Errors
338
309
 
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.2.0"
5
+ spec.version = "4.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/htmx"
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = ">= 4.0"
26
26
 
27
27
  spec.add_dependency "refinements", "~> 14.0"
28
- spec.add_dependency "zeitwerk", "~> 2.7"
28
+ spec.add_dependency "zeitwerk", "~> 2.8"
29
29
 
30
30
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
31
31
  spec.files = Dir["*.gemspec", "lib/**/*"]
@@ -8,7 +8,7 @@ module HTMX
8
8
  Request = Data.define(*REQUEST_MAP.keys) do
9
9
  using Refinements::String
10
10
 
11
- def self.for(key_map: REQUEST_MAP.invert, **attributes)
11
+ def self.for key_map: REQUEST_MAP.invert, **attributes
12
12
  new(**attributes.slice(*key_map.keys).transform_keys!(key_map))
13
13
  end
14
14
 
@@ -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"
@@ -4,7 +4,7 @@ module HTMX
4
4
  module Headers
5
5
  # Models the supported HTMX response headers.
6
6
  Response = Data.define(*RESPONSE_MAP.keys) do
7
- def self.for(key_map: RESPONSE_MAP.invert, **attributes)
7
+ def self.for key_map: RESPONSE_MAP.invert, **attributes
8
8
  new(**attributes.slice(*key_map.keys).transform_keys!(key_map))
9
9
  end
10
10
 
@@ -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
@@ -52,7 +50,7 @@ module HTMX
52
50
 
53
51
  def self.response(**) = Headers::Response.for(**)
54
52
 
55
- def self.response!(headers, **attributes)
53
+ def self.response! headers, **attributes
56
54
  headers.merge! attributes.transform_keys!(RESPONSE_MAP)
57
55
  end
58
56
 
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.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -55,14 +55,14 @@ dependencies:
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: '2.7'
58
+ version: '2.8'
59
59
  type: :runtime
60
60
  prerelease: false
61
61
  version_requirements: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '2.7'
65
+ version: '2.8'
66
66
  email:
67
67
  - brooke@alchemists.io
68
68
  executables: []
@@ -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.10
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