tail_merge 0.1.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 +7 -0
- data/.rubocop.yml +8 -0
- data/Cargo.lock +357 -0
- data/Cargo.toml +7 -0
- data/README.md +107 -0
- data/Rakefile +22 -0
- data/ext/tail_merge/Cargo.toml +13 -0
- data/ext/tail_merge/extconf.rb +6 -0
- data/ext/tail_merge/src/lib.rs +33 -0
- data/lib/tail_merge/version.rb +5 -0
- data/lib/tail_merge.rb +9 -0
- data/sig/tail_merge.rbs +4 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3aa2748d158cbcc46f8db818a6f1dbf5c0f3b210f03b48b96b178ee4e8d4c25c
|
4
|
+
data.tar.gz: fae3b047cf0136529135c371bae6ecdf4172bdb7f96bed1e16821a41decc9343
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec9ef9dc0dc7f40e77fbc5ae416abdf1054a959465e5cbd22a86ecefbc6b86454ef4c416833b8c35dbc41749c5fbfa9d8b10a9e1720dba741d1ee51742d68f8d
|
7
|
+
data.tar.gz: c9210f053328369aa0b25a3e9f14f87a011b84c85f33f65d2a8e5962efccb7a83698cba71b824cc522469f596da2eab7c0701bd931ba0de088620cada7192914
|
data/.rubocop.yml
ADDED
data/Cargo.lock
ADDED
@@ -0,0 +1,357 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
version = 4
|
4
|
+
|
5
|
+
[[package]]
|
6
|
+
name = "aho-corasick"
|
7
|
+
version = "1.1.3"
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
10
|
+
dependencies = [
|
11
|
+
"memchr",
|
12
|
+
]
|
13
|
+
|
14
|
+
[[package]]
|
15
|
+
name = "bindgen"
|
16
|
+
version = "0.69.5"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
19
|
+
dependencies = [
|
20
|
+
"bitflags",
|
21
|
+
"cexpr",
|
22
|
+
"clang-sys",
|
23
|
+
"itertools",
|
24
|
+
"lazy_static",
|
25
|
+
"lazycell",
|
26
|
+
"proc-macro2",
|
27
|
+
"quote",
|
28
|
+
"regex",
|
29
|
+
"rustc-hash",
|
30
|
+
"shlex",
|
31
|
+
"syn",
|
32
|
+
]
|
33
|
+
|
34
|
+
[[package]]
|
35
|
+
name = "bitflags"
|
36
|
+
version = "2.9.1"
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
38
|
+
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
39
|
+
|
40
|
+
[[package]]
|
41
|
+
name = "cexpr"
|
42
|
+
version = "0.6.0"
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
44
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
45
|
+
dependencies = [
|
46
|
+
"nom",
|
47
|
+
]
|
48
|
+
|
49
|
+
[[package]]
|
50
|
+
name = "cfg-if"
|
51
|
+
version = "1.0.0"
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
53
|
+
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
54
|
+
|
55
|
+
[[package]]
|
56
|
+
name = "clang-sys"
|
57
|
+
version = "1.8.1"
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
59
|
+
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
60
|
+
dependencies = [
|
61
|
+
"glob",
|
62
|
+
"libc",
|
63
|
+
"libloading",
|
64
|
+
]
|
65
|
+
|
66
|
+
[[package]]
|
67
|
+
name = "either"
|
68
|
+
version = "1.15.0"
|
69
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
70
|
+
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
71
|
+
|
72
|
+
[[package]]
|
73
|
+
name = "glob"
|
74
|
+
version = "0.3.2"
|
75
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
76
|
+
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
77
|
+
|
78
|
+
[[package]]
|
79
|
+
name = "itertools"
|
80
|
+
version = "0.12.1"
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
82
|
+
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
83
|
+
dependencies = [
|
84
|
+
"either",
|
85
|
+
]
|
86
|
+
|
87
|
+
[[package]]
|
88
|
+
name = "lazy_static"
|
89
|
+
version = "1.5.0"
|
90
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
91
|
+
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
92
|
+
|
93
|
+
[[package]]
|
94
|
+
name = "lazycell"
|
95
|
+
version = "1.3.0"
|
96
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
97
|
+
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
98
|
+
|
99
|
+
[[package]]
|
100
|
+
name = "libc"
|
101
|
+
version = "0.2.172"
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
103
|
+
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
|
104
|
+
|
105
|
+
[[package]]
|
106
|
+
name = "libloading"
|
107
|
+
version = "0.8.7"
|
108
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
109
|
+
checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c"
|
110
|
+
dependencies = [
|
111
|
+
"cfg-if",
|
112
|
+
"windows-targets",
|
113
|
+
]
|
114
|
+
|
115
|
+
[[package]]
|
116
|
+
name = "magnus"
|
117
|
+
version = "0.6.4"
|
118
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
119
|
+
checksum = "b1597ef40aa8c36be098249e82c9a20cf7199278ac1c1a1a995eeead6a184479"
|
120
|
+
dependencies = [
|
121
|
+
"magnus-macros",
|
122
|
+
"rb-sys",
|
123
|
+
"rb-sys-env",
|
124
|
+
"seq-macro",
|
125
|
+
]
|
126
|
+
|
127
|
+
[[package]]
|
128
|
+
name = "magnus-macros"
|
129
|
+
version = "0.6.0"
|
130
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
131
|
+
checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
|
132
|
+
dependencies = [
|
133
|
+
"proc-macro2",
|
134
|
+
"quote",
|
135
|
+
"syn",
|
136
|
+
]
|
137
|
+
|
138
|
+
[[package]]
|
139
|
+
name = "memchr"
|
140
|
+
version = "2.7.4"
|
141
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
142
|
+
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
143
|
+
|
144
|
+
[[package]]
|
145
|
+
name = "minimal-lexical"
|
146
|
+
version = "0.2.1"
|
147
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
148
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
149
|
+
|
150
|
+
[[package]]
|
151
|
+
name = "nom"
|
152
|
+
version = "7.1.3"
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
154
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
155
|
+
dependencies = [
|
156
|
+
"memchr",
|
157
|
+
"minimal-lexical",
|
158
|
+
]
|
159
|
+
|
160
|
+
[[package]]
|
161
|
+
name = "proc-macro2"
|
162
|
+
version = "1.0.95"
|
163
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
164
|
+
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
165
|
+
dependencies = [
|
166
|
+
"unicode-ident",
|
167
|
+
]
|
168
|
+
|
169
|
+
[[package]]
|
170
|
+
name = "quote"
|
171
|
+
version = "1.0.40"
|
172
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
173
|
+
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
174
|
+
dependencies = [
|
175
|
+
"proc-macro2",
|
176
|
+
]
|
177
|
+
|
178
|
+
[[package]]
|
179
|
+
name = "rb-sys"
|
180
|
+
version = "0.9.115"
|
181
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
182
|
+
checksum = "99ca6726be0eca74687047fed7dcbc2d509571f3962e190c343ac1eb40e482b3"
|
183
|
+
dependencies = [
|
184
|
+
"rb-sys-build",
|
185
|
+
]
|
186
|
+
|
187
|
+
[[package]]
|
188
|
+
name = "rb-sys-build"
|
189
|
+
version = "0.9.115"
|
190
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
191
|
+
checksum = "9f2390cfc87b7513656656faad6567291e581542d3ec41dd0a2bf381896e0880"
|
192
|
+
dependencies = [
|
193
|
+
"bindgen",
|
194
|
+
"lazy_static",
|
195
|
+
"proc-macro2",
|
196
|
+
"quote",
|
197
|
+
"regex",
|
198
|
+
"shell-words",
|
199
|
+
"syn",
|
200
|
+
]
|
201
|
+
|
202
|
+
[[package]]
|
203
|
+
name = "rb-sys-env"
|
204
|
+
version = "0.1.2"
|
205
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
206
|
+
checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
207
|
+
|
208
|
+
[[package]]
|
209
|
+
name = "regex"
|
210
|
+
version = "1.11.1"
|
211
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
212
|
+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
213
|
+
dependencies = [
|
214
|
+
"aho-corasick",
|
215
|
+
"memchr",
|
216
|
+
"regex-automata",
|
217
|
+
"regex-syntax",
|
218
|
+
]
|
219
|
+
|
220
|
+
[[package]]
|
221
|
+
name = "regex-automata"
|
222
|
+
version = "0.4.9"
|
223
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
224
|
+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
225
|
+
dependencies = [
|
226
|
+
"aho-corasick",
|
227
|
+
"memchr",
|
228
|
+
"regex-syntax",
|
229
|
+
]
|
230
|
+
|
231
|
+
[[package]]
|
232
|
+
name = "regex-syntax"
|
233
|
+
version = "0.8.5"
|
234
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
235
|
+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
236
|
+
|
237
|
+
[[package]]
|
238
|
+
name = "rustc-hash"
|
239
|
+
version = "1.1.0"
|
240
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
241
|
+
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
242
|
+
|
243
|
+
[[package]]
|
244
|
+
name = "rustui_merge"
|
245
|
+
version = "0.1.6"
|
246
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
247
|
+
checksum = "393cd2993ada676d1a92a85dd1009eb9045e2891c228b4b073888f72872c3502"
|
248
|
+
dependencies = [
|
249
|
+
"nom",
|
250
|
+
]
|
251
|
+
|
252
|
+
[[package]]
|
253
|
+
name = "seq-macro"
|
254
|
+
version = "0.3.6"
|
255
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
256
|
+
checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
|
257
|
+
|
258
|
+
[[package]]
|
259
|
+
name = "shell-words"
|
260
|
+
version = "1.1.0"
|
261
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
262
|
+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
263
|
+
|
264
|
+
[[package]]
|
265
|
+
name = "shlex"
|
266
|
+
version = "1.3.0"
|
267
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
268
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
269
|
+
|
270
|
+
[[package]]
|
271
|
+
name = "syn"
|
272
|
+
version = "2.0.101"
|
273
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
274
|
+
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
|
275
|
+
dependencies = [
|
276
|
+
"proc-macro2",
|
277
|
+
"quote",
|
278
|
+
"unicode-ident",
|
279
|
+
]
|
280
|
+
|
281
|
+
[[package]]
|
282
|
+
name = "tail_merge"
|
283
|
+
version = "0.1.0"
|
284
|
+
dependencies = [
|
285
|
+
"magnus",
|
286
|
+
"rustui_merge",
|
287
|
+
]
|
288
|
+
|
289
|
+
[[package]]
|
290
|
+
name = "unicode-ident"
|
291
|
+
version = "1.0.18"
|
292
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
293
|
+
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
294
|
+
|
295
|
+
[[package]]
|
296
|
+
name = "windows-targets"
|
297
|
+
version = "0.53.0"
|
298
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
299
|
+
checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b"
|
300
|
+
dependencies = [
|
301
|
+
"windows_aarch64_gnullvm",
|
302
|
+
"windows_aarch64_msvc",
|
303
|
+
"windows_i686_gnu",
|
304
|
+
"windows_i686_gnullvm",
|
305
|
+
"windows_i686_msvc",
|
306
|
+
"windows_x86_64_gnu",
|
307
|
+
"windows_x86_64_gnullvm",
|
308
|
+
"windows_x86_64_msvc",
|
309
|
+
]
|
310
|
+
|
311
|
+
[[package]]
|
312
|
+
name = "windows_aarch64_gnullvm"
|
313
|
+
version = "0.53.0"
|
314
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
315
|
+
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
|
316
|
+
|
317
|
+
[[package]]
|
318
|
+
name = "windows_aarch64_msvc"
|
319
|
+
version = "0.53.0"
|
320
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
321
|
+
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
|
322
|
+
|
323
|
+
[[package]]
|
324
|
+
name = "windows_i686_gnu"
|
325
|
+
version = "0.53.0"
|
326
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
327
|
+
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
|
328
|
+
|
329
|
+
[[package]]
|
330
|
+
name = "windows_i686_gnullvm"
|
331
|
+
version = "0.53.0"
|
332
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
333
|
+
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
|
334
|
+
|
335
|
+
[[package]]
|
336
|
+
name = "windows_i686_msvc"
|
337
|
+
version = "0.53.0"
|
338
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
339
|
+
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
|
340
|
+
|
341
|
+
[[package]]
|
342
|
+
name = "windows_x86_64_gnu"
|
343
|
+
version = "0.53.0"
|
344
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
345
|
+
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
|
346
|
+
|
347
|
+
[[package]]
|
348
|
+
name = "windows_x86_64_gnullvm"
|
349
|
+
version = "0.53.0"
|
350
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
351
|
+
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
|
352
|
+
|
353
|
+
[[package]]
|
354
|
+
name = "windows_x86_64_msvc"
|
355
|
+
version = "0.53.0"
|
356
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
357
|
+
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
data/Cargo.toml
ADDED
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# TailMerge
|
2
|
+
|
3
|
+
TailMerge is a super fast utility library to merge Tailwind CSS classes without conflicts.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
TailMerge.merge %w[px-2 py-1 bg-red hover:bg-dark-red p-3 bg-[#B91C1C]]
|
7
|
+
=> "hover:bg-dark-red p-3 bg-[#B91C1C]"
|
8
|
+
```
|
9
|
+
|
10
|
+
Classes on the right will override classes on the left.
|
11
|
+
|
12
|
+
TailMerge wraps the Rust library [rustui_merge](https://docs.rs/rustui_merge/latest/rustui_merge/) so that it can be used in Ruby. This makes it a lot faster than combining classes in Ruby.
|
13
|
+
|
14
|
+
## Purpose
|
15
|
+
|
16
|
+
When you use Tailwindcss to style components, you will probably run into the situation where you want to adjust the styling of component in a specific situation.
|
17
|
+
|
18
|
+
An example:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class Well < ApplicationComponent
|
22
|
+
def initialize(**options)
|
23
|
+
@classes = options.delete(:classes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
tag.div class: default_classes + @classes
|
28
|
+
content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_classes
|
33
|
+
%w[bg-gray-100 rounded-lg p-4]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
If you want to render this component somewhere with a different background, ideally you'd be able to do this:
|
39
|
+
|
40
|
+
```erb
|
41
|
+
<%= render Well.new(classes: %w[bg-blue-50 p-2]) do %>
|
42
|
+
<p>Hello</p>
|
43
|
+
<% end %>
|
44
|
+
```
|
45
|
+
|
46
|
+
Sadly, this will not work. The div will have a gray-100 background and a padding of 4 instead of the intended blue-50 and p-2.
|
47
|
+
|
48
|
+
This is where TailMerge comes in. It allows you to merge classes without conflicts.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
TailMerge.merge %w[bg-gray-100 rounded-lg p-4] + %w[bg-blue-50 p-2]
|
52
|
+
=> "rounded-lg bg-blue-50 p-2"
|
53
|
+
```
|
54
|
+
|
55
|
+
Implementing this in your component is easy:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Well < ApplicationComponent
|
59
|
+
def initialize(**options)
|
60
|
+
@classes = options.delete(:classes)
|
61
|
+
end
|
62
|
+
|
63
|
+
def call
|
64
|
+
tag.div class: TailMerge.merge(default_classes + @classes)
|
65
|
+
content
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def default_classes
|
70
|
+
%w[bg-gray-100 rounded-lg p-4]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
No more conflicts!
|
76
|
+
|
77
|
+
## Installation
|
78
|
+
|
79
|
+
Add the gem to your Gemfile:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
gem "tail_merge"
|
83
|
+
```
|
84
|
+
|
85
|
+
Run `bundle install` to install the gem.
|
86
|
+
|
87
|
+
## Usage
|
88
|
+
|
89
|
+
You can pass a string or an array of strings to the `merge` method.
|
90
|
+
|
91
|
+
Whatever you pass last will override whatever you pass first.
|
92
|
+
|
93
|
+
A string is returned for easy use in ERB.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
TailMerge.merge %w[px-2 py-1 bg-red hover:bg-dark-red p-3 bg-[#B91C1C]]
|
97
|
+
=> "hover:bg-dark-red p-3 bg-[#B91C1C]"
|
98
|
+
```
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
TailMerge.merge "px-2 py-1 bg-red hover:bg-dark-red p-3 bg-[#B91C1C]"
|
102
|
+
=> "hover:bg-dark-red p-3 bg-[#B91C1C]"
|
103
|
+
```
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abuisman/tail_merge.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "minitest/test_task"
|
5
|
+
|
6
|
+
Minitest::TestTask.create
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
require "rb_sys/extensiontask"
|
13
|
+
|
14
|
+
task build: :compile
|
15
|
+
|
16
|
+
GEMSPEC = Gem::Specification.load("tail_merge.gemspec")
|
17
|
+
|
18
|
+
RbSys::ExtensionTask.new("tail_merge", GEMSPEC) do |ext|
|
19
|
+
ext.lib_dir = "lib/tail_merge"
|
20
|
+
end
|
21
|
+
|
22
|
+
task default: %i[compile test rubocop]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
[package]
|
2
|
+
name = "tail_merge"
|
3
|
+
version = "0.1.0"
|
4
|
+
edition = "2021"
|
5
|
+
authors = ["Achilleas Buisman <accounts@abuisman.nl>"]
|
6
|
+
publish = false
|
7
|
+
|
8
|
+
[lib]
|
9
|
+
crate-type = ["cdylib"]
|
10
|
+
|
11
|
+
[dependencies]
|
12
|
+
magnus = { version = "0.6.2" }
|
13
|
+
rustui_merge = "0.1.6"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
use magnus::{define_module, function, prelude::*, Error, RArray, RString, Value};
|
2
|
+
use rustui_merge::merge::tw_merge;
|
3
|
+
|
4
|
+
fn merge_tailwind_classes(arg: Value) -> Result<RString, Error> {
|
5
|
+
let mut class_strings = Vec::new();
|
6
|
+
|
7
|
+
if let Ok(rstring) = arg.clone().try_convert::<RString>() {
|
8
|
+
// If it's a string, split on spaces
|
9
|
+
let s = rstring.to_string()?;
|
10
|
+
class_strings.extend(s.split_whitespace().map(|s| s.to_string()));
|
11
|
+
} else if let Ok(rarray) = arg.try_convert::<RArray>() {
|
12
|
+
// If it's an array, process as before
|
13
|
+
for arg in rarray.each() {
|
14
|
+
let rstring: RString = arg?.try_convert()?;
|
15
|
+
class_strings.push(rstring.to_string()?);
|
16
|
+
}
|
17
|
+
} else {
|
18
|
+
return Err(Error::new(
|
19
|
+
magnus::exception::type_error(),
|
20
|
+
"Expected String or Array of Strings as argument",
|
21
|
+
));
|
22
|
+
}
|
23
|
+
|
24
|
+
let merged = tw_merge(class_strings.join(" "));
|
25
|
+
Ok(RString::new(&merged))
|
26
|
+
}
|
27
|
+
|
28
|
+
#[magnus::init]
|
29
|
+
fn init() -> Result<(), Error> {
|
30
|
+
let module = define_module("TailMerge")?;
|
31
|
+
module.define_singleton_method("merge", function!(merge_tailwind_classes, 1))?;
|
32
|
+
Ok(())
|
33
|
+
}
|
data/lib/tail_merge.rb
ADDED
data/sig/tail_merge.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tail_merge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Achilleas Buisman
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rb_sys
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.9.91
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.9.91
|
26
|
+
description: Merge Tailwind CSS classes
|
27
|
+
email:
|
28
|
+
- accounts@abuisman.nl
|
29
|
+
executables: []
|
30
|
+
extensions:
|
31
|
+
- ext/tail_merge/extconf.rb
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rubocop.yml"
|
35
|
+
- Cargo.lock
|
36
|
+
- Cargo.toml
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- ext/tail_merge/Cargo.toml
|
40
|
+
- ext/tail_merge/extconf.rb
|
41
|
+
- ext/tail_merge/src/lib.rs
|
42
|
+
- lib/tail_merge.rb
|
43
|
+
- lib/tail_merge/version.rb
|
44
|
+
- sig/tail_merge.rbs
|
45
|
+
homepage: https://github.com/abuisman/tail_merge
|
46
|
+
licenses: []
|
47
|
+
metadata:
|
48
|
+
allowed_push_host: https://rubygems.org
|
49
|
+
homepage_uri: https://github.com/abuisman/tail_merge
|
50
|
+
source_code_uri: https://github.com/abuisman/tail_merge
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 3.1.0
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.3.11
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.6.9
|
66
|
+
specification_version: 4
|
67
|
+
summary: Merge Tailwind CSS classes
|
68
|
+
test_files: []
|