shoelace-rails 0.1.0 → 0.2.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: 1c7cf138c772d734257018fa691d7082b04caf56da45e2d5243041d9a90e345b
4
- data.tar.gz: 1902dd8b4ee4d41e57dd3ede4bfe4c71f21a1fc7607d02524e052667a3481330
3
+ metadata.gz: 43863053db02a41a1fd24e9a2b82f72a10ed5ef99e90bedc142b7cb9a3d94696
4
+ data.tar.gz: 6615e13ecde994ab1e5c029c84cd3e1bdc5be11a5262fe5b887d0b18b86115e1
5
5
  SHA512:
6
- metadata.gz: e6fb93a87eabac57355bd4a2a7d567d1e94680c0b59d0dc40731d46b76b3eb4ca74cce56f6c720b7bd63f4845de37a93a735a8013ea21e3d1d7a3c8b5aa22722
7
- data.tar.gz: de7ddf7f75dee4a26b71eb95cf1ae3d29e9884080a25abe8f575352b0068a3c5d5e459852947ce8d286999cec6ca218efd77f9587f32ba9c44efd56ceac8fc6f
6
+ metadata.gz: 5fadffcefc1ac4a5be597e5b6274ea8f5463ee375dd535c6b42f4fb34c02fd8ef0c80dfe4fe7bb889c1096968c83d82b6e7ba5c1641dad7c8cf3761b4723447d
7
+ data.tar.gz: 56398431cd8865bacaae5daf55a4076b0ab2c5857878a89994c13209fae098273c0fe4d2032b890473b71147074884f476a1dd09f86129e58fcab0810e6e4722
@@ -17,13 +17,14 @@ jobs:
17
17
  - gemfiles/rails_70.gemfile
18
18
  - gemfiles/rails_61.gemfile
19
19
  - gemfiles/rails_60.gemfile
20
+ exclude:
21
+ - ruby_version: 'jruby-9.3.3.0'
22
+ gemfile: gemfiles/rails_70.gemfile
20
23
  runs-on: ubuntu-18.04
21
24
  env:
22
25
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
23
26
  steps:
24
27
  - uses: actions/checkout@v2
25
- - name: Install curl
26
- run: sudo apt-get install curl libcurl4-openssl-dev
27
28
  - name: Set up Ruby
28
29
  uses: ruby/setup-ruby@v1
29
30
  with:
@@ -32,6 +33,7 @@ jobs:
32
33
  - run: bundle exec rake test
33
34
 
34
35
  system:
36
+ needs: unit
35
37
  runs-on: ubuntu-18.04
36
38
  steps:
37
39
  - uses: actions/checkout@v2
@@ -49,6 +51,39 @@ jobs:
49
51
  - name: Run the system test in the dummy app
50
52
  run: rake test:system
51
53
 
54
+ rails_edge:
55
+ needs: system
56
+ runs-on: ubuntu-18.04
57
+ env:
58
+ BUNDLE_GEMFILE: gemfiles/rails_edge.gemfile
59
+ steps:
60
+ - uses: actions/checkout@v2
61
+ - name: Set up Ruby
62
+ uses: ruby/setup-ruby@v1
63
+ with:
64
+ ruby-version: 3.1
65
+ bundler-cache: true
66
+ - run: bundle exec rake test || echo "Rails edge test is done."
67
+
68
+ ruby_edge:
69
+ needs: system
70
+ strategy:
71
+ matrix:
72
+ gemfile:
73
+ - gemfiles/rails_edge.gemfile
74
+ - gemfiles/rails_70.gemfile
75
+ runs-on: ubuntu-18.04
76
+ env:
77
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
78
+ steps:
79
+ - uses: actions/checkout@v2
80
+ - name: Set up Ruby
81
+ uses: ruby/setup-ruby@v1
82
+ with:
83
+ ruby-version: 'ruby-head'
84
+ bundler-cache: true
85
+ - run: bundle exec rake || echo "Ruby edge test is done."
86
+
52
87
  # browser_tests:
53
88
  # runs-on: ubuntu-18.04
54
89
  # steps:
data/Appraisals CHANGED
@@ -7,9 +7,9 @@ appraise "rails_edge" do
7
7
  end
8
8
 
9
9
  appraise "rails_70" do
