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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91485b58594a99f3189bf1ee9eb24f5943e264dc3581b1331d8586b0547923df
4
- data.tar.gz: 47629f3e6d93eaf333dffb53f2d465fdf8669034aa48592a9e144de04e67fe86
3
+ metadata.gz: 45ac24e1dc67b91015f67efc09208e7b185c90bb1ca84de486b810dc1d699116
4
+ data.tar.gz: b87bcf3c0c50e8ca497757951736e9029cbd0411bdbd97134b136511f2855740
5
5
  SHA512:
6
- metadata.gz: 650f7631c2b3b11ab5399c567e96639158641484950c70aefc1c73982b79c8fc19082cd1d3b9571806af5576aa5417e1aad8682353ad9031c52d89b127478b0a
7
- data.tar.gz: 2d7bccb44d21f6a9232b39b278cb66dc2deb068ea00660fbabfa2737e28c70dbc09a4990fecb308c1ae318839480010f07aa7b6bf3df69259d8ff9b275afa2d4
6
+ metadata.gz: 41aa382866ac371d48e305383df40fcfd8568c7ea4e98c0acf38784c7bee267adb40ce8a9b065de55a5c5622ca9e8584a55b66e838c7203a52fa5646eca4f0c6
7
+ data.tar.gz: e66a6eccab9e8774dea217944e2a00a38f09276aac57c200e0dee7075a9cfa096029d2ad28debc5ee6ea66ad7c3af2a3248a5f6803bbcc94198364a5cb2f98c4
@@ -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.
@@ -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/action_view/component/version.rb`. Try to adhere to SemVer.
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 actionview-component.gemspec`
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 actionview-component-VERSION.gem`
46
+ 1. Push to rubygems.org -- `gem push view_component-VERSION.gem`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.17.0)
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. In `application.rb`, require `view_component/engine`
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
- `actionview-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
+ `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 "actionview-component"
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/components/test_component/with_default_title>,
326
- <http://localhost:3000/rails/components/test_component/with_long_title>,
327
- and <http://localhost:3000/rails/components/test_component/with_content_block>.
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.action_view_component.preview_path = "#{Rails.root}/lib/component_previews"
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.action_view_component.test_controller = "BaseController"
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.action_view_component.preview_path = "#{Rails.root}/spec/components/previews"
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
- `actionview-component` is built by:
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::ComponentsController < Rails::ApplicationController # :nodoc:
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/components/#{preview.preview_name}" %></h3>
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/components/#{preview.preview_name}/#{preview_example}" %></li>
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/components/#{@preview.preview_name}/#{example}" %></li>
4
+ <li><%= link_to example, "/rails/view_components/#{@preview.preview_name}/#{example}" %></li>
5
5
  <% end %>
6
6
  </ul>
@@ -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
@@ -274,6 +274,6 @@ module ViewComponent
274
274
  end
275
275
  end
276
276
 
277
- ActiveSupport.run_load_hooks(:action_view_component, self)
277
+ ActiveSupport.run_load_hooks(:view_component, self)
278
278
  end
279
279
  end
@@ -5,10 +5,10 @@ require "view_component"
5
5
 
6
6
  module ViewComponent
7
7
  class Engine < Rails::Engine # :nodoc:
8
- config.action_view_component = ActiveSupport::OrderedOptions.new
8
+ config.view_component = ActiveSupport::OrderedOptions.new
9
9
 
10
- initializer "action_view_component.set_configs" do |app|
11
- options = app.config.action_view_component
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(:action_view_component) do
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 "action_view_component.set_autoload_paths" do |app|
25
- options = app.config.action_view_component
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 "action_view_component.eager_load_actions" do
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 "action_view_component.compile_config_methods" do
39
- ActiveSupport.on_load(:action_view_component) do
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 "action_view_component.monkey_patch_render" do
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.action_view_component
55
+ options = app.config.view_component
56
56
 
57
57
  if options.show_previews
58
58
  app.routes.prepend do
59
- get "/rails/components" => "rails/components#index", :internal => true
60
- get "/rails/components/*path" => "rails/components#previews", :internal => true
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.action_view_component.preview_path = "#{Rails.root}/lib/component_previews"
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.action_view_component.show_previews = true
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) && Rails.version.to_f < 6.1
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) && Rails.version.to_f < 6.1
6
+ if options.respond_to?(:render_in)
7
7
  self.response_body = options.render_in(self.view_context)
8
8
  else
9
9
  super
@@ -2,8 +2,8 @@
2
2
 
3
3
  module ViewComponent
4
4
  module VERSION
5
- MAJOR = 1
6
- MINOR = 17
5
+ MAJOR = 2
6
+ MINOR = 0
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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: 1.17.0
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/components_controller.rb
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,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_model"
4
- require "view_component"
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component
5
- class Base < ViewComponent::Base
6
- include ActiveModel::Validations
7
-
8
- def before_render_check
9
- validate!
10
- end
11
- end
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component # :nodoc:
5
- class Preview < ViewComponent::Preview
6
- end
7
- end
8
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "view_component/engine"
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component
5
- class TestCase
6
- include ActionView::Component::TestHelpers
7
- end
8
- end
9
- end
@@ -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
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent # :nodoc:
4
- module Conversion
5
- def to_component_class
6
- "#{self.class.name}Component".safe_constantize
7
- end
8
- end
9
- end