shoelace-rails 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -18
- data/README.md +5 -0
- data/app/helpers/shoelace/form_helper.rb +6 -9
- data/lib/shoelace/rails/version.rb +1 -1
- data/lib/shoelace/railtie.rb +4 -1
- data/lib/shoelace/testing.rb +2 -2
- data/lib/tasks/shoelace.rake +5 -1
- data/test/dummy_app/app/views/layouts/application.html.erb +2 -2
- data/test/helpers/form_helper_test.rb +28 -28
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a2dfd18c31e8151980211fe86c5911629f795652e2662315055695f31b7e2d6
|
4
|
+
data.tar.gz: a2c224c7c8ba4fd199d9190d77e37246650753f9c76d29156c25b4754c65018b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a78a2537a9851beb4f9d7e33214e51fbff8c3539cef0d244951b6ac36d7f0837a84129a8dfe36a46f8e7eec8f474e65b9a45078abde2a508b3a3b90f5322060
|
7
|
+
data.tar.gz: 5a99554ecd05cd33ffbe41929984a82828961db94ac3f4a4c796e6685bff57c08afef96ed8d8c58e055edaada87e2e0be0ebc5761b870bec74164a476c7e36e6
|
data/CHANGELOG.md
CHANGED
@@ -1,28 +1,49 @@
|
|
1
|
-
## v0.
|
1
|
+
## v0.4.1
|
2
2
|
|
3
|
-
_<sup>released at 2023-
|
3
|
+
_<sup>released at 2023-03-21 05:01:50 UTC</sup>_
|
4
|
+
|
5
|
+
#### 🐞Bug Fixes
|
6
|
+
|
7
|
+
- Fixes a bug where `FormHelper` may not be defined when someone loads `ActionView` too early (d91ed3b595c01ce2dfc471b12b14311e0660d3d7)
|
8
|
+
- Fixes a bug where the Shoelace rake tasks blow up when the project does not depend on Sprockets or Propshaft (0e64cd6dc38a037171be04eaf1d3f59c3c8529eb, 75adf831b1faa7f5d1faeed26e672d4bc89b9513)
|
9
|
+
|
10
|
+
## [v0.4.0](https://github.com/yuki24/shoelace-rails/tree/v0.4.0)
|
11
|
+
|
12
|
+
_<sup>released at 2023-01-07 07:23:50 UTC</sup>_
|
13
|
+
|
14
|
+
#### 🚨 Breaking Changes
|
15
|
+
|
16
|
+
- No longer works with `2.0.0-beta.88` and below.
|
17
|
+
|
18
|
+
#### ⭐️ Features
|
19
|
+
|
20
|
+
- Support Shoelace.style `2.0.0-beta.88`.
|
21
|
+
|
22
|
+
## [v0.3.0](https://github.com/yuki24/shoelace-rails/tree/v0.3.0)
|
23
|
+
|
24
|
+
_<sup>released at 2023-01-05 08:49:23 UTC</sup>_
|
4
25
|
|
5
26
|
#### Features
|
6
27
|
|
7
|
-
- No longer requires the `sl-form` component (
|
8
|
-
- The `#text_area` method now accepts a block (
|
9
|
-
- Allow overriding the value attribute for `<sl-select>` (
|
10
|
-
- Auto-display labels whenever possible (
|
11
|
-
- `<sl-select>` now always has a label by default (
|
12
|
-
- Support Ruby 3.2 (
|
13
|
-
- Add `#sl_button_to` (
|
14
|
-
- Add `#sl_icon_tag` (
|
15
|
-
- Add `#sl_avatar_tag` (
|
16
|
-
- Allow using the `Shoelace::FormBuilder` in a cleaner way (
|
28
|
+
- No longer requires the `sl-form` component ([<tt>4fdbfa1</tt>](https://github.com/yuki24/shoelace-rails/commit/4fdbfa15fa10db9e7240378ca34ebcc494d18f1a))
|
29
|
+
- The `#text_area` method now accepts a block ([<tt>5092dc1</tt>](https://github.com/yuki24/shoelace-rails/commit/5092dc1cbc7e8e74552451450804baa378ab1f11))
|
30
|
+
- Allow overriding the value attribute for `<sl-select>` ([<tt>1f38be7</tt>](https://github.com/yuki24/shoelace-rails/commit/1f38be73e3335c10e846393ebcf5155d155b00b2))
|
31
|
+
- Auto-display labels whenever possible ([<tt>c1e3a95</tt>](https://github.com/yuki24/shoelace-rails/commit/c1e3a950c3e8ac4238ed3e83e4d87467a68eb91f))
|
32
|
+
- `<sl-select>` now always has a label by default ([<tt>f9fb5f0</tt>](https://github.com/yuki24/shoelace-rails/commit/f9fb5f0cd74d179241be51510fa1c306481946c9))
|
33
|
+
- Support Ruby 3.2 ([<tt>b286cbc</tt>](https://github.com/yuki24/shoelace-rails/commit/b286cbc18930218ab5c82bd8648a51e9c6ce53db))
|
34
|
+
- Add `#sl_button_to` ([<tt>e1bdedb</tt>](https://github.com/yuki24/shoelace-rails/commit/e1bdedba4656d89a82c78641644490085da1fa37))
|
35
|
+
- Add `#sl_icon_tag` ([<tt>8a2187a</tt>](https://github.com/yuki24/shoelace-rails/commit/8a2187a2800771512fccf2c8231378a77be59df4))
|
36
|
+
- Add `#sl_avatar_tag` ([<tt>77dccdb</tt>](https://github.com/yuki24/shoelace-rails/commit/77dccdb24cfc014bd997ffb66ad89ff95afb3ef7))
|
37
|
+
- Allow using the `Shoelace::FormBuilder` in a cleaner way ([<tt>43dea33</tt>](https://github.com/yuki24/shoelace-rails/commit/43dea3309c3e0cf9d9b43b6957f6e54ad9497c9f))
|
17
38
|
|
18
39
|
#### Bug Fixes
|
19
40
|
|
20
|
-
- Fixes a bug where the gem rake tasks are not loaded (
|
21
|
-
- Fixes a bug where values are not properly passed in to `<sl-textarea>` (
|
22
|
-
- Make sure yarn install is always executed before copying shoelace assets (
|
23
|
-
- Fixes a bug where the `@object` needs to respond to `#errors` (
|
24
|
-
- Fixes a bug where the `size` attr is ignored by the `#text_area` method (
|
25
|
-
- Fixes a bug where unchecked checkbox values are not captured (
|
41
|
+
- Fixes a bug where the gem rake tasks are not loaded ([<tt>115bfb3</tt>](https://github.com/yuki24/shoelace-rails/commit/115bfb3d81ca19b5b922a5fb32f46adb1d6e8544))
|
42
|
+
- Fixes a bug where values are not properly passed in to `<sl-textarea>` ([<tt>3d16384</tt>](https://github.com/yuki24/shoelace-rails/commit/3d16384554bd4a6143e28e483f8d6bee8fb2e073))
|
43
|
+
- Make sure yarn install is always executed before copying shoelace assets ([<tt>98018a2</tt>](https://github.com/yuki24/shoelace-rails/commit/98018a27a29ddc9ff2c2fa066bbe986709803a1d))
|
44
|
+
- Fixes a bug where the `@object` needs to respond to `#errors` ([<tt>bb981ed</tt>](https://github.com/yuki24/shoelace-rails/commit/bb981ed05825707cef89d70a7d1699c12cd0ba9b))
|
45
|
+
- Fixes a bug where the `size` attr is ignored by the `#text_area` method ([<tt>8bc4c37</tt>](https://github.com/yuki24/shoelace-rails/commit/8bc4c3784a458e7fc9c18a143578b2cbf588e9e7))
|
46
|
+
- Fixes a bug where unchecked checkbox values are not captured ([<tt>dc658be</tt>](https://github.com/yuki24/shoelace-rails/commit/dc658bea9fc4d4205dacdfe133b091c5a5edf14c))
|
26
47
|
|
27
48
|
## [v0.2.0](https://github.com/yuki24/shoelace-rails/tree/v0.2.0)
|
28
49
|
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
The `shoelace-rails` gem adds useful helper methods for [Shoelace.style](https://shoelace.style), the design system.
|
4
4
|
|
5
|
+
## Compatibility with Shoelace
|
6
|
+
|
7
|
+
* **For Shoelace version >= 2.0.0-beta.88, use the gem version `0.4.0` or above**.
|
8
|
+
* For Shoelace version <= 2.0.0-beta.87, use the gem version `0.3.0`.
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -2,9 +2,6 @@
|
|
2
2
|
|
3
3
|
module Shoelace
|
4
4
|
module FormHelper
|
5
|
-
mattr_accessor :invalid_input_class_name
|
6
|
-
self.invalid_input_class_name = nil
|
7
|
-
|
8
5
|
class ShoelaceInputField < ActionView::Helpers::Tags::TextField #:nodoc:
|
9
6
|
attr_reader :field_type
|
10
7
|
|
@@ -21,7 +18,7 @@ module Shoelace
|
|
21
18
|
|
22
19
|
options["size"] = options["maxlength"] unless options.key?("size")
|
23
20
|
options["type"] ||= field_type
|
24
|
-
options["class"] ||= [options["class"], Shoelace
|
21
|
+
options["class"] ||= [options["class"], Shoelace.invalid_input_class_name].compact.join(" ") if @object.respond_to?(:errors) && @object.errors[@method_name].present?
|
25
22
|
|
26
23
|
add_default_name_and_id(options)
|
27
24
|
|
@@ -274,7 +271,7 @@ module Shoelace
|
|
274
271
|
content_tag('sl-input', '', { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys), &block)
|
275
272
|
end
|
276
273
|
|
277
|
-
# Returns a string of +<sl-
|
274
|
+
# Returns a string of +<sl-option>+ tags, like +options_for_select+, but prepends a +<small>+ tag to
|
278
275
|
# each group.
|
279
276
|
def grouped_sl_options_for_select(grouped_options, options)
|
280
277
|
body = "".html_safe
|
@@ -283,14 +280,14 @@ module Shoelace
|
|
283
280
|
label, values = container
|
284
281
|
|
285
282
|
body.safe_concat(DIVIDER_TAG) if index > 0
|
286
|
-
body.safe_concat(content_tag("
|
283
|
+
body.safe_concat(content_tag("small", label)) if label.present?
|
287
284
|
body.safe_concat(sl_options_for_select(values, options))
|
288
285
|
end
|
289
286
|
|
290
287
|
body
|
291
288
|
end
|
292
289
|
|
293
|
-
# Accepts an enumerable (hash, array, enumerable, your type) and returns a string of +sl-
|
290
|
+
# Accepts an enumerable (hash, array, enumerable, your type) and returns a string of +sl-option+ tags. Given
|
294
291
|
# an enumerable where the elements respond to +first+ and +last+ (such as a two-element array), the “lasts” serve
|
295
292
|
# as option values and the “firsts” as option text.
|
296
293
|
def sl_options_for_select(enumerable, options = nil)
|
@@ -306,11 +303,11 @@ module Shoelace
|
|
306
303
|
html_attributes[:disabled] ||= disabled.include?(value)
|
307
304
|
html_attributes[:value] = value
|
308
305
|
|
309
|
-
tag_builder.content_tag_string('sl-
|
306
|
+
tag_builder.content_tag_string('sl-option', text, html_attributes)
|
310
307
|
end.join("\n").html_safe
|
311
308
|
end
|
312
309
|
|
313
|
-
# Returns a string of +<sl-
|
310
|
+
# Returns a string of +<sl-option>+ tags compiled by iterating over the collection and assigning the result of
|
314
311
|
# a call to the +value_method+ as the option value and the +text_method+ as the option text.
|
315
312
|
def sl_options_from_collection_for_select(collection, value_method, text_method, selected = nil)
|
316
313
|
options = collection.map do |element|
|
data/lib/shoelace/railtie.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require 'action_dispatch/middleware/static'
|
4
4
|
|
5
5
|
module Shoelace
|
6
|
+
mattr_accessor :invalid_input_class_name
|
7
|
+
self.invalid_input_class_name = nil
|
8
|
+
|
6
9
|
# The only reason this class exists is to clarify that we have a custom static file server after
|
7
10
|
# `ActionDispatch::Static`. We could just use `ActionDispatch::Static` directly, but it would make the result of
|
8
11
|
# `rake middleware` more difficult to understand, as the output would look like:
|
@@ -43,7 +46,7 @@ module Shoelace
|
|
43
46
|
|
44
47
|
initializer "shoelace.form_helper" do |app|
|
45
48
|
ActiveSupport.on_load :action_view do
|
46
|
-
Shoelace
|
49
|
+
Shoelace.invalid_input_class_name = app.config.shoelace.invalid_input_class_name
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
data/lib/shoelace/testing.rb
CHANGED
@@ -7,7 +7,7 @@ module Shoelace
|
|
7
7
|
select_element.click
|
8
8
|
|
9
9
|
within select_element do
|
10
|
-
find('sl-
|
10
|
+
find('sl-option', text: option_text).click
|
11
11
|
end
|
12
12
|
|
13
13
|
select_element
|
@@ -19,7 +19,7 @@ module Shoelace
|
|
19
19
|
select_element.click
|
20
20
|
within select_element do
|
21
21
|
options_to_select.each do |option_text|
|
22
|
-
find('sl-
|
22
|
+
find('sl-option', text: option_text).click
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/tasks/shoelace.rake
CHANGED
@@ -13,8 +13,12 @@ namespace :shoelace do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Make sure `yarn install` is run before running `shoelace:icons:copy`.
|
16
|
-
Rake::Task
|
16
|
+
if Rake::Task.task_defined?("javascript:build")
|
17
|
+
Rake::Task["shoelace:icons:copy"].enhance(["javascript:build"])
|
18
|
+
end
|
17
19
|
|
18
20
|
if Rake::Task.task_defined?("assets:precompile")
|
19
21
|
Rake::Task["assets:precompile"].enhance(["shoelace:icons:copy"])
|
22
|
+
else
|
23
|
+
Rake::Task.define_task('assets:precompile' => ['shoelace:icons:copy'])
|
20
24
|
end
|
@@ -21,8 +21,8 @@
|
|
21
21
|
}
|
22
22
|
</style>
|
23
23
|
|
24
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.
|
25
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.
|
24
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.88/dist/themes/light.css">
|
25
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.88/dist/shoelace.js"></script>
|
26
26
|
|
27
27
|
<% if request.path.include?("hotwire") %>
|
28
28
|
<%= javascript_pack_tag 'hotwire' %>
|
@@ -282,9 +282,9 @@ class FormHelperTest < ActionView::TestCase
|
|
282
282
|
sl_form_for(User.new, url: "/") do |form|
|
283
283
|
assert_dom_equal <<~HTML, form.select(:name, users)
|
284
284
|
<sl-select label="Name" name="user[name]" id="user_name">
|
285
|
-
<sl-
|
286
|
-
<sl-
|
287
|
-
<sl-
|
285
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
286
|
+
<sl-option value="2">Matz</sl-option>
|
287
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
288
288
|
</sl-select>
|
289
289
|
HTML
|
290
290
|
end
|
@@ -300,9 +300,9 @@ class FormHelperTest < ActionView::TestCase
|
|
300
300
|
sl_form_for(User.new, url: "/") do |form|
|
301
301
|
assert_dom_equal <<~HTML, form.select(:name, users, {}, { value: 3 })
|
302
302
|
<sl-select label="Name" value="3" name="user[name]" id="user_name">
|
303
|
-
<sl-
|
304
|
-
<sl-
|
305
|
-
<sl-
|
303
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
304
|
+
<sl-option value="2">Matz</sl-option>
|
305
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
306
306
|
</sl-select>
|
307
307
|
HTML
|
308
308
|
end
|
@@ -318,9 +318,9 @@ class FormHelperTest < ActionView::TestCase
|
|
318
318
|
sl_form_for(User.new, url: "/") do |form|
|
319
319
|
assert_dom_equal <<~HTML, form.select(:name, users, selected: 3, disabled: 1)
|
320
320
|
<sl-select label="Name" name="user[name]" id="user_name">
|
321
|
-
<sl-
|
322
|
-
<sl-
|
323
|
-
<sl-
|
321
|
+
<sl-option value="1" disabled="disabled">Yuki Nishijima</sl-option>
|
322
|
+
<sl-option value="2">Matz</sl-option>
|
323
|
+
<sl-option value="3" checked="checked">Koichi Sasada</sl-option>
|
324
324
|
</sl-select>
|
325
325
|
HTML
|
326
326
|
end
|
@@ -336,9 +336,9 @@ class FormHelperTest < ActionView::TestCase
|
|
336
336
|
sl_form_for(User.new, url: "/") do |form|
|
337
337
|
assert_dom_equal <<~HTML, form.select(:name, users, {}, { multiple: true })
|
338
338
|
<sl-select label="Name" name="user[name][]" id="user_name" multiple="multiple">
|
339
|
-
<sl-
|
340
|
-
<sl-
|
341
|
-
<sl-
|
339
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
340
|
+
<sl-option value="2">Matz</sl-option>
|
341
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
342
342
|
</sl-select>
|
343
343
|
HTML
|
344
344
|
end
|
@@ -358,12 +358,12 @@ class FormHelperTest < ActionView::TestCase
|
|
358
358
|
sl_form_for(User.new, url: "/") do |form|
|
359
359
|
assert_dom_equal <<~HTML, form.select(:name, users)
|
360
360
|
<sl-select label="Name" name="user[name]" id="user_name">
|
361
|
-
<
|
362
|
-
<sl-
|
363
|
-
<sl-
|
361
|
+
<small>Main maintainers</small>
|
362
|
+
<sl-option value="2">Matz</sl-option>
|
363
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
364
364
|
<sl-divider></sl-divider>
|
365
|
-
<
|
366
|
-
<sl-
|
365
|
+
<small>Default gem maintainers</small>
|
366
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
367
367
|
</sl-select>
|
368
368
|
HTML
|
369
369
|
end
|
@@ -383,12 +383,12 @@ class FormHelperTest < ActionView::TestCase
|
|
383
383
|
sl_form_for(User.new(name: 2), url: "/") do |form|
|
384
384
|
assert_dom_equal <<~HTML, form.select(:name, users)
|
385
385
|
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
386
|
-
<
|
387
|
-
<sl-
|
388
|
-
<sl-
|
386
|
+
<small>Main maintainers</small>
|
387
|
+
<sl-option value="2" checked="checked">Matz</sl-option>
|
388
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
389
389
|
<sl-divider></sl-divider>
|
390
|
-
<
|
391
|
-
<sl-
|
390
|
+
<small>Default gem maintainers</small>
|
391
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
392
392
|
</sl-select>
|
393
393
|
HTML
|
394
394
|
end
|
@@ -404,9 +404,9 @@ class FormHelperTest < ActionView::TestCase
|
|
404
404
|
sl_form_for(User.new, url: "/") do |form|
|
405
405
|
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
406
406
|
<sl-select label="Name" name="user[name]" id="user_name">
|
407
|
-
<sl-
|
408
|
-
<sl-
|
409
|
-
<sl-
|
407
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
408
|
+
<sl-option value="2">Matz</sl-option>
|
409
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
410
410
|
</sl-select>
|
411
411
|
HTML
|
412
412
|
end
|
@@ -422,9 +422,9 @@ class FormHelperTest < ActionView::TestCase
|
|
422
422
|
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
423
423
|
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
424
424
|
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
425
|
-
<sl-
|
426
|
-
<sl-
|
427
|
-
<sl-
|
425
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
426
|
+
<sl-option value="2" checked="checked">Matz</sl-option>
|
427
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
428
428
|
</sl-select>
|
429
429
|
HTML
|
430
430
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoelace-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.4.
|
196
|
+
rubygems_version: 3.4.6
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Rails view helpers Shoelace.style, the design system.
|