10
- gem "rails", "~> 6.1.0"
11
- gem "railties", "~> 6.1.0"
12
- gem "activesupport", "~> 6.1.0"
10
+ gem "rails", "~> 7.0.0"
11
+ gem "railties", "~> 7.0.0"
12
+ gem "activesupport", "~> 7.0.0"
13
13
  end
14
14
 
15
15
  appraise "rails_61" do
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
- ## [0.1.0] - 2022-02-17
1
+ ## v0.2.0
2
+
3
+ #### Features
4
+
5
+ - Do not require the `copy-webpack-plugin` to set up Shoelace so the gem works with any js bundler.
6
+
7
+ ## [v0.1.0](https://github.com/yuki24/shoelace-rails/tree/v0.1.0)
8
+
9
+ _<sup>released at 2022-02-17 13:17:09 UTC</sup>_
10
+
11
+ First release!
2
12
 
3
- - First release!
data/README.md CHANGED
@@ -23,7 +23,7 @@ $ bundle install
23
23
  Additionally, you need to add the following npm packages:
24
24
 
25
25
  ```sh
26
- $ yarn add @shoelace-style/shoelace copy-webpack-plugin
26
+ $ yarn add @shoelace-style/shoelace
27
27
  ```
28
28
 
29
29
  ## Set up CSS
@@ -50,62 +50,23 @@ import "@shoelace-style/shoelace/dist/themes/dark.css" // Optional dark mode
50
50
 
51
51
  ## Set up Javascript
52
52
 
53
- In order to use Shoelace the icons need to be copied to the `public/assets` directory so they will show pu properly.
54
-
55
- If you are using the `jsbundling-rails` gem and have `webpack.config.js` in the top level directory of your project, Add th
56
- e configuration for the `CopyPlugin`:
53
+ In this README, it is assumed that you are using a JS bundler such as `webpack` or `esbuild`. In order to define all
54
+ the custome elements, import the shoelace dependency in the entrypoint file:
57
55
 
58
56
  ```js
59
- // webpack.config.js
60
- const CopyPlugin = require("copy-webpack-plugin")
61
- const path = require('path')
62
-
63
- module.exports = {
64
- ...,
65
- plugins: [
66
- new CopyPlugin({
67
- patterns: [
68
- {
69
- from: path.resolve(__dirname, "node_modules/@shoelace-style/shoelace/dist/assets"),
70
- to: path.resolve(__dirname, "public/assets"),
71
- },
72
- ],
73
- }),
74
- ],
75
- }
57
+ import "@shoelace-style/shoelace"
76
58
  ```
77
59
 
78
- If you are using the `webpacker` gem, you could add the same configuration but to `config/webpack/environment.js`:
79
-
80
- ```js
81
- // config/webpack/environment.js
82
- const { environment } = require('@rails/webpacker')
83
- const path = require('path')
84
- const CopyPlugin = require('copy-webpack-plugin')
85
-
86
- // Add shoelace icons to webpack's build process
87
- environment.plugins.append(
88
- 'CopyPlugin',
89
- new CopyPlugin({
90
- patterns: [
91
- {
92
- from: path.resolve(__dirname, '../../node_modules/@shoelace-style/shoelace/dist/assets'),
93
- to: path.resolve(__dirname, '../../public/packs/js/assets')
94
- }
95
- ]
96
- })
97
- )
98
-
99
- module.exports = environment
100
- ```
60
+ That's it!
101
61
 
102
- Finally, import the shoelace dependency in the entrypoint file:
62
+ ### Shoelace Icons
103
63
 
104
- ```js
105
- import "@shoelace-style/shoelace"
106
- ```
64
+ Shoelace icons are automatically set up to load properly, so you don't need to add any extra code. More specifically,
107
65
 
108
- That's it!
66
+ * In development, the icons are served by the `ActionDispatch::Static` middleware, directly from the
67
+ `node_modules/@shoelace-style/shoelace/dist/assets/icons` directory.
68
+ * In production, the icon files are automatically copied into the `public/assets` directory as part of the
69
+ `assets:precompile` rake task.
109
70
 
110
71
  ## View Helpers
111
72
 
@@ -133,7 +94,7 @@ As explained above, this gem provides drop-in replacements to. Here is a short e
133
94
  And this code will produce:
134
95
 
