actionview-component 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c20b9ae371123eb58c62aa3c093baafdf7d5745bf8311ff2fb975c70282e6dfd
4
- data.tar.gz: caaad9f6e645602efe2faea055ff08dd1f548efe08b503a3048d83eebc824997
3
+ metadata.gz: 2d2c0dab4ae3674f45f3f830257f49b108f51923e98a3de1182667f71a951cb2
4
+ data.tar.gz: 220a51f5dee367a6bf22e3a5306d17a2e302c5326cf4ad4a5f271c2ff0edb864
5
5
  SHA512:
6
- metadata.gz: 52aec02cba11b482df4c4e4f160ad7602dadca664eb75a4fad579fb5802c9f4efb6a7e07f1082ab634e99c9ed8efad82861daf1fdc9c5108cdf63e3f2b0f80d1
7
- data.tar.gz: 4d5fb555f12740dfa62a64b4c9b095879e4ea182a3930f9a725482525c6d5bbeae08d9914dff847e8521a7107f31b13b919f5b9d5cc69d83cbaf53c08422503c
6
+ metadata.gz: f9c79d7c62166ef2fb8f1cba5220d1599c8d6129252e09aec47917de3a7db1c3d9d6ef70da8231dc3389eac9e0136b2b533a972867a12ad975f8f5db9f49d5cc
7
+ data.tar.gz: efc71bebe0aeba60aeefdc00ae50d7485e2a28334c7b4764d359e84402e740f8aa0b66a36035be5223a2114c1e432c50c071d0924c2a3f90d8658f5e76a330d5
@@ -1,7 +1,19 @@
1
+ # v1.11.0
2
+
3
+ * Add support for Capybara matchers.
4
+
5
+ *Joel Hawksley*
6
+
7
+ * Add erb, haml, & slim template generators
8
+
9
+ *Asger Behncke Jacobsen*
10
+
1
11
  # v1.10.0
2
12
 
3
13
  * Deprecate all `render` syntaxes except for `render(MyComponent.new(foo: :bar))`
4
14
 
15
+ *Joel Hawksley*
16
+
5
17
  # v1.9.0
6
18
 
7
19
  * Remove initializer requirement for Ruby 2.7+
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.10.0)
4
+ actionview-component (1.11.0)
5
+ capybara (>= 3.26)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -61,6 +62,8 @@ GEM
61
62
  minitest (~> 5.1)
62
63
  tzinfo (~> 1.1)
63
64
  zeitwerk (~> 2.1, >= 2.1.8)
65
+ addressable (2.7.0)
66
+ public_suffix (>= 2.0.2, < 5.0)
64
67
  ast (2.4.0)
65
68
  better_html (1.0.14)
66
69
  actionview (>= 4.0)
@@ -71,6 +74,14 @@ GEM
71
74
  parser (>= 2.4)
72
75
  smart_properties
73
76
  builder (3.2.3)
77
+ capybara (3.31.0)
78
+ addressable
79
+ mini_mime (>= 0.1.3)
80
+ nokogiri (~> 1.8)
81
+ rack (>= 1.6.0)
82
+ rack-test (>= 0.6.3)
83
+ regexp_parser (~> 1.5)
84
+ xpath (~> 3.2)
74
85
  concurrent-ruby (1.1.5)
75
86
  crass (1.0.5)
76
87
  erubi (1.8.0)
@@ -101,6 +112,7 @@ GEM
101
112
  parallel (1.17.0)
102
113
  parser (2.6.3.0)
103
114
  ast (~> 2.4.0)
115
+ public_suffix (4.0.3)
104
116
  rack (2.0.8)
105
117
  rack-test (1.1.0)
106
118
  rack (>= 1.0, < 3)
@@ -132,6 +144,7 @@ GEM
132
144
  thor (>= 0.20.3, < 2.0)
133
145
  rainbow (3.0.0)
134
146
  rake (10.5.0)
147
+ regexp_parser (1.6.0)
135
148
  rubocop (0.74.0)
