htmx 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43e9bb667215224c821dacc90e470dc7d7cff8763db175976e8f50a4914d9ff0
4
- data.tar.gz: 87bcf2eda837ccde944a18824f2f8268f2d1688999ae2b50136daec486fb72a4
3
+ metadata.gz: e3bf798de3b7a08abddf9e0ebf6a46896889f08a815ea252310e43fdaf60e1b3
4
+ data.tar.gz: '0974300668c259fc13323bde4cf337ac9d3e87201ec07e1b0aa879346557d881'
5
5
  SHA512:
6
- metadata.gz: 96f0e5a903c20d736a57a001351e020277ad988bd7fe08277994f1d0708a2765accd3a6e642e74bcd63905f36f1bfc01e12a90072151f67544ae8aa2c78a5407
7
- data.tar.gz: 110d7c8385ab152d67f2639d51c27f5c9e5bd3bbd72384e35cc191771c5574ebf195d5135852b6e0ff79048e9d35ccf35b04326e31ca7c19249f1bc1e7f40839
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.0"
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.0
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-13 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