135
96
  ```html
136
- <sl-form class="new_user" id="new_user" data-remote="true" action="/" accept-charset="UTF-8" method="post">
97
+ <form class="new_user" id="new_user" data-remote="true" action="/" accept-charset="UTF-8" method="post">
137
98
  <sl-input label="Name" type="text" name="user[name]" id="user_name"></sl-input>
138
99
  <sl-input label="Password" type="password" name="user[password]" id="user_password"></sl-input>
139
100
  <sl-color-picker value="#ffffff" name="user[color]" id="user_color"></sl-color-picker>
@@ -151,7 +112,7 @@ And this code will produce:
151
112
  </sl-select>
152
113
 
153
114
  <sl-button submit="true" type="primary" data-disable-with="Create User">Create User</sl-button>
154
- </sl-form>
115
+ </form>
155
116
  ```
156
117
 
157
118
  ## Development
@@ -4,8 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rake", "~> 13.0"
6
6
  gem "rails-dom-testing", git: "https://github.com/rails/rails-dom-testing.git", ref: "8f5acdfc"
7
- gem "rails", "~> 6.1.0"
8
- gem "railties", "~> 6.1.0"
9
- gem "activesupport", "~> 6.1.0"
7
+ gem "rails", "~> 7.0.0"
8
+ gem "railties", "~> 7.0.0"
9
+ gem "activesupport", "~> 7.0.0"
10
10
 
11
11
  gemspec path: "../"
@@ -2,7 +2,5 @@
2
2
 
3
3
  module Shoelace
4
4
  class Engine < ::Rails::Engine #:nodoc:
5
- config.shoelace = ActiveSupport::OrderedOptions.new
6
- config.shoelace.use_sl_form_tag = false
7
5
  end
8
6
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Shoelace
4
4
  module Rails
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rails/version"
4
- require_relative "engine" if defined?(::Rails::Railtie)
4
+
5
+ if defined?(::Rails::Railtie)
6
+ require_relative "engine"
7
+ require_relative "railtie"
8
+ end
5
9
 
6
10
  module Shoelace
7
11
  module Rails
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_dispatch/middleware/static'
4
+
5
+ module Shoelace
6
+ # The only reason this class exists is to clarify that we have a custom static file server after
7
+ # `ActionDispatch::Static`. We could just use `ActionDispatch::Static` directly, but it would make the result of
8
+ # `rake middleware` more difficult to understand, as the output would look like:
9
+ #
10
+ # use ...
11
+ # use ActionDispatch::Static
12
+ # use ActionDispatch::Static # Why do we use the same middleware twice?
13
+ # use ...
14
+ #
15
+ # It is much more straightforward if it looks like:
16
+ #
17
+ # use ...
18
+ # use ActionDispatch::Static
19
+ # use Shoelace::AssetProvider
20
+ # use ...
21
+ #
22
+ class AssetProvider < ActionDispatch::Static; end
23
+
24
+ class Railtie < ::Rails::Railtie #:nodoc:
25
+ config.shoelace = ActiveSupport::OrderedOptions.new
26
+ config.shoelace.use_sl_form_tag = false
27
+ config.shoelace.dist_path = "node_modules/@shoelace-style/shoelace/dist"
28
+
29
+ initializer "shoelace.use_rack_middleware" do |app|
30
+ icon_dir = File.join(app.paths["public"].first, "assets/icons")
31
+
32
+ if !Dir.exist?(icon_dir)
33
+ path = app.root.join(config.shoelace.dist_path).to_s
34
+ headers = app.config.public_file_server.headers || {}
35
+
36
+ app.config.middleware.insert_after ActionDispatch::Static, Shoelace::AssetProvider, path, index: "index.html", headers: headers
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ namespace :shoelace do
2
+ namespace :icons do
3
+ desc "Copy Shoelace icons to the assets path"
4
+ task copy: :environment do
5
+ cp_r Rails.root.join(Shoelace::Railtie.config.shoelace.dist_path, "assets").to_s, Rails.public_path
6
+ end
7
+
8
+ desc "Remove Shoelace icons"
9
+ task clobber: :environment do
10
+ rm_rf File.join(Rails.public_path, "assets/icons")
11
+ end
12
+ end
13
+ end
14
+
15
+ if Rake::Task.task_defined?("assets:precompile")
16
+ Rake::Task["assets:precompile"].enhance(["shoelace:icons:copy"])
17
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  require_relative '../../app/helpers/shoelace/form_helper'
@@ -5,6 +6,8 @@ require_relative '../../app/helpers/shoelace/form_helper'
5
6
  class FormHelperTest < ActionView::TestCase
