htmx 0.2.1 → 0.4.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: 43814b022ac875bff7a54e57794a90f77a2dbe239f34158883062aa947e0e799
4
- data.tar.gz: 5d68ef44732add00a2bc32048aa668907d50fe720dc1b1b5786c3d2d3ec3b0c0
3
+ metadata.gz: 65dd7e62da5f84c05bee2472e6894ad14b93b3ed302102d77c05538fb0c95edb
4
+ data.tar.gz: cae8715c6576a53c2e0adbeb4206f795add1ef4360eda4b6503046610caa374e
5
5
  SHA512:
6
- metadata.gz: 756f8ba0a3ffd08b05022afc74984fd633d10fe1f8e02a011e6d3468902ac58df581fea26fe2070c4ad3a23fdd7a16acadbb0f321b007e5be80bcdd68e8e000f
7
- data.tar.gz: a01b465b9bbf9f89b780d69ed007e99af2f6da5ad62b4928b6dea2dff10fba8c6662913e9ac7f975990beea2735f331ee9567486b24fd5b58d370acf4ad429ec
6
+ metadata.gz: 62e06efdbcb28a141d685397a1c1bd90b25f8f619a921b974a07d92ee4cd5ea60737de5563e1fe5df28b536d8c251ec0a8aa4e8e1bc0e32986c8f2d6296cb921
7
+ data.tar.gz: 2c41fb9b95e4cd6c476aecc1264c61319cdfa138c760b23be5697616738092a42212ef5fe738fb4111a9fbbc73dde2accdac9936275553238a376ccdfa747e10
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.4.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/lib/htmx.rb CHANGED
@@ -2,13 +2,17 @@
2
2
 
3
3
  require "zeitwerk"
4
4
 
5
- Zeitwerk::Loader.for_gem.then do |loader|
5
+ Zeitwerk::Loader.new.then do |loader|
6
6
  loader.inflector.inflect "htmx" => "HTMX"
7
+ loader.tag = File.basename __FILE__, ".rb"
8
+ loader.push_dir __dir__
7
9
  loader.setup
8
10
  end
9
11
 
10
12
  # Main namespace.
11
13
  module HTMX
14
+ def self.loader(registry = Zeitwerk::Registry) = registry.loader_for __FILE__
15
+
12
16
  def self.[](...)
13
17
  @prefixer ||= Prefixer.new
14
18
  @prefixer.call(...)
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.4.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-10-01 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.20
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