Skip to content

Commit

Permalink
Merge pull request #268 from github/131-v2.0.0
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
joelhawksley authored Mar 23, 2020
2 parents be46b71 + 58be310 commit a1635d4
Show file tree
Hide file tree
Showing 38 changed files with 77 additions and 247 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# master

# v2.0.0

* Move to `ViewComponent` namespace, removing all references to `ActionView`.

* The gem name is now `view_component`.
* ViewComponent previews are now accessed at `/rails/view_components`.
* ViewComponents can _only_ be rendered with the instance syntax: `render(MyComponent.new)`. Support for all other syntaxes has been removed.
* ActiveModel::Validations have been removed. ViewComponent generators no longer include validations.
* In Rails 6.1, no monkey patching is used.
* `to_component_class` has been removed.
* All gem configuration is now in `config.view_component`.

# v1.17.0

* Support Ruby 2.4 in CI.
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Here are a few things you can do that will increase the likelihood of your pull
If you are the current maintainer of this gem:

1. Create a branch for the release: `git checkout -b release-vxx.xx.xx`
1. Bump gem version in `lib/action_view/component/version.rb`. Try to adhere to SemVer.
1. Bump gem version in `lib/view_component/version.rb`. Try to adhere to SemVer.
1. Add version heading/entries to `CHANGELOG.md`.
1. Make sure your local dependencies are up to date: `bundle`
1. Ensure that tests are green: `bundle exec rake`
1. Make a PR to github/view_component.
1. Build a local gem: `gem build actionview-component.gemspec`
1. Build a local gem: `gem build view_component.gemspec`
1. Merge github/view_component PR
1. Tag and push: `git tag vx.xx.xx; git push --tags`
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]`
1. Push to rubygems.org -- `gem push actionview-component-VERSION.gem`
1. Push to rubygems.org -- `gem push view_component-VERSION.gem`
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
actionview-component (1.17.0)
view_component (2.0.0)
capybara (~> 3)

GEM
Expand Down Expand Up @@ -187,7 +187,6 @@ PLATFORMS
ruby

DEPENDENCIES
actionview-component!
better_html (~> 1)
bundler (~> 1.14)
haml (~> 5)
Expand All @@ -197,6 +196,7 @@ DEPENDENCIES
rubocop (= 0.74)
rubocop-github (~> 0.13.0)
slim (~> 4.0)
view_component!

BUNDLED WITH
1.17.3
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ This gem is in the process of a name / API change from `ActionView::Component` t

### How to migrate to ViewComponent

1. In `application.rb`, require `view_component/engine`
1. Update `Gemfile` to use `view_component`.
1. In `application.rb`, require `view_component/engine`.
1. Update components to inherit from `ViewComponent::Base`.
1. Update component tests to inherit from `ViewComponent::TestCase`.
1. Update component previews to inherit from `ViewComponent::Preview`.
Expand All @@ -33,14 +34,14 @@ This library is designed to integrate as seamlessly as possible with Rails, with

## Compatibility

`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`.
`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`.

## Installation

In `Gemfile`, add:

```ruby
gem "actionview-component"
gem "view_component"
```

In `config/application.rb`, add:
Expand Down Expand Up @@ -322,9 +323,9 @@ class TestComponentPreview < ViewComponent::Preview
end
```

Which generates <http://localhost:3000/rails/components/test_component/with_default_title>,
<http://localhost:3000/rails/components/test_component/with_long_title>,
and <http://localhost:3000/rails/components/test_component/with_content_block>.
Which generates <http://localhost:3000/rails/view_components/test_component/with_default_title>,
<http://localhost:3000/rails/view_components/test_component/with_long_title>,
and <http://localhost:3000/rails/view_components/test_component/with_content_block>.

The `ViewComponent::Preview` base class includes
[`ActionView::Helpers::TagHelper`][tag-helper], which provides the [`tag`][tag]
Expand All @@ -351,7 +352,7 @@ To use `lib/component_previews`:

`config/application.rb`
```ruby
config.action_view_component.preview_path = "#{Rails.root}/lib/component_previews"
config.view_component.preview_path = "#{Rails.root}/lib/component_previews"
```

#### Configuring TestController
Expand All @@ -360,7 +361,7 @@ Component tests and previews assume the existence of an `ApplicationController`

`config/application.rb`
```ruby
config.action_view_component.test_controller = "BaseController"
config.view_component.test_controller = "BaseController"
```

### Setting up RSpec
Expand All @@ -382,7 +383,7 @@ To use component previews:

`config/application.rb`
```ruby
config.action_view_component.preview_path = "#{Rails.root}/spec/components/previews"
config.view_component.preview_path = "#{Rails.root}/spec/components/previews"
```

## Frequently Asked Questions
Expand Down Expand Up @@ -418,7 +419,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github

## Contributors

`actionview-component` is built by:
`view_component` is built by:

|<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" />|
|:---:|:---:|:---:|:---:|:---:|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails/application_controller"

class Rails::ComponentsController < Rails::ApplicationController # :nodoc:
class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc:
prepend_view_path File.expand_path("../../../lib/railties/lib/rails/templates/rails", __dir__)
prepend_view_path "#{Rails.root}/app/views/" if defined?(Rails.root)

Expand Down
4 changes: 0 additions & 4 deletions lib/action_view/component.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/action_view/component/base.rb

This file was deleted.