136
149
  jaro_winkler (~> 1.5.1)
137
150
  parallel (~> 1.10)
@@ -166,6 +179,8 @@ GEM
166
179
  websocket-driver (0.7.1)
167
180
  websocket-extensions (>= 0.1.0)
168
181
  websocket-extensions (0.1.4)
182
+ xpath (3.2.0)
183
+ nokogiri (~> 1.8)
169
184
  zeitwerk (2.1.10)
170
185
 
171
186
  PLATFORMS
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ _Note: This gem is in the process of a name / API change, see https://github.com/github/actionview-component/issues/206_
2
+
1
3
  # ActionView::Component
2
4
  `ActionView::Component` is a framework for building view components in Rails.
3
5
 
@@ -15,7 +17,7 @@ As the goal of this gem is to be upstreamed into Rails, it is designed to integr
15
17
 
16
18
  ## Compatibility
17
19
 
18
- `actionview-component` is tested for compatibility with combinations of Ruby `2.5`/`2.6` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`6.1.0.alpha`.
20
+ `actionview-component` is tested for compatibility with combinations of Ruby `2.5`/`2.6`/`2.7` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`6.1.0.alpha`.
19
21
 
20
22
  ## Installation
21
23
  Add this line to your application's Gemfile:
@@ -117,6 +119,18 @@ bin/rails generate component Example title content
117
119
  create app/components/example_component.html.erb
118
120
  ```
119
121
 
122
+ `ActionView::Component` includes template generators for the `erb`, `haml`, and `slim` template engines and will use the template engine specified in your Rails config (`config.generators.template_engine`) by default.
123
+
124
+ If you want to override this behavior, you can pass the template engine as an option to the generator:
125
+
126
+ ```bash
127
+ bin/rails generate component Example title content --template-engine slim
128
+ invoke test_unit
129
+ create test/components/example_component_test.rb
130
+ create app/components/example_component.rb
131
+ create app/components/example_component.html.slim
132
+ ```
133
+
120
134
  #### Implementation
121
135
 
122
136
  An `ActionView::Component` is a Ruby file and corresponding template file (in any format supported by Rails) with the same base name:
@@ -389,17 +403,16 @@ end
389
403
 
390
404
  ### Testing
391
405
 
392
- Components are unit tested directly. The `render_inline` test helper wraps the result in `Nokogiri.HTML`, allowing us to test the component above as:
406
+ Components are unit tested directly. The `render_inline` test helper is compatible with Capybara matchers, allowing us to test the component above as:
393
407
 
394
408
  ```ruby
395
409
  require "action_view/component/test_case"
396
410
 
397
411
  class MyComponentTest < ActionView::Component::TestCase
398
412
  test "render component" do
399
- assert_equal(
400
- %(<span title="my title">Hello, World!</span>),
401
- render_inline(TestComponent.new(title: "my title")) { "Hello, World!" }.to_html
402
- )
413
+ render_inline(TestComponent.new(title: "my title")) { "Hello, World!" }
414
+
415
+ assert_selector("span[title='my title']", "Hello, World!")
403
416
  end
404
417
  end
405
418
  ```
@@ -413,10 +426,9 @@ To test a specific variant you can wrap your test with the `with_variant` helper
413
426
  ```ruby
414
427
  test "render component for tablet" do
415
428
  with_variant :tablet do
416
- assert_equal(
417
- %(<span title="my title">Hello, tablets!</span>),
418
- render_inline(TestComponent.new(title: "my title")) { "Hello, tablets!" }.css("span").to_html
419
- )
429
+ render_inline(TestComponent.new(title: "my title")) { "Hello, tablets!" }
430
+
431
+ assert_selector("span[title='my title']", "Hello, tablets!")
420
432
  end
421
433
  end
