actionview-component 1.5.3 → 1.8.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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE +25 -0
  3. data/.github/PULL_REQUEST_TEMPLATE +17 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +4 -0
  6. data/CHANGELOG.md +106 -0
  7. data/CONTRIBUTING.md +4 -13
  8. data/Gemfile.lock +13 -2
  9. data/README.md +282 -9
  10. data/actionview-component.gemspec +1 -0
  11. data/lib/action_view/component.rb +20 -2
  12. data/lib/action_view/component/base.rb +95 -39
  13. data/lib/action_view/component/conversion.rb +11 -0
  14. data/lib/action_view/component/preview.rb +8 -35
  15. data/lib/action_view/component/previewable.rb +27 -0
  16. data/lib/action_view/component/railtie.rb +15 -1
  17. data/lib/action_view/component/render_monkey_patch.rb +29 -0
  18. data/lib/action_view/component/template_error.rb +11 -0
  19. data/lib/action_view/component/test_case.rb +11 -0
  20. data/lib/action_view/component/test_helpers.rb +2 -2
  21. data/lib/action_view/component/version.rb +2 -2
  22. data/lib/rails/generators/component/component_generator.rb +2 -2
  23. data/lib/rails/generators/rspec/component_generator.rb +1 -1
  24. data/lib/rails/generators/test_unit/component_generator.rb +1 -1
  25. data/lib/rails/generators/test_unit/templates/component_test.rb.tt +2 -4
  26. data/lib/railties/lib/rails.rb +0 -1
  27. data/lib/railties/lib/rails/components_controller.rb +5 -1
  28. data/lib/railties/lib/rails/templates/rails/components/preview.html.erb +1 -1
  29. metadata +23 -5
  30. data/lib/action_view/component/monkey_patch.rb +0 -27
  31. data/lib/railties/lib/rails/component_examples_controller.rb +0 -9
  32. data/lib/railties/lib/rails/templates/rails/examples/show.html.erb +0 -1
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/test_case"
4
+
5
+ module ActionView
6
+ module Component
7
+ class TestCase < ActiveSupport::TestCase
8
+ include ActionView::Component::TestHelpers
9
+ end
10
+ end
11
+ end
@@ -4,11 +4,11 @@ module ActionView
4
4
  module Component
5
5
  module TestHelpers
6
6
  def render_inline(component, **args, &block)
7
- Nokogiri::HTML(controller.view_context.render(component, args, &block)).css("body > *")
7
+ Nokogiri::HTML.fragment(controller.view_context.render(component, args, &block))
8
8
  end
9
9
 
10
10
  def controller
11
- @controller ||= ApplicationController.new.tap { |c| c.request = request }
11
+ @controller ||= Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
12
12
  end
13
13
 
14
14
  def request
@@ -4,8 +4,8 @@ module ActionView
4
4
  module Component
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 5
8
- PATCH = 3
7
+ MINOR = 8
8
+ PATCH = 0
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -10,11 +10,11 @@ module Rails
10
10
  check_class_collision suffix: "Component"
11
11
 
12
12
  def create_component_file
13
- template "component.rb", File.join("app/components", "#{file_name}_component.rb")
13
+ template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb")
14
14
  end
15
15
 
16
16
  def create_template_file
17
- template "component.html.erb", File.join("app/components", "#{file_name}_component.html.erb")
17
+ template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
18
18
  end
19
19
 
20
20
  private
@@ -6,7 +6,7 @@ module Rspec
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
8
  def create_test_file
9
- template "component_spec.rb", File.join("spec/components", "#{file_name}_component_spec.rb")
9
+ template "component_spec.rb", File.join("spec/components", class_path, "#{file_name}_component_spec.rb")
10
10
  end
11
11
 
12
12
  private
@@ -7,7 +7,7 @@ module TestUnit
7
7
  check_class_collision suffix: "ComponentTest"
8
8
 
9
9
  def create_test_file
10
- template "component_test.rb", File.join("test/components", "#{file_name}_component_test.rb")
10
+ template "component_test.rb", File.join("test/components", class_path, "#{file_name}_component_test.rb")
11
11
  end
12
12
 
13
13
  private
@@ -1,12 +1,10 @@
1
1
  require "test_helper"
2
2
 
3
- class <%= class_name %>ComponentTest < ActiveSupport::TestCase
4
- include ActionView::Component::TestHelpers
5
-
3
+ class <%= class_name %>ComponentTest < ActionView::Component::TestCase
6
4
  test "component renders something useful" do