8 changes: 0 additions & 8 deletions lib/action_view/component/preview.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/action_view/component/railtie.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/action_view/component/test_case.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/action_view/component/test_helpers.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% @previews.each do |preview| %>
<h3><%= link_to preview.preview_name.titleize, "/rails/components/#{preview.preview_name}" %></h3>
<h3><%= link_to preview.preview_name.titleize, "/rails/view_components/#{preview.preview_name}" %></h3>
<ul>
<% preview.examples.each do |preview_example| %>
<li><%= link_to preview_example, "/rails/components/#{preview.preview_name}/#{preview_example}" %></li>
<li><%= link_to preview_example, "/rails/view_components/#{preview.preview_name}/#{preview_example}" %></li>
<% end %>
</ul>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3><%= @preview.preview_name.titleize %></h3>
<ul>
<% @preview.examples.each do |example| %>
<li><%= link_to example, "/rails/components/#{@preview.preview_name}/#{example}" %></li>
<li><%= link_to example, "/rails/view_components/#{@preview.preview_name}/#{example}" %></li>
<% end %>
</ul>
14 changes: 0 additions & 14 deletions lib/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module ViewComponent
extend ActiveSupport::Autoload

autoload :Base
autoload :Conversion
autoload :Preview
autoload :Previewable
autoload :TestHelpers
Expand All @@ -15,16 +14,3 @@ module ViewComponent
autoload :RenderingMonkeyPatch
autoload :TemplateError
end

module ActionView
module Component
extend ActiveSupport::Autoload

autoload :Base
autoload :Preview
autoload :TestCase
autoload :TestHelpers
end
end

ActiveModel::Conversion.include ViewComponent::Conversion
2 changes: 1 addition & 1 deletion lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,6 @@ def compiled_template(file_path)
end
end

ActiveSupport.run_load_hooks(:action_view_component, self)
ActiveSupport.run_load_hooks(:view_component, self)
end
end
9 changes: 0 additions & 9 deletions lib/view_component/conversion.rb

This file was deleted.

30 changes: 15 additions & 15 deletions lib/view_component/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,59 @@

module ViewComponent
class Engine < Rails::Engine # :nodoc:
config.action_view_component = ActiveSupport::OrderedOptions.new
config.view_component = ActiveSupport::OrderedOptions.new

initializer "action_view_component.set_configs" do |app|
options = app.config.action_view_component
initializer "view_component.set_configs" do |app|
options = app.config.view_component

options.show_previews = Rails.env.development? if options.show_previews.nil?

if options.show_previews
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/components/previews" : nil
end

ActiveSupport.on_load(:action_view_component) do
ActiveSupport.on_load(:view_component) do
options.each { |k, v| send("#{k}=", v) }
end
end

initializer "action_view_component.set_autoload_paths" do |app|
options = app.config.action_view_component
initializer "view_component.set_autoload_paths" do |app|
options = app.config.view_component

if options.show_previews && options.preview_path
ActiveSupport::Dependencies.autoload_paths << options.preview_path
end
end

initializer "action_view_component.eager_load_actions" do
initializer "view_component.eager_load_actions" do
ActiveSupport.on_load(:after_initialize) do
ViewComponent::Base.descendants.each(&:compile)
end
end

initializer "action_view_component.compile_config_methods" do
ActiveSupport.on_load(:action_view_component) do
initializer "view_component.compile_config_methods" do
ActiveSupport.on_load(:view_component) do
config.compile_methods! if config.respond_to?(:compile_methods!)
end
end

initializer "action_view_component.monkey_patch_render" do
initializer "view_component.monkey_patch_render" do
ActiveSupport.on_load(:action_view) do
ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
ActionView::Base.prepend ViewComponent::RenderMonkeyPatch if Rails.version.to_f < 6.1
end

ActiveSupport.on_load(:action_controller) do
ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch if Rails.version.to_f < 6.1
end
end

config.after_initialize do |app|
options = app.config.action_view_component
options = app.config.view_component

if options.show_previews
app.routes.prepend do
get "/rails/components" => "rails/components#index", :internal => true
get "/rails/components/*path" => "rails/components#previews", :internal => true
get "/rails/view_components" => "rails/view_components#index", :internal => true
get "/rails/view_components/*path" => "rails/view_components#previews", :internal => true
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/previewable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module Previewable
included do
# Set the location of component previews through app configuration:
#
# config.action_view_component.preview_path = "#{Rails.root}/lib/component_previews"
# config.view_component.preview_path = "#{Rails.root}/lib/component_previews"
#
mattr_accessor :preview_path, instance_writer: false

# Enable or disable component previews through app configuration:
#
# config.action_view_component.show_previews = true
# config.view_component.show_previews = true
#
# Defaults to +true+ for development environment
#
Expand Down
20 changes: 1 addition & 19 deletions lib/view_component/render_monkey_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,8 @@
module ViewComponent
module RenderMonkeyPatch # :nodoc:
def render(options = {}, args = {}, &block)
if options.respond_to?(:render_in) && Rails.version.to_f < 6.1
if options.respond_to?(:render_in)
options.render_in(self, &block)
elsif options.is_a?(Class) && options < ActionView::Component::Base
ActiveSupport::Deprecation.warn(
"`render MyComponent, foo: :bar` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
)

options.new(args).render_in(self, &block)
elsif options.is_a?(Hash) && options.has_key?(:component) && options[:component] < ActionView::Component::Base
ActiveSupport::Deprecation.warn(
"`render component: MyComponent, locals: { foo: :bar }` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
)

options[:component].new(options[:locals]).render_in(self, &block)
elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil? && options.to_component_class < ActionView::Component::Base
ActiveSupport::Deprecation.warn(
"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."
)

options.to_component_class.new(options).render_in(self, &block)
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/rendering_monkey_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ViewComponent
module RenderingMonkeyPatch # :nodoc:
def render(options = {}, args = {})
if options.respond_to?(:render_in) && Rails.version.to_f < 6.1
if options.respond_to?(:render_in)
self.response_body = options.render_in(self.view_context)
else
super
Expand Down
Loading

0 comments on commit a1635d4

Please sign in to comment.