422
434
  ```
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.required_ruby_version = ">= 2.3.0"
36
36
 
37
+ spec.add_runtime_dependency "capybara", ">= 3.26"
37
38
  spec.add_development_dependency "bundler", ">= 1.14"
38
39
  spec.add_development_dependency "rake", "~> 10.0"
39
40
  spec.add_development_dependency "minitest", "= 5.1.0"
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "capybara/minitest"
4
+
3
5
  module ActionView
4
6
  module Component
5
7
  module TestHelpers
8
+ include Capybara::Minitest::Assertions
9
+
10
+ def page
11
+ Capybara::Node::Simple.new(@raw)
12
+ end
13
+
6
14
  def render_inline(component, **args, &block)
7
- Nokogiri::HTML.fragment(controller.view_context.render(component, args, &block))
15
+ @raw = controller.view_context.render(component, args, &block)
16
+
17
+ Nokogiri::HTML.fragment(@raw)
8
18
  end
9
19
 
10
20
  def controller
@@ -4,7 +4,7 @@ module ActionView
4
4
  module Component
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 10
7
+ MINOR = 11
8
8
  PATCH = 0
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
@@ -6,15 +6,18 @@ module Rails
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
8
  argument :attributes, type: :array, default: [], banner: "attribute"
9
- hook_for :test_framework
10
9
  check_class_collision suffix: "Component"
11
10
 
11
+ class_option :require_content, type: :boolean, default: false
12
+
12
13
  def create_component_file
13
14
  template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb")
14
15
  end
15
16
 
16
- def create_template_file
17
- template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
17
+ hook_for :test_framework
18
+
19
+ hook_for :template_engine do |instance, template_engine|
20
+ instance.invoke template_engine, [instance.name], require_content: instance.send(:requires_content?)
18
21
  end
19
22
 
20
23
  private
@@ -24,6 +27,7 @@ module Rails
24
27
  end
25
28
 
26
29
  def requires_content?
30
+ return if behavior == :revoke
27
31
  return @requires_content if @asked
28
32
 
29
33
  @asked = true
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb"
4
+
5
+ module Erb
6
+ module Generators
7
+ class ComponentGenerator < Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb/component_generator"
4
+
5
+ module Haml
6
+ module Generators
7
+ class ComponentGenerator < Erb::Generators::ComponentGenerator
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.haml", File.join("app/components", class_path, "#{file_name}_component.html.haml")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ <%- if requires_content? -%>
2
+ <%= "= content" %>
3
+ <%- else -%>
4
+ %div Add <%= class_name %> template here
5
+ <%- end -%>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb/component_generator"
4
+
5
+ module Slim
6
+ module Generators
7
+ class ComponentGenerator < Erb::Generators::ComponentGenerator
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.slim", File.join("app/components", class_path, "#{file_name}_component.html.slim")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ <%- if requires_content? -%>
2
+ = content
3
+ <%- else -%>
4
+ div Add <%= class_name %> template here
5
+ <%- end -%>
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.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: 2020-02-14 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.26'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.26'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -156,10 +170,15 @@ files:
156
170
  - lib/action_view/component/version.rb
157
171
  - lib/rails/generators/component/USAGE
158
172
  - lib/rails/generators/component/component_generator.rb
159
- - lib/rails/generators/component/templates/component.html.erb.tt
160
173
  - lib/rails/generators/component/templates/component.rb.tt
174
+ - lib/rails/generators/erb/component_generator.rb
175
+ - lib/rails/generators/erb/templates/component.html.erb.tt
176
+ - lib/rails/generators/haml/component_generator.rb
177
+ - lib/rails/generators/haml/templates/component.html.haml.tt
161
178
  - lib/rails/generators/rspec/component_generator.rb
162
179
  - lib/rails/generators/rspec/templates/component_spec.rb.tt
180
+ - lib/rails/generators/slim/component_generator.rb
181
+ - lib/rails/generators/slim/templates/component.html.slim
163
182
  - lib/rails/generators/test_unit/component_generator.rb
164
183
  - lib/rails/generators/test_unit/templates/component_test.rb.tt
165
184
  - lib/railties/lib/rails.rb