actionview-component 1.7.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE +5 -8
  3. data/.github/PULL_REQUEST_TEMPLATE +2 -4
  4. data/.github/workflows/ruby_on_rails.yml +6 -2
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +4 -0
  7. data/CHANGELOG.md +150 -0
  8. data/CONTRIBUTING.md +10 -19
  9. data/Gemfile.lock +20 -5
  10. data/README.md +204 -248
  11. data/actionview-component.gemspec +10 -8
  12. data/{lib/railties/lib → app/controllers}/rails/components_controller.rb +18 -8
  13. data/docs/case-studies/jellyswitch.md +76 -0
  14. data/lib/action_view/component.rb +1 -20
  15. data/lib/action_view/component/base.rb +2 -246
  16. data/lib/action_view/component/preview.rb +1 -80
  17. data/lib/action_view/component/railtie.rb +1 -64
  18. data/lib/action_view/component/test_case.rb +1 -3
  19. data/lib/action_view/component/test_helpers.rb +1 -19
  20. data/lib/rails/generators/component/component_generator.rb +6 -12
  21. data/lib/rails/generators/component/templates/component.rb.tt +0 -4
  22. data/lib/rails/generators/erb/component_generator.rb +21 -0
  23. data/lib/rails/generators/erb/templates/component.html.erb.tt +1 -0
  24. data/lib/rails/generators/haml/component_generator.rb +21 -0
  25. data/lib/rails/generators/haml/templates/component.html.haml.tt +1 -0
  26. data/lib/rails/generators/rspec/component_generator.rb +1 -1
  27. data/lib/rails/generators/rspec/templates/component_spec.rb.tt +1 -1
  28. data/lib/rails/generators/slim/component_generator.rb +21 -0
  29. data/lib/rails/generators/slim/templates/component.html.slim.tt +1 -0
  30. data/lib/rails/generators/test_unit/component_generator.rb +1 -1
  31. data/lib/rails/generators/test_unit/templates/component_test.rb.tt +3 -3
  32. data/lib/railties/lib/rails.rb +0 -1
  33. data/lib/railties/lib/rails/templates/rails/components/preview.html.erb +1 -1
  34. data/lib/view_component.rb +30 -0
  35. data/lib/view_component/base.rb +279 -0
  36. data/lib/view_component/conversion.rb +9 -0
  37. data/lib/view_component/engine.rb +65 -0
  38. data/lib/view_component/preview.rb +78 -0
  39. data/lib/view_component/previewable.rb +25 -0
  40. data/lib/view_component/render_monkey_patch.rb +31 -0
  41. data/lib/view_component/rendering_monkey_patch.rb +13 -0
  42. data/lib/view_component/template_error.rb +9 -0
  43. data/lib/view_component/test_case.rb +9 -0
  44. data/lib/view_component/test_helpers.rb +39 -0
  45. data/lib/view_component/version.rb +11 -0
  46. data/script/console +1 -1
  47. metadata +48 -21
  48. data/lib/action_view/component/conversion.rb +0 -11
  49. data/lib/action_view/component/previewable.rb +0 -27
  50. data/lib/action_view/component/render_monkey_patch.rb +0 -29
  51. data/lib/action_view/component/template_error.rb +0 -11
  52. data/lib/action_view/component/version.rb +0 -13
  53. data/lib/rails/generators/component/templates/component.html.erb.tt +0 -5
  54. data/lib/railties/lib/rails/component_examples_controller.rb +0 -9
  55. data/lib/railties/lib/rails/templates/rails/examples/show.html.erb +0 -1
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component # :nodoc:
5
- module Conversion
6
- def to_component_class
7
- "#{self.class.name}Component".safe_constantize
8
- end
9
- end
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/concern"
4
-
5
- module ActionView
6
- module Component # :nodoc:
7
- module Previewable
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
- # Set the location of component previews through app configuration:
12
- #
13
- # config.action_view_component.preview_path = "#{Rails.root}/lib/component_previews"
14
- #
15
- mattr_accessor :preview_path, instance_writer: false
16
-
17
- # Enable or disable component previews through app configuration:
18
- #
19
- # config.action_view_component.show_previews = true
20
- #
21
- # Defaults to +true+ for development environment
22
- #
23
- mattr_accessor :show_previews, instance_writer: false
24
- end
25
- end
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Monkey patch ActionView::Base#render to support ActionView::Component
4
- #
5
- # A version of this monkey patch was upstreamed in https://github.com/rails/rails/pull/36388
6
- # We'll need to upstream an updated version of this eventually.
7
- module ActionView
8
- module Component
9
- module RenderMonkeyPatch # :nodoc:
10
- def render(options = {}, args = {}, &block)
11
- if options.respond_to?(:render_in)
12
- ActiveSupport::Deprecation.warn(
13
- "passing component instances (`render MyComponent.new(foo: :bar)`) has been deprecated and will be removed in v2.0.0. Use `render MyComponent, foo: :bar` instead."
14
- )
15
-
16
- options.render_in(self, &block)
17
- elsif options.is_a?(Class) && options < ActionView::Component::Base
18
- options.new(args).render_in(self, &block)
19
- elsif options.is_a?(Hash) && options.has_key?(:component)
20
- options[:component].new(options[:locals]).render_in(self, &block)
21
- elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil?
22
- options.to_component_class.new(options).render_in(self, &block)
23
- else
24
- super
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component
5
- class TemplateError < StandardError
6
- def initialize(errors)
7
- super(errors.join(", "))
8
- end
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionView
4
- module Component
5
- module VERSION
6
- MAJOR = 1
7
- MINOR = 7
8
- PATCH = 0
9
-
10
- STRING = [MAJOR, MINOR, PATCH].join(".")
11
- end
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- <%- if requires_content? -%>
2
- <%= "<%= content %%>" %>
3
- <%- else -%>
4
- <div>Add <%= class_name %> template here</div>
5
- <%- end -%>
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/application_controller"
4
- load "config/application.rb" unless Rails.root
5
-
6
- class Rails::ComponentExamplesController < ActionController::Base # :nodoc:
7
- prepend_view_path File.expand_path("templates/rails", __dir__)
8
- append_view_path Rails.root.join("app/views")
9
- end