view_component 1.17.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +3 -3
- data/Gemfile.lock +2 -2
- data/README.md +11 -10
- data/app/controllers/rails/{components_controller.rb → view_components_controller.rb} +1 -1
- data/lib/railties/lib/rails/templates/rails/components/index.html.erb +2 -2
- data/lib/railties/lib/rails/templates/rails/components/previews.html.erb +1 -1
- data/lib/view_component.rb +0 -14
- data/lib/view_component/base.rb +1 -1
- data/lib/view_component/engine.rb +15 -15
- data/lib/view_component/previewable.rb +2 -2
- data/lib/view_component/render_monkey_patch.rb +1 -19
- data/lib/view_component/rendering_monkey_patch.rb +1 -1
- data/lib/view_component/version.rb +2 -2
- metadata +2 -9
- data/lib/action_view/component.rb +0 -4
- data/lib/action_view/component/base.rb +0 -13
- data/lib/action_view/component/preview.rb +0 -8
- data/lib/action_view/component/railtie.rb +0 -3
- data/lib/action_view/component/test_case.rb +0 -9
- data/lib/action_view/component/test_helpers.rb +0 -17
- data/lib/view_component/conversion.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ac24e1dc67b91015f67efc09208e7b185c90bb1ca84de486b810dc1d699116
|
4
|
+
data.tar.gz: b87bcf3c0c50e8ca497757951736e9029cbd0411bdbd97134b136511f2855740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41aa382866ac371d48e305383df40fcfd8568c7ea4e98c0acf38784c7bee267adb40ce8a9b065de55a5c5622ca9e8584a55b66e838c7203a52fa5646eca4f0c6
|
7
|
+
data.tar.gz: e66a6eccab9e8774dea217944e2a00a38f09276aac57c200e0dee7075a9cfa096029d2ad28debc5ee6ea66ad7c3af2a3248a5f6803bbcc94198364a5cb2f98c4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# v2.0.0
|
4
|
+
|
5
|
+
* Move to `ViewComponent` namespace, removing all references to `ActionView`.
|
6
|
+
|
7
|
+
* The gem name is now `view_component`.
|
8
|
+
* ViewComponent previews are now accessed at `/rails/view_components`.
|
9
|
+
* ViewComponents can _only_ be rendered with the instance syntax: `render(MyComponent.new)`. Support for all other syntaxes has been removed.
|
10
|
+
* ActiveModel::Validations have been removed. ViewComponent generators no longer include validations.
|
11
|
+
* In Rails 6.1, no monkey patching is used.
|
12
|
+
* `to_component_class` has been removed.
|
13
|
+
* All gem configuration is now in `config.view_component`.
|
14
|
+
|
3
15
|
# v1.17.0
|
4
16
|
|
5
17
|
* Support Ruby 2.4 in CI.
|
data/CONTRIBUTING.md
CHANGED
@@ -34,13 +34,13 @@ Here are a few things you can do that will increase the likelihood of your pull
|
|
34
34
|
If you are the current maintainer of this gem:
|
35
35
|
|
36
36
|
1. Create a branch for the release: `git checkout -b release-vxx.xx.xx`
|
37
|
-
1. Bump gem version in `lib/
|
37
|
+
1. Bump gem version in `lib/view_component/version.rb`. Try to adhere to SemVer.
|
38
38
|
1. Add version heading/entries to `CHANGELOG.md`.
|
39
39
|
1. Make sure your local dependencies are up to date: `bundle`
|
40
40
|
1. Ensure that tests are green: `bundle exec rake`
|
41
41
|
1. Make a PR to github/view_component.
|
42
|
-
1. Build a local gem: `gem build
|
42
|
+
1. Build a local gem: `gem build view_component.gemspec`
|
43
43
|
1. Merge github/view_component PR
|
44
44
|
1. Tag and push: `git tag vx.xx.xx; git push --tags`
|
45
45
|
1. Create a GitHub release with the pushed tag (https://github.com/github/view_component/releases/new) and populate it with a list of the commits from `git log --pretty=format:"- %s" --reverse refs/tags/[OLD TAG]...refs/tags/[NEW TAG]`
|
46
|
-
1. Push to rubygems.org -- `gem push
|
46
|
+
1. Push to rubygems.org -- `gem push view_component-VERSION.gem`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
view_component (2.0.0)
|
5
5
|
capybara (~> 3)
|
6
6
|
|
7
7
|
GEM
|
@@ -187,7 +187,6 @@ PLATFORMS
|
|
187
187
|
ruby
|
188
188
|
|
189
189
|
DEPENDENCIES
|
190
|
-
actionview-component!
|
191
190
|
better_html (~> 1)
|
192
191
|
bundler (~> 1.14)
|
193
192
|
haml (~> 5)
|
@@ -197,6 +196,7 @@ DEPENDENCIES
|
|
197
196
|
rubocop (= 0.74)
|
198
197
|
rubocop-github (~> 0.13.0)
|
199
198
|
slim (~> 4.0)
|
199
|
+
view_component!
|
200
200
|
|
201
201
|
BUNDLED WITH
|
202
202
|
1.17.3
|
data/README.md
CHANGED
@@ -15,7 +15,8 @@ This gem is in the process of a name / API change from `ActionView::Component` t
|
|
15
15
|
|
16
16
|
### How to migrate to ViewComponent
|
17
17
|
|
18
|
-
1.
|
18
|
+
1. Update `Gemfile` to use `view_component`.
|
19
|
+
1. In `application.rb`, require `view_component/engine`.
|
19
20
|
1. Update components to inherit from `ViewComponent::Base`.
|
20
21
|
1. Update component tests to inherit from `ViewComponent::TestCase`.
|
21
22
|
1. Update component previews to inherit from `ViewComponent::Preview`.
|
@@ -33,14 +34,14 @@ This library is designed to integrate as seamlessly as possible with Rails, with
|
|
33
34
|
|
34
35
|
## Compatibility
|
35
36
|
|
36
|
-
`
|
37
|
+
`view_component` is tested for compatibility with combinations of Ruby `2.4`/`2.5`/`2.6`/`2.7` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`master`.
|
37
38
|
|
38
39
|
## Installation
|
39
40
|
|
40
41
|
In `Gemfile`, add:
|
41
42
|
|
42
43
|
```ruby
|
43
|
-
gem "
|
44
|
+
gem "view_component"
|
44
45
|
```
|
45
46
|
|
46
47
|
In `config/application.rb`, add:
|
@@ -322,9 +323,9 @@ class TestComponentPreview < ViewComponent::Preview
|
|
322
323
|
end
|
323
324
|
```
|
324
325
|
|
325
|
-
Which generates <http://localhost:3000/rails/
|
326
|
-
<http://localhost:3000/rails/
|
327
|
-
and <http://localhost:3000/rails/
|
326
|
+
Which generates <http://localhost:3000/rails/view_components/test_component/with_default_title>,
|
327
|
+
<http://localhost:3000/rails/view_components/test_component/with_long_title>,
|
328
|
+
and <http://localhost:3000/rails/view_components/test_component/with_content_block>.
|
328
329
|
|
329
330
|
The `ViewComponent::Preview` base class includes
|
330
331
|
[`ActionView::Helpers::TagHelper`][tag-helper], which provides the [`tag`][tag]
|
@@ -351,7 +352,7 @@ To use `lib/component_previews`:
|
|
351
352
|
|
352
353
|
`config/application.rb`
|
353
354
|
```ruby
|
354
|
-
config.
|
355
|
+
config.view_component.preview_path = "#{Rails.root}/lib/component_previews"
|
355
356
|
```
|
356
357
|
|
357
358
|
#### Configuring TestController
|
@@ -360,7 +361,7 @@ Component tests and previews assume the existence of an `ApplicationController`
|
|
360
361
|
|
361
362
|
`config/application.rb`
|
362
363
|
```ruby
|
363
|
-
config.
|
364
|
+
config.view_component.test_controller = "BaseController"
|
364
365
|
```
|
365
366
|
|
366
367
|
### Setting up RSpec
|
@@ -382,7 +383,7 @@ To use component previews:
|
|
382
383
|
|
383
384
|
`config/application.rb`
|
384
385
|
```ruby
|
385
|
-
config.
|
386
|
+
config.view_component.preview_path = "#{Rails.root}/spec/components/previews"
|
386
387
|
```
|
387
388
|
|
388
389
|
## Frequently Asked Questions
|
@@ -418,7 +419,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github
|
|
418
419
|
|
419
420
|
## Contributors
|
420
421
|
|
421
|
-
`
|
422
|
+
`view_component` is built by:
|
422
423
|
|
423
424
|
|<img src="https://avatars.githubusercontent.com/joelhawksley?s=256" alt="joelhawksley" width="128" />|<img src="https://avatars.githubusercontent.com/tenderlove?s=256" alt="tenderlove" width="128" />|<img src="https://avatars.githubusercontent.com/jonspalmer?s=256" alt="jonspalmer" width="128" />|<img src="https://avatars.githubusercontent.com/juanmanuelramallo?s=256" alt="juanmanuelramallo" width="128" />|<img src="https://avatars.githubusercontent.com/vinistock?s=256" alt="vinistock" width="128" />|
|
424
425
|
|:---:|:---:|:---:|:---:|:---:|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "rails/application_controller"
|
4
4
|
|
5
|
-
class Rails::
|
5
|
+
class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc:
|
6
6
|
prepend_view_path File.expand_path("../../../lib/railties/lib/rails/templates/rails", __dir__)
|
7
7
|
prepend_view_path "#{Rails.root}/app/views/" if defined?(Rails.root)
|
8
8
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<% @previews.each do |preview| %>
|
2
|
-
<h3><%= link_to preview.preview_name.titleize, "/rails/
|
2
|
+
<h3><%= link_to preview.preview_name.titleize, "/rails/view_components/#{preview.preview_name}" %></h3>
|
3
3
|
<ul>
|
4
4
|
<% preview.examples.each do |preview_example| %>
|
5
|
-
<li><%= link_to preview_example, "/rails/
|
5
|
+
<li><%= link_to preview_example, "/rails/view_components/#{preview.preview_name}/#{preview_example}" %></li>
|
6
6
|
<% end %>
|
7
7
|
</ul>
|
8
8
|
<% end %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h3><%= @preview.preview_name.titleize %></h3>
|
2
2
|
<ul>
|
3
3
|
<% @preview.examples.each do |example| %>
|
4
|
-
<li><%= link_to example, "/rails/
|
4
|
+
<li><%= link_to example, "/rails/view_components/#{@preview.preview_name}/#{example}" %></li>
|
5
5
|
<% end %>
|
6
6
|
</ul>
|
data/lib/view_component.rb
CHANGED
@@ -6,7 +6,6 @@ module ViewComponent
|
|
6
6
|
extend ActiveSupport::Autoload
|
7
7
|
|
8
8
|
autoload :Base
|
9
|
-
autoload :Conversion
|
10
9
|
autoload :Preview
|
11
10
|
autoload :Previewable
|
12
11
|
autoload :TestHelpers
|
@@ -15,16 +14,3 @@ module ViewComponent
|
|
15
14
|
autoload :RenderingMonkeyPatch
|
16
15
|
autoload :TemplateError
|
17
16
|
end
|
18
|
-
|
19
|
-
module ActionView
|
20
|
-
module Component
|
21
|
-
extend ActiveSupport::Autoload
|
22
|
-
|
23
|
-
autoload :Base
|
24
|
-
autoload :Preview
|
25
|
-
autoload :TestCase
|
26
|
-
autoload :TestHelpers
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
ActiveModel::Conversion.include ViewComponent::Conversion
|
data/lib/view_component/base.rb
CHANGED
@@ -5,10 +5,10 @@ require "view_component"
|
|
5
5
|
|
6
6
|
module ViewComponent
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
8
|
-
config.
|
8
|
+
config.view_component = ActiveSupport::OrderedOptions.new
|
9
9
|
|
10
|
-
initializer "
|
11
|
-
options = app.config.
|
10
|
+
initializer "view_component.set_configs" do |app|
|
11
|
+
options = app.config.view_component
|
12
12
|
|
13
13
|
options.show_previews = Rails.env.development? if options.show_previews.nil?
|
14
14
|
|
@@ -16,48 +16,48 @@ module ViewComponent
|
|
16
16
|
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/components/previews" : nil
|
17
17
|
end
|
18
18
|
|
19
|
-
ActiveSupport.on_load(:
|
19
|
+
ActiveSupport.on_load(:view_component) do
|
20
20
|
options.each { |k, v| send("#{k}=", v) }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
initializer "
|
25
|
-
options = app.config.
|
24
|
+
initializer "view_component.set_autoload_paths" do |app|
|
25
|
+
options = app.config.view_component
|
26
26
|
|
27
27
|
if options.show_previews && options.preview_path
|
28
28
|
ActiveSupport::Dependencies.autoload_paths << options.preview_path
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
initializer "
|
32
|
+
initializer "view_component.eager_load_actions" do
|
33
33
|
ActiveSupport.on_load(:after_initialize) do
|
34
34
|
ViewComponent::Base.descendants.each(&:compile)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
initializer "
|
39
|
-
ActiveSupport.on_load(:
|
38
|
+
initializer "view_component.compile_config_methods" do
|
39
|
+
ActiveSupport.on_load(:view_component) do
|
40
40
|
config.compile_methods! if config.respond_to?(:compile_methods!)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
initializer "
|
44
|
+
initializer "view_component.monkey_patch_render" do
|
45
45
|
ActiveSupport.on_load(:action_view) do
|
46
|
-
ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
|
46
|
+
ActionView::Base.prepend ViewComponent::RenderMonkeyPatch if Rails.version.to_f < 6.1
|
47
47
|
end
|
48
48
|
|
49
49
|
ActiveSupport.on_load(:action_controller) do
|
50
|
-
ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
|
50
|
+
ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch if Rails.version.to_f < 6.1
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
config.after_initialize do |app|
|
55
|
-
options = app.config.
|
55
|
+
options = app.config.view_component
|
56
56
|
|
57
57
|
if options.show_previews
|
58
58
|
app.routes.prepend do
|
59
|
-
get "/rails/
|
60
|
-
get "/rails/
|
59
|
+
get "/rails/view_components" => "rails/view_components#index", :internal => true
|
60
|
+
get "/rails/view_components/*path" => "rails/view_components#previews", :internal => true
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -9,13 +9,13 @@ module ViewComponent # :nodoc:
|
|
9
9
|
included do
|
10
10
|
# Set the location of component previews through app configuration:
|
11
11
|
#
|
12
|
-
# config.
|
12
|
+
# config.view_component.preview_path = "#{Rails.root}/lib/component_previews"
|
13
13
|
#
|
14
14
|
mattr_accessor :preview_path, instance_writer: false
|
15
15
|
|
16
16
|
# Enable or disable component previews through app configuration:
|
17
17
|
#
|
18
|
-
# config.
|
18
|
+
# config.view_component.show_previews = true
|
19
19
|
#
|
20
20
|
# Defaults to +true+ for development environment
|
21
21
|
#
|
@@ -3,26 +3,8 @@
|
|
3
3
|
module ViewComponent
|
4
4
|
module RenderMonkeyPatch # :nodoc:
|
5
5
|
def render(options = {}, args = {}, &block)
|
6
|
-
if options.respond_to?(:render_in)
|
6
|
+
if options.respond_to?(:render_in)
|
7
7
|
options.render_in(self, &block)
|
8
|
-
elsif options.is_a?(Class) && options < ActionView::Component::Base
|
9
|
-
ActiveSupport::Deprecation.warn(
|
10
|
-
"`render MyComponent, foo: :bar` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
|
11
|
-
)
|
12
|
-
|
13
|
-
options.new(args).render_in(self, &block)
|
14
|
-
elsif options.is_a?(Hash) && options.has_key?(:component) && options[:component] < ActionView::Component::Base
|
15
|
-
ActiveSupport::Deprecation.warn(
|
16
|
-
"`render component: MyComponent, locals: { foo: :bar }` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
|
17
|
-
)
|
18
|
-
|
19
|
-
options[:component].new(options[:locals]).render_in(self, &block)
|
20
|
-
elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil? && options.to_component_class < ActionView::Component::Base
|
21
|
-
ActiveSupport::Deprecation.warn(
|
22
|
-
"rendering objects that respond_to `to_component_class` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
|
23
|
-
)
|
24
|
-
|
25
|
-
options.to_component_class.new(options).render_in(self, &block)
|
26
8
|
else
|
27
9
|
super
|
28
10
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module ViewComponent
|
4
4
|
module RenderingMonkeyPatch # :nodoc:
|
5
5
|
def render(options = {}, args = {})
|
6
|
-
if options.respond_to?(:render_in)
|
6
|
+
if options.respond_to?(:render_in)
|
7
7
|
self.response_body = options.render_in(self.view_context)
|
8
8
|
else
|
9
9
|
super
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
@@ -156,14 +156,8 @@ files:
|
|
156
156
|
- LICENSE.txt
|
157
157
|
- README.md
|
158
158
|
- Rakefile
|
159
|
-
- app/controllers/rails/
|
159
|
+
- app/controllers/rails/view_components_controller.rb
|
160
160
|
- docs/case-studies/jellyswitch.md
|
161
|
-
- lib/action_view/component.rb
|
162
|
-
- lib/action_view/component/base.rb
|
163
|
-
- lib/action_view/component/preview.rb
|
164
|
-
- lib/action_view/component/railtie.rb
|
165
|
-
- lib/action_view/component/test_case.rb
|
166
|
-
- lib/action_view/component/test_helpers.rb
|
167
161
|
- lib/rails/generators/component/USAGE
|
168
162
|
- lib/rails/generators/component/component_generator.rb
|
169
163
|
- lib/rails/generators/component/templates/component.rb.tt
|
@@ -183,7 +177,6 @@ files:
|
|
183
177
|
- lib/railties/lib/rails/templates/rails/components/previews.html.erb
|
184
178
|
- lib/view_component.rb
|
185
179
|
- lib/view_component/base.rb
|
186
|
-
- lib/view_component/conversion.rb
|
187
180
|
- lib/view_component/engine.rb
|
188
181
|
- lib/view_component/preview.rb
|
189
182
|
- lib/view_component/previewable.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
module Component
|
5
|
-
module TestHelpers
|
6
|
-
include ViewComponent::TestHelpers
|
7
|
-
|
8
|
-
def render_component(component, **args, &block)
|
9
|
-
ActiveSupport::Deprecation.warn(
|
10
|
-
"`render_component` has been deprecated in favor of `render_inline`, and will be removed in v2.0.0."
|
11
|
-
)
|
12
|
-
|
13
|
-
render_inline(component, args, &block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|