7
5
  # assert_equal(
8
6
  # %(<span title="my title">Hello, components!</span>),
9
- # render_inline(<%= class_name %>, attr: "value") { "Hello, components!" }.css("span").to_html
7
+ # render_inline(<%= class_name %>Component, attr: "value") { "Hello, components!" }.css("span").to_html
10
8
  # )
11
9
  end
12
10
  end
@@ -2,5 +2,4 @@
2
2
 
3
3
  module Rails
4
4
  autoload :ComponentsController
5
- autoload :ComponentExamplesController
6
5
  end
@@ -4,6 +4,7 @@ require "rails/application_controller"
4
4
 
5
5
  class Rails::ComponentsController < Rails::ApplicationController # :nodoc:
6
6
  prepend_view_path File.expand_path("templates/rails", __dir__)
7
+ prepend_view_path "#{Rails.root}/app/views/" if defined?(Rails.root)
7
8
 
8
9
  around_action :set_locale, only: :previews
9
10
  before_action :find_preview, only: :previews
@@ -25,7 +26,10 @@ class Rails::ComponentsController < Rails::ApplicationController # :nodoc:
25
26
  render template: "components/previews"
26
27
  else
27
28
  @example_name = File.basename(params[:path])
28
- render template: "components/preview", layout: false
29
+ @render_args = @preview.render_args(@example_name)
30
+ layout = @render_args[:layout]
31
+ opts = layout.nil? ? {} : { layout: layout }
32
+ render template: "components/preview", **opts
29
33
  end
30
34
  end
31
35
 
@@ -1 +1 @@
1
- <%= raw @preview.call(@example_name) %>
1
+ <%= render(@render_args[:component], **@render_args[:args], &@render_args[:block])%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: better_html
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +129,8 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - ".github/ISSUE_TEMPLATE"
133
+ - ".github/PULL_REQUEST_TEMPLATE"
118
134
  - ".github/workflows/ruby_on_rails.yml"
119
135
  - ".gitignore"
120
136
  - ".rubocop.yml"
@@ -129,9 +145,13 @@ files:
129
145
  - actionview-component.gemspec
130
146
  - lib/action_view/component.rb
131
147
  - lib/action_view/component/base.rb
132
- - lib/action_view/component/monkey_patch.rb
148
+ - lib/action_view/component/conversion.rb
133
149
  - lib/action_view/component/preview.rb
150
+ - lib/action_view/component/previewable.rb
134
151
  - lib/action_view/component/railtie.rb
152
+ - lib/action_view/component/render_monkey_patch.rb
153
+ - lib/action_view/component/template_error.rb
154
+ - lib/action_view/component/test_case.rb
135
155
  - lib/action_view/component/test_helpers.rb
136
156
  - lib/action_view/component/version.rb
137
157
  - lib/rails/generators/component/USAGE
@@ -143,12 +163,10 @@ files:
143
163
  - lib/rails/generators/test_unit/component_generator.rb
144
164
  - lib/rails/generators/test_unit/templates/component_test.rb.tt
145
165
  - lib/railties/lib/rails.rb
146
- - lib/railties/lib/rails/component_examples_controller.rb
147
166
  - lib/railties/lib/rails/components_controller.rb
148
167
  - lib/railties/lib/rails/templates/rails/components/index.html.erb
149
168
  - lib/railties/lib/rails/templates/rails/components/preview.html.erb
150
169
  - lib/railties/lib/rails/templates/rails/components/previews.html.erb
151
- - lib/railties/lib/rails/templates/rails/examples/show.html.erb
152
170
  - script/bootstrap
153
171
  - script/console
154
172
  - script/install
@@ -1,27 +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
- class ActionView::Base
8
- module RenderMonkeyPatch
9
- def render(options = {}, args = {}, &block)
10
- if options.respond_to?(:render_in)
11
- ActiveSupport::Deprecation.warn(
12
- "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."
13
- )
14
-
15
- options.render_in(self, &block)
16
- elsif options.is_a?(Class) && options < ActionView::Component::Base
17
- options.new(args).render_in(self, &block)
18
- elsif options.is_a?(Hash) && options.has_key?(:component)
19
- options[:component].new(options[:locals]).render_in(self, &block)
20
- else
21
- super
22
- end
23
- end
24
- end
25
-
26
- prepend RenderMonkeyPatch
27
- 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