htmx 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +280 -0
- data/htmx.gemspec +31 -0
- data/lib/htmx/error.rb +7 -0
- data/lib/htmx/headers/request.rb +43 -0
- data/lib/htmx/headers/response.rb +49 -0
- data/lib/htmx/prefixer.rb +32 -0
- data/lib/htmx.rb +13 -0
- data.tar.gz.sig +0 -0
- metadata +115 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 383f09f05abca1f2fe9ec5344642b5df7186fe0a20897bb349300c836020b3e5
|
4
|
+
data.tar.gz: 933f33aa31997a1c23c96d78cc0a99a32f460260c78bcd555b0af6bfe887d485
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d01fe0fe6ff1424c22179559bd17d188718f0c4edb2e96d43b7c6acaa5beb7dc750ecfac2a95cefcd46b0bc24e4af786470d05a49c93095ed6a1b87e9bdf2bd0
|
7
|
+
data.tar.gz: 92e7dc0c6b33e262b50ec602e1285d888123cc194c68331584ff64d6d9d5f88457f1b9210c6d183e097e3b468c110ba13c6b30c49c561cabaf0b55e894247d7a
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/LICENSE.adoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Hippocratic License
|
2
|
+
|
3
|
+
Version: 2.1.0.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
11
|
+
liability.
|
12
|
+
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
21
|
+
following terms and conditions:
|
22
|
+
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
27
|
+
property right held by Licensor.
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
30
|
+
the License and the above copyright notice (and if included by the
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
+
free to create modifications of the Software and distribute only the
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
+
hereunder) shall end immediately.
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
+
[arabic]
|
44
|
+
. Human Rights Principles.
|
45
|
+
[loweralpha]
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
48
|
+
Compact that define recognized principles of international human rights
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
+
manner consistent with Human Rights Principles.
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
+
unless the Rules require otherwise.
|
63
|
+
+
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
+
documents and information concerning the arbitration shall be public and
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
88
|
+
apply.
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
+
Human Rights Principles.
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
+
the terms and conditions of this License against Licensee through
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
+
may not terminate this License with Licensee.
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
+
the court may modify this License to affect the original purpose that
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
+
against any party.
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
+
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
:htmx_link: link:https://htmx.org[HTMX]
|
6
|
+
:hypermedia_systems_link: link:https://hypermedia.systems[Hypermedia Systems]
|
7
|
+
:hanami_link: link:https://hanamirb.org[Hanami]
|
8
|
+
:roda_link: link:http://roda.jeremyevans.net[Roda]
|
9
|
+
:data_link: link:https://alchemists.io/articles/ruby_data[Data]
|
10
|
+
:hanamismith_link: link:https://alchemists.io/projects/hanamismith[Hanamismith]
|
11
|
+
|
12
|
+
= HTMX
|
13
|
+
|
14
|
+
A haiku from the {htmx_link} team:
|
15
|
+
|
16
|
+
____
|
17
|
+
javascript fatigue:
|
18
|
+
longing for a hypertext
|
19
|
+
already in hand
|
20
|
+
____
|
21
|
+
|
22
|
+
...and from {hypermedia_systems_link}:
|
23
|
+
|
24
|
+
____
|
25
|
+
The goal of [HTMX] is not less JavaScript, but less code, more readable and hypermedia-friendly code.
|
26
|
+
____
|
27
|
+
|
28
|
+
|
29
|
+
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 the unnecessary bloat and complexity common with JavaScript frameworks by building upon the original foundations of Hypermedia REST APIs. Even better, you can build rich web applications with no additional JavaScript!
|
30
|
+
|
31
|
+
At the moment, the functionality of this gem is still in the early stages of development but the goal of this gem is to aid with the development of {htmx_link} applications.
|
32
|
+
|
33
|
+
💡 This is used with the {hanamismith_link} gem when building {hanami_link} applications. Even better, you can play with the link:https://github.com/bkuhlmann/hemo[Hanami demo application] to learn more. Enjoy!
|
34
|
+
|
35
|
+
toc::[]
|
36
|
+
|
37
|
+
== Features
|
38
|
+
|
39
|
+
- Augments the {htmx_link} JavaScript library.
|
40
|
+
- Speeds up {htmx_link} development.
|
41
|
+
- Compatible with {hanami_link}, {roda_link}, and other web frameworks.
|
42
|
+
|
43
|
+
== Requirements
|
44
|
+
|
45
|
+
. {htmx_link}.
|
46
|
+
. A strong understanding of {hypermedia_systems_link} and Hypermedia REST APIs in general.
|
47
|
+
. link:https://www.ruby-lang.org[Ruby].
|
48
|
+
|
49
|
+
== Setup
|
50
|
+
|
51
|
+
To install _with_ security, run:
|
52
|
+
|
53
|
+
[source,bash]
|
54
|
+
----
|
55
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
56
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/projects/htmx/gems.pem)
|
57
|
+
gem install htmx --trust-policy HighSecurity
|
58
|
+
----
|
59
|
+
|
60
|
+
To install _without_ security, run:
|
61
|
+
|
62
|
+
[source,bash]
|
63
|
+
----
|
64
|
+
gem install htmx
|
65
|
+
----
|
66
|
+
|
67
|
+
You can also add the gem directly to your project:
|
68
|
+
|
69
|
+
[source,bash]
|
70
|
+
----
|
71
|
+
bundle add htmx
|
72
|
+
----
|
73
|
+
|
74
|
+
Once the gem is installed, you only need to require it:
|
75
|
+
|
76
|
+
[source,ruby]
|
77
|
+
----
|
78
|
+
require "htmx"
|
79
|
+
----
|
80
|
+
|
81
|
+
== Usage
|
82
|
+
|
83
|
+
One of the first tasks you'll want 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_link} view part, you could use the following:
|
84
|
+
|
85
|
+
[source,ruby]
|
86
|
+
----
|
87
|
+
html.button(
|
88
|
+
"Delete",
|
89
|
+
class: "button decline",
|
90
|
+
type: "submit",
|
91
|
+
**HTMX[target: "closest .task", delete: "/tasks/#{value.id}"]
|
92
|
+
)
|
93
|
+
----
|
94
|
+
|
95
|
+
The above would produce the following:
|
96
|
+
|
97
|
+
[source,html]
|
98
|
+
----
|
99
|
+
<button class="button decline" type="submit" hx-target="closest .task" hx-delete="/tasks/1">
|
100
|
+
Delete
|
101
|
+
</button>
|
102
|
+
----
|
103
|
+
|
104
|
+
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 even use symbols, strings, or a mix of both as well.
|
105
|
+
|
106
|
+
=== HTML Attribute Prefixes
|
107
|
+
|
108
|
+
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:
|
109
|
+
|
110
|
+
[source,ruby]
|
111
|
+
----
|
112
|
+
prefixer = HTMX::Prefixer.new "data-hx"
|
113
|
+
|
114
|
+
html.button(
|
115
|
+
"Delete",
|
116
|
+
class: "button decline",
|
117
|
+
type: "submit",
|
118
|
+
**prefixer.call(target: "closest .task", delete: "/tasks/#{value.id}")
|
119
|
+
)
|
120
|
+
----
|
121
|
+
|
122
|
+
This would then produce the following HTML code:
|
123
|
+
|
124
|
+
[source,html]
|
125
|
+
----
|
126
|
+
<button class="button decline"
|
127
|
+
type="submit"
|
128
|
+
data-hx-target="closest .task"
|
129
|
+
data-hx-delete="/tasks/1"
|
130
|
+
>
|
131
|
+
Delete
|
132
|
+
</button>
|
133
|
+
----
|
134
|
+
|
135
|
+
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:
|
136
|
+
|
137
|
+
[source,ruby]
|
138
|
+
----
|
139
|
+
HTMX[delete: "/tasks/1"]
|
140
|
+
HTMX::Prefixer.new.call delete: "/tasks/1"
|
141
|
+
HTMX::Prefixer.new("hx").call delete: "/tasks/1"
|
142
|
+
----
|
143
|
+
|
144
|
+
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.
|
145
|
+
|
146
|
+
If you attempt to use an unsupported prefix, you'll get an error:
|
147
|
+
|
148
|
+
[source,ruby]
|
149
|
+
----
|
150
|
+
HTMX::Prefixer.new "bogus"
|
151
|
+
# Invalid prefix: "bogus". Use: "hx" or "data-hx". (HTMX::Error)
|
152
|
+
----
|
153
|
+
|
154
|
+
=== HTTP Headers
|
155
|
+
|
156
|
+
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
|
+
|
158
|
+
==== Request
|
159
|
+
|
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:
|
161
|
+
|
162
|
+
[source,ruby]
|
163
|
+
----
|
164
|
+
request = HTMX::Headers::Request.new
|
165
|
+
|
166
|
+
# <data HTMX::Headers::Request boosted=nil,
|
167
|
+
# current_url=nil,
|
168
|
+
# history_restore_request=nil,
|
169
|
+
# prompt=nil,
|
170
|
+
# request=nil,
|
171
|
+
# target=nil,
|
172
|
+
# trigger_name=nil,
|
173
|
+
# trigger=nil
|
174
|
+
# >
|
175
|
+
----
|
176
|
+
|
177
|
+
Notice you get a {data_link} instance where all members have the `HX-` prefix removed while each value defaults to `nil`. Even better -- and more practical -- is you can ask the request object to parse the incoming HTTP headers directly and give you _exactly_ what you need:
|
178
|
+
|
179
|
+
[source,ruby]
|
180
|
+
----
|
181
|
+
request = HTMX::Headers::Request.for request.headers
|
182
|
+
|
183
|
+
# <data HTMX::Headers::Request boosted="true",
|
184
|
+
# current_url="/demo",
|
185
|
+
# history_restore_request=nil,
|
186
|
+
# prompt="Yes",
|
187
|
+
# request="true",
|
188
|
+
# target="demo",
|
189
|
+
# trigger_name="save",
|
190
|
+
# trigger="demo"
|
191
|
+
# >
|
192
|
+
----
|
193
|
+
|
194
|
+
With the above, the `.for` method plucks out only the HTMX specific headers which may or may not have values. Extra header keys, which are not specific to {htmx_link}, are ignored.
|
195
|
+
|
196
|
+
==== Response
|
197
|
+
|
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:
|
199
|
+
|
200
|
+
[source,ruby]
|
201
|
+
----
|
202
|
+
response = HTMX::Headers::Response.new
|
203
|
+
|
204
|
+
# <data HTMX::Headers::Response location=nil,
|
205
|
+
# push_url=nil,
|
206
|
+
# redirect=nil,
|
207
|
+
# refresh=nil,
|
208
|
+
# replace_url=nil,
|
209
|
+
# reswap=nil,
|
210
|
+
# retarget=nil,
|
211
|
+
# trigger=nil,
|
212
|
+
# trigger_after_settle=nil,
|
213
|
+
# trigger_after_swap=nil
|
214
|
+
# >
|
215
|
+
----
|
216
|
+
|
217
|
+
Notice you get a {data_link} instance where all members have the `HX-` prefix removed while each value defaults to `nil`. Even better -- and more practical -- is you can ask the response object to parse the incoming HTTP headers directly and give you _exactly_ what you need:
|
218
|
+
|
219
|
+
[source,ruby]
|
220
|
+
----
|
221
|
+
response = HTMX::Headers::Response.for response.headers
|
222
|
+
|
223
|
+
# <data HTMX::Headers::Response location="/",
|
224
|
+
# push_url="/demo",
|
225
|
+
# redirect="/demo",
|
226
|
+
# refresh="true",
|
227
|
+
# replace_url="/demo",
|
228
|
+
# reswap="none",
|
229
|
+
# retarget=".demo",
|
230
|
+
# trigger="demo",
|
231
|
+
# trigger_after_settle="demo",
|
232
|
+
# trigger_after_swap="demo"
|
233
|
+
# >
|
234
|
+
----
|
235
|
+
|
236
|
+
With the above, the `.for` method plucks out only the HTMX specific headers which may or may not have values. Extra header keys, which are not specific to {htmx_link}, are ignored.
|
237
|
+
|
238
|
+
== Development
|
239
|
+
|
240
|
+
To contribute, run:
|
241
|
+
|
242
|
+
[source,bash]
|
243
|
+
----
|
244
|
+
git clone https://github.com/bkuhlmann/htmx
|
245
|
+
cd htmx
|
246
|
+
bin/setup
|
247
|
+
----
|
248
|
+
|
249
|
+
You can also use the IRB console for direct access to all objects:
|
250
|
+
|
251
|
+
[source,bash]
|
252
|
+
----
|
253
|
+
bin/console
|
254
|
+
----
|
255
|
+
|
256
|
+
== Tests
|
257
|
+
|
258
|
+
To test, run:
|
259
|
+
|
260
|
+
[source,bash]
|
261
|
+
----
|
262
|
+
bin/rake
|
263
|
+
----
|
264
|
+
|
265
|
+
== link:https://alchemists.io/policies/license[License]
|
266
|
+
|
267
|
+
== link:https://alchemists.io/policies/security[Security]
|
268
|
+
|
269
|
+
== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
|
270
|
+
|
271
|
+
== link:https://alchemists.io/policies/contributions[Contributions]
|
272
|
+
|
273
|
+
== link:https://alchemists.io/projects/htmx/versions[Versions]
|
274
|
+
|
275
|
+
== link:https://alchemists.io/community[Community]
|
276
|
+
|
277
|
+
== Credits
|
278
|
+
|
279
|
+
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
|
280
|
+
* Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/htmx.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "htmx"
|
5
|
+
spec.version = "0.0.0"
|
6
|
+
spec.authors = ["Brooke Kuhlmann"]
|
7
|
+
spec.email = ["brooke@alchemists.io"]
|
8
|
+
spec.homepage = "https://alchemists.io/projects/htmx"
|
9
|
+
spec.summary = "Augmenter, enhancer, and companion to the HTMX JavaScript library."
|
10
|
+
spec.license = "Hippocratic-2.1"
|
11
|
+
|
12
|
+
spec.metadata = {
|
13
|
+
"bug_tracker_uri" => "https://github.com/bkuhlmann/htmx/issues",
|
14
|
+
"changelog_uri" => "https://alchemists.io/projects/htmx/versions",
|
15
|
+
"documentation_uri" => "https://alchemists.io/projects/htmx",
|
16
|
+
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
17
|
+
"label" => "HTMX",
|
18
|
+
"rubygems_mfa_required" => "true",
|
19
|
+
"source_code_uri" => "https://github.com/bkuhlmann/htmx"
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.signing_key = Gem.default_key_path
|
23
|
+
spec.cert_chain = [Gem.default_cert_path]
|
24
|
+
|
25
|
+
spec.required_ruby_version = "~> 3.2"
|
26
|
+
spec.add_dependency "refinements", "~> 10.0"
|
27
|
+
spec.add_dependency "zeitwerk", "~> 2.6"
|
28
|
+
|
29
|
+
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
30
|
+
spec.files = Dir["*.gemspec", "lib/**/*"]
|
31
|
+
end
|
data/lib/htmx/error.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HTMX
|
4
|
+
module Headers
|
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
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# Models the supported HTMX request headers.
|
17
|
+
Request = Data.define(
|
18
|
+
:boosted,
|
19
|
+
:current_url,
|
20
|
+
:history_restore_request,
|
21
|
+
:prompt,
|
22
|
+
:request,
|
23
|
+
:target,
|
24
|
+
:trigger_name,
|
25
|
+
:trigger
|
26
|
+
) do
|
27
|
+
def self.for(key_map: REQUEST_KEY_MAP, **attributes)
|
28
|
+
new(**attributes.slice(*key_map.keys).transform_keys(key_map))
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize boosted: nil,
|
32
|
+
current_url: nil,
|
33
|
+
history_restore_request: nil,
|
34
|
+
prompt: nil,
|
35
|
+
request: nil,
|
36
|
+
target: nil,
|
37
|
+
trigger_name: nil,
|
38
|
+
trigger: nil
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HTMX
|
4
|
+
module Headers
|
5
|
+
RESPONSE_KEY_MAP = {
|
6
|
+
"HX-Location" => :location,
|
7
|
+
"HX-Push-Url" => :push_url,
|
8
|
+
"HX-Redirect" => :redirect,
|
9
|
+
"HX-Refresh" => :refresh,
|
10
|
+
"HX-Replace-Url" => :replace_url,
|
11
|
+
"HX-Reswap" => :reswap,
|
12
|
+
"HX-Retarget" => :retarget,
|
13
|
+
"HX-Trigger" => :trigger,
|
14
|
+
"HX-Trigger-After-Settle" => :trigger_after_settle,
|
15
|
+
"HX-Trigger-After-Swap" => :trigger_after_swap
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
# Models the supported HTMX response headers.
|
19
|
+
Response = Data.define(
|
20
|
+
:location,
|
21
|
+
:push_url,
|
22
|
+
:redirect,
|
23
|
+
:refresh,
|
24
|
+
:replace_url,
|
25
|
+
:reswap,
|
26
|
+
:retarget,
|
27
|
+
:trigger,
|
28
|
+
:trigger_after_settle,
|
29
|
+
:trigger_after_swap
|
30
|
+
) do
|
31
|
+
def self.for(key_map: RESPONSE_KEY_MAP, **attributes)
|
32
|
+
new(**attributes.slice(*key_map.keys).transform_keys(key_map))
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize location: nil,
|
36
|
+
push_url: nil,
|
37
|
+
redirect: nil,
|
38
|
+
refresh: nil,
|
39
|
+
replace_url: nil,
|
40
|
+
reswap: nil,
|
41
|
+
retarget: nil,
|
42
|
+
trigger: nil,
|
43
|
+
trigger_after_settle: nil,
|
44
|
+
trigger_after_swap: nil
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/arrays"
|
4
|
+
|
5
|
+
module HTMX
|
6
|
+
# Prefixes HTML element attributes for proper consumption by HTMX JavaScript library.
|
7
|
+
class Prefixer
|
8
|
+
using Refinements::Arrays
|
9
|
+
|
10
|
+
PREFIXES = %w[hx data-hx].freeze
|
11
|
+
|
12
|
+
def initialize default = "hx", allowed: PREFIXES
|
13
|
+
@default = default
|
14
|
+
@allowed = allowed
|
15
|
+
validate
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(**attributes) = attributes.transform_keys! { |key| "#{default}-#{key}" }
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :default, :allowed
|
23
|
+
|
24
|
+
def validate
|
25
|
+
return true if allowed.include? default
|
26
|
+
|
27
|
+
usage = allowed.map(&:inspect).to_sentence conjunction: "or"
|
28
|
+
|
29
|
+
fail Error, "Invalid prefix: #{default.inspect}. Use: #{usage}."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/htmx.rb
ADDED
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brooke Kuhlmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEeDCCAuCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
|
14
|
+
a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
|
15
|
+
aW8wHhcNMjMwMzIyMTYxNDQxWhcNMjUwMzIxMTYxNDQxWjBBMQ8wDQYDVQQDDAZi
|
16
|
+
cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
|
17
|
+
GRYCaW8wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCro8tj5/E1Hg88
|
18
|
+
f4qfiwPVd2zJQHvdYt4GHVvuHRRgx4HGhJuNp+4BId08RBn7V6V1MW6MY3kezRBs
|
19
|
+
M+7QOQ4b1xNLTvY7FYQB1wGK5a4x7TTokDrPYQxDB2jmsdDYCzVbIMrAvUfcecRi
|
20
|
+
khyGZCdByiiCl4fKv77P12tTT+NfsvXkLt/AYCGwjOUyGKTQ01Z6eC09T27GayPH
|
21
|
+
QQvIkakyFgcJtzSyGzs8bzK5q9u7wQ12MNTjJoXzW69lqp0oNvDylu81EiSUb5S6
|
22
|
+
QzzPxZBiRB1sgtbt1gUbVI262ZDq1gR+HxPFmp+Cgt7ZLIJZAtesQvtcMzseXpfn
|
23
|
+
hpmm0Sw22KGhRAy/mqHBRhDl5HqS1SJp2Ko3lcnpXeFResp0HNlt8NSu13vhC08j
|
24
|
+
GUHU9MyIXbFOsnp3K3ADrAVjPWop8EZkmUR3MV/CUm00w2cZHCSGiXl1KMpiVKvk
|
25
|
+
Ywr1gd2ZME4QLSo+EXUtLxDUa/W3xnBS8dBOuMMz02FPWYr3PN8CAwEAAaN7MHkw
|
26
|
+
CQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFAFgmv0tYMZnItuPycSM
|
27
|
+
F5wykJEVMB8GA1UdEQQYMBaBFGJyb29rZUBhbGNoZW1pc3RzLmlvMB8GA1UdEgQY
|
28
|
+
MBaBFGJyb29rZUBhbGNoZW1pc3RzLmlvMA0GCSqGSIb3DQEBCwUAA4IBgQAX+EGY
|
29
|
+
9RLYGxF1VLZz+G1ACQc4uyrCB6kXwI06kzUa5dF9tPXqTX9ffnz3/W8ck2IQhKzu
|
30
|
+
MKO2FVijzbDWTsZeZGglS4E+4Jxpau1lU9HhOIcKolv6LeC6UdALTFudY+GLb8Xw
|
31
|
+
REXgaJkjzzhkUSILmEnRwEbY08dVSl7ZAaxVI679vfI2yapLlIwpbBgmQTiTvPr3
|
32
|
+
qyyLUno9flYEOv9fmGHunSrM+gE0/0niGTXa5GgXBXYGS2he4LQGgSBfGp/cTwMU
|
33
|
+
rDKJRcusZ12lNBeDfgqACz/BBJF8FLodgk6rGMRZz7+ZmjjHEmpG5bQpR6Q2BuWL
|
34
|
+
XMtYk/QzaWuhiR7pWjiF8jbdd7RO6or0ohq7iFkokz/5xrtQ/vPzU2RQ3Qc6YaKw
|
35
|
+
3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
|
36
|
+
gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: refinements
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: zeitwerk
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.6'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.6'
|
68
|
+
description:
|
69
|
+
email:
|
70
|
+
- brooke@alchemists.io
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.adoc
|
75
|
+
- LICENSE.adoc
|
76
|
+
files:
|
77
|
+
- LICENSE.adoc
|
78
|
+
- README.adoc
|
79
|
+
- htmx.gemspec
|
80
|
+
- lib/htmx.rb
|
81
|
+
- lib/htmx/error.rb
|
82
|
+
- lib/htmx/headers/request.rb
|
83
|
+
- lib/htmx/headers/response.rb
|
84
|
+
- lib/htmx/prefixer.rb
|
85
|
+
homepage: https://alchemists.io/projects/htmx
|
86
|
+
licenses:
|
87
|
+
- Hippocratic-2.1
|
88
|
+
metadata:
|
89
|
+
bug_tracker_uri: https://github.com/bkuhlmann/htmx/issues
|
90
|
+
changelog_uri: https://alchemists.io/projects/htmx/versions
|
91
|
+
documentation_uri: https://alchemists.io/projects/htmx
|
92
|
+
funding_uri: https://github.com/sponsors/bkuhlmann
|
93
|
+
label: HTMX
|
94
|
+
rubygems_mfa_required: 'true'
|
95
|
+
source_code_uri: https://github.com/bkuhlmann/htmx
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.2'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.4.13
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Augmenter, enhancer, and companion to the HTMX JavaScript library.
|
115
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|