6
7
  include Shoelace::FormHelper
7
8
 
9
+ AUTOCOMPLETE_ATTRIBUTE = ActionView::VERSION::STRING >= '6.1.0' ? 'autocomplete="off"' : ''
10
+
8
11
  test "#sl_text_field_tag with name and value" do
9
12
  assert_dom_equal <<~HTML, sl_text_field_tag('name', 'Your name')
10
13
  <sl-input type="text" name="name" id="name" value="Your name"></sl-input>
@@ -56,7 +59,7 @@ class FormHelperTest < ActionView::TestCase
56
59
  test "#sl_form_tag" do
57
60
  assert_dom_equal(<<~HTML, sl_form_tag("/posts") { })
58
61
  <form data-remote="true" action="/posts" accept-charset="UTF-8" method="post">
59
- <input name="utf8" type="hidden" value="&#x2713;" />
62
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
60
63
  </sl-form>
61
64
  HTML
62
65
  end
@@ -64,7 +67,7 @@ class FormHelperTest < ActionView::TestCase
64
67
  test "#sl_form_with" do
65
68
  assert_dom_equal(<<~HTML, sl_form_with(url: "/") {})
66
69
  <form action="/" accept-charset="UTF-8" data-remote="true" method="post">
67
- <input name="utf8" type="hidden" value="&#x2713;" />
70
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
68
71
  </sl-form>
69
72
  HTML
70
73
  end
@@ -72,7 +75,7 @@ class FormHelperTest < ActionView::TestCase
72
75
  test "#sl_form_for" do
73
76
  assert_dom_equal(<<~HTML, sl_form_for(User.new, url: "/") { })
74
77
  <form class="new_user" id="new_user" action="/" accept-charset="UTF-8" method="post">
75
- <input name="utf8" type="hidden" value="&#x2713;" />
78
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
76
79
  </sl-form>
77
80
  HTML
78
81
  end
@@ -80,7 +83,7 @@ class FormHelperTest < ActionView::TestCase
80
83
  test "#sl_turbo_form_tag" do
81
84
  assert_dom_equal(<<~HTML, sl_turbo_form_tag("/posts") { })
82
85
  <form action="/posts" accept-charset="UTF-8" method="post">
83
- <input name="utf8" type="hidden" value="&#x2713;" />
86
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
84
87
  </form>
85
88
  HTML
86
89
  end
@@ -88,7 +91,7 @@ class FormHelperTest < ActionView::TestCase
88
91
  test "#sl_turbo_form_with" do
89
92
  assert_dom_equal(<<~HTML, sl_turbo_form_with(url: "/") {})
90
93
  <form action="/" accept-charset="UTF-8" data-remote="true" method="post">
91
- <input name="utf8" type="hidden" value="&#x2713;" />
94
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
92
95
  </form>
93
96
  HTML
94
97
  end
@@ -96,7 +99,7 @@ class FormHelperTest < ActionView::TestCase
96
99
  test "#sl_turbo_form_for" do
97
100
  assert_dom_equal(<<~HTML, sl_turbo_form_for(User.new, url: "/") { })
98
101
  <form class="new_user" id="new_user" action="/" accept-charset="UTF-8" method="post">
99
- <input name="utf8" type="hidden" value="&#x2713;" />
102
+ <input name="utf8" type="hidden" value="&#x2713;" #{AUTOCOMPLETE_ATTRIBUTE} />
100
103
  </form>
101
104
  HTML
102
105
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -112,7 +112,9 @@ files:
112
112
  - lib/shoelace/engine.rb
113
113
  - lib/shoelace/rails.rb
114
114
  - lib/shoelace/rails/version.rb
115
+ - lib/shoelace/railtie.rb
115
116
  - lib/shoelace/testing.rb
117
+ - lib/tasks/assets.rake
116
118
  - package.json
117
119
  - rollup.config.js
118
120
  - shoelace-rails.gemspec
@@ -189,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
191
  - !ruby/object:Gem::Version
190
192
  version: '0'
191
193
  requirements: []
192
- rubygems_version: 3.3.3
194
+ rubygems_version: 3.3.7
193
195
  signing_key:
194
196
  specification_version: 4
195
197
  summary: Rails view helpers Shoelace.style, the design system.