htmx 0.2.1 → 0.3.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: 43814b022ac875bff7a54e57794a90f77a2dbe239f34158883062aa947e0e799
4
- data.tar.gz: 5d68ef44732add00a2bc32048aa668907d50fe720dc1b1b5786c3d2d3ec3b0c0
3
+ metadata.gz: e3bf798de3b7a08abddf9e0ebf6a46896889f08a815ea252310e43fdaf60e1b3
4
+ data.tar.gz: '0974300668c259fc13323bde4cf337ac9d3e87201ec07e1b0aa879346557d881'
5
5
  SHA512:
6
- metadata.gz: 756f8ba0a3ffd08b05022afc74984fd633d10fe1f8e02a011e6d3468902ac58df581fea26fe2070c4ad3a23fdd7a16acadbb0f321b007e5be80bcdd68e8e000f
7
- data.tar.gz: a01b465b9bbf9f89b780d69ed007e99af2f6da5ad62b4928b6dea2dff10fba8c6662913e9ac7f975990beea2735f331ee9567486b24fd5b58d370acf4ad429ec
6
+ metadata.gz: 91017541f831aba6aab0050a3b43c31f3020507a02f88e7aeb3f989c3884eadc1ede315abbce4f68a7be0a640594917c525683c86fafdaa1ca966b901f0299e8
7
+ data.tar.gz: cc38ff860e9450c0f72308be687a41c27a23ffb30ec1c0239963add89638b294a0198bc3dba8275e2058090cf1712399e5c2b6116dc4546d5f0a8a0488805725
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -84,7 +84,7 @@ One of the first tasks you'll want to tackle, when working with the {htmx_link}
84
84
 
85
85
  [source,ruby]
86
86
  ----
87
- html.button(
87
+ tag.button(
88
88
  "Delete",
89
89
  class: "button decline",
90
90
  type: "submit",
@@ -111,7 +111,7 @@ As shown above, building HTMX attributes takes minimal effort but if you'd prefe
111
111
  ----
112
112
  prefixer = HTMX::Prefixer.new "data-hx"
113
113
 
114
- html.button(
114
+ tag.button(
115
115
  "Delete",
116
116
  class: "button decline",
117
117
  type: "submit",
@@ -151,13 +151,21 @@ HTMX::Prefixer.new "bogus"
151
151
  # Invalid prefix: "bogus". Use: "hx" or "data-hx". (HTMX::Error)
152
152
  ----
153
153
 
154
+ 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 and example using both a string and symbol for keys:
155
+
156
+ [source,ruby]
157
+ ----
158
+ HTMX["swap-oob" => true, push_url: "/demo/123"]
159
+ # {"hx-swap-oob"=>true, "hx-push-url"=>"/demo/123"}
160
+ ----
161
+
154
162
  === HTTP Headers
155
163
 
156
164
  When working with HTTP requests/responses, especially HTTP headers, there are a few objects that can parse and make the data easier to work with. These objects are named accordingly: request and response. Here's how to use them.
157
165
 
158
166
  ==== Request
159
167
 
160
- The request object allows you to obtain an immutable {data_link} object to interact with when parsing link:https://htmx.org/reference/#request_headers[HTMX HTTP request headers]. Example:
168
+ The request object allows you to obtain a {data_link} object to interact with when parsing link:https://htmx.org/reference/#request_headers[HTMX HTTP request headers]. Example:
161
169
 
162
170
  [source,ruby]
163
171
  ----
@@ -195,7 +203,7 @@ With the above, the `.for` method plucks out only the HTMX specific headers whic
195
203
 
196
204
  ==== Response
197
205
 
198
- The response object allows you to obtain an immutable {data_link} object to interact with when parsing link:https://htmx.org/reference/#response_headers[HTMX HTTP response headers]. Example:
206
+ The response object allows you to obtain a {data_link} object to interact with when parsing link:https://htmx.org/reference/#response_headers[HTMX HTTP response headers]. Example:
199
207
 
200
208
  [source,ruby]
201
209
  ----
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 = "0.2.1"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/htmx"
@@ -3,14 +3,14 @@
3
3
  module HTMX
4
4
  module Headers
5
5
  REQUEST_KEY_MAP = {
6
- "HX-Boosted" => :boosted,
7
- "HX-Current-URL" => :current_url,
8
- "HX-History-Restore-Request" => :history_restore_request,
9
- "HX-Prompt" => :prompt,
10
- "HX-Request" => :request,
11
- "HX-Target" => :target,
12
- "HX-Trigger-Name" => :trigger_name,
13
- "HX-Trigger" => :trigger
6
+ "HTTP_HX_BOOSTED" => :boosted,
7
+ "HTTP_HX_CURRENT_URL" => :current_url,
8
+ "HTTP_HX_HISTORY_RESTORE_REQUEST" => :history_restore_request,
9
+ "HTTP_HX_PROMPT" => :prompt,
10
+ "HTTP_HX_REQUEST" => :request,
11
+ "HTTP_HX_TARGET" => :target,
12
+ "HTTP_HX_TRIGGER_NAME" => :trigger_name,
13
+ "HTTP_HX_TRIGGER" => :trigger
14
14
  }.freeze
15
15
 
16
16
  # Models the supported HTMX request headers.
@@ -28,6 +28,10 @@ module HTMX
28
28
  new(**attributes.slice(*key_map.keys).transform_keys!(key_map))
29
29
  end
30
30
 
31
+ def self.key_for(header, key_map: REQUEST_KEY_MAP) = key_map.fetch header
32
+
33
+ def self.header_for(key, key_map: REQUEST_KEY_MAP.invert) = key_map.fetch key
34
+
31
35
  def initialize boosted: nil,
32
36
  current_url: nil,
33
37
  history_restore_request: nil,
@@ -32,6 +32,10 @@ module HTMX
32
32
  new(**attributes.slice(*key_map.keys).transform_keys!(key_map))
33
33
  end
34
34
 
35
+ def self.key_for(header, key_map: RESPONSE_KEY_MAP) = key_map.fetch header
36
+
37
+ def self.header_for(key, key_map: RESPONSE_KEY_MAP.invert) = key_map.fetch key
38
+
35
39
  def initialize location: nil,
36
40
  push_url: nil,
37
41
  redirect: nil,
data/lib/htmx/prefixer.rb CHANGED
@@ -15,7 +15,7 @@ module HTMX
15
15
  validate
16
16
  end
17
17
 
18
- def call(**attributes) = attributes.transform_keys! { |key| "#{default}-#{key}" }
18
+ def call(**attributes) = attributes.transform_keys! { |key| "#{default}-#{key}".tr "_", "-" }
19
19
 
20
20
  private
21
21
 
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: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-06-19 00:00:00.000000000 Z
38
+ date: 2023-08-11 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: refinements
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.4.14
111
+ rubygems_version: 3.4.18
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: An augmenter and companion to the HTMX JavaScript library.
metadata.gz.sig CHANGED
Binary file