view_component 2.3.0 → 2.4.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.

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: 9dddd6d65c2dc550deac20d7bcaf84051f1c4b2f8c219ed8e402e8c058524c03
4
- data.tar.gz: 2fa94dc83ac665667f3559364c77a4682ee9f7fb71219ed3eb3cce2ba8ed6354
3
+ metadata.gz: ca0004a178e80b26bc7c47af5ef2dab32cdb4f3c61d09a1b27e593cf8ec4f5ea
4
+ data.tar.gz: 16427ce66ee5872627dafd670799fe19c42bfec499163dcbbe4e643a0e3b34fc
5
5
  SHA512:
6
- metadata.gz: ec78468d11cbf6c8011b39b6000156ce19e9caef4082dd68f0561422fb88d5cc5e11c2e8966c33a4ac0e50f0bc455934847519e4229d47756ce9fa4af2576c06
7
- data.tar.gz: bac3e1f5b3619c5c2f310e700862e6a2f0dfee69ec770079400ff5744c49c976741fdc5f6b019f0e0ab5858396dd236aa90cc94247c15ba0c73c5f423f80a1ff
6
+ metadata.gz: 7ea71f48ee58741b49df4818f0717328b715a1c11ebb0ecf0771c15aabb53fc3cdb51428c0b5f85781c04f113afca98fbe152083090f9f0b518f988cd60de3e9
7
+ data.tar.gz: 401537d259e436c9cb0ea7e3c4dc40af6c02f69013460583b4827795f9d615d79aa510aa9472840af05edea39d689d6cd785279a82c6e1b48ebb980654c03087
@@ -1,5 +1,25 @@
1
1
  # master
2
2
 
3
+ # v2.4.0
4
+
5
+ * Add `#render_to_string` support.
6
+
7
+ *Jarod Reid*
8
+
9
+ * Declare explicit dependency on `activesupport`.
10
+
11
+ *Richard Macklin*
12
+
13
+ * Remove `autoload`s of internal modules (`Previewable`, `RenderMonkeyPatch`, `RenderingMonkeyPatch`).
14
+
15
+ *Richard Macklin*
16
+
17
+ * Remove `capybara` dependency.
18
+
19
+ *Richard Macklin*
20
+
21
+ # v2.3.0
22
+
3
23
  * Allow using inline render method(s) defined on a parent.
4
24
 
5
25
  *Simon Rand*
data/README.md CHANGED
@@ -455,7 +455,7 @@ This will allow you to create files such as `app/components/widget_controller.js
455
455
 
456
456
  ### Testing
457
457
 
458
- Unit test components directly, using the `render_inline` test helper and Capybara matchers:
458
+ Unit test components directly, using the `render_inline` test helper. If you have a `capybara` test dependency, Capybara matchers will be available in your tests:
459
459
 
460
460
  ```ruby
461
461
  require "view_component/test_case"
@@ -469,6 +469,16 @@ class MyComponentTest < ViewComponent::TestCase
469
469
  end
470
470
  ```
471
471
 
472
+ In the absence of `capybara`, you can make assertions on the `render_inline` return value, which is an instance of `Nokogiri::HTML::DocumentFragment`:
473
+
474
+ ```ruby
475
+ test "render component" do
476
+ result = render_inline(TestComponent.new(title: "my title")) { "Hello, World!" }
477
+
478
+ assert_includes result.css("span[title='my title']").to_html, "Hello, World!"
479
+ end
480
+ ```
481
+
472
482
  #### Action Pack Variants
473
483
 
474
484
  Use the `with_variant` helper to test specific variants:
@@ -591,6 +601,7 @@ Inline templates have been removed (for now) due to concerns raised by [@soutaro
591
601
 
592
602
  ## Resources
593
603
 
604
+ - [ViewComponent at GitHub with Joel Hawksley](https://the-ruby-blend.fireside.fm/9)
594
605
  - [Components, HAML vs ERB, and Design Systems](https://the-ruby-blend.fireside.fm/4)
595
606
  - [Choosing the Right Tech Stack with Dave Paola](https://5by5.tv/rubyonrails/307)
596
607
  - [Rethinking the View Layer with Components, RailsConf 2019](https://www.youtube.com/watch?v=y5Z5a6QdA-M)
@@ -637,10 +648,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github
637
648
  |@blakewilliams|@seanpdoyle|@tclem|@nashby|@jaredcwhite|
638
649
  |Boston, MA|New York, NY|San Francisco, CA|Minsk|Portland, OR|
639
650
 
640
- |<img src="https://avatars.githubusercontent.com/simonrand?s=256" alt="simonrand" width="128" />|
641
- |:---:|
642
- |@simonrand|
643
- |Dublin, Ireland|
651
+ |<img src="https://avatars.githubusercontent.com/simonrand?s=256" alt="simonrand" width="128" />|<img src="https://avatars.githubusercontent.com/fugufish?s=256" alt="fugufish" width="128" />|
652
+ |:---:|:---:|
653
+ |@simonrand|@fugufish|
654
+ |Dublin, Ireland|Salt Lake City, Utah|
644
655
 
645
656
  ## License
646
657
 
@@ -7,10 +7,7 @@ module ViewComponent
7
7
 
8
8
  autoload :Base
9
9
  autoload :Preview
10
- autoload :Previewable
11
10
  autoload :TestHelpers
12
11
  autoload :TestCase
13
- autoload :RenderMonkeyPatch
14
- autoload :RenderingMonkeyPatch
15
12
  autoload :TemplateError
16
13
  end
@@ -43,11 +43,19 @@ module ViewComponent
43
43
 
44
44
  initializer "view_component.monkey_patch_render" do
45
45
  ActiveSupport.on_load(:action_view) do
46
- ActionView::Base.prepend ViewComponent::RenderMonkeyPatch if Rails.version.to_f < 6.1
46
+ if Rails.version.to_f < 6.1
47
+ require "view_component/render_monkey_patch"
48
+ ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
49
+ end
47
50
  end
48
51
 
49
52
  ActiveSupport.on_load(:action_controller) do
50
- ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch if Rails.version.to_f < 6.1
53
+ if Rails.version.to_f < 6.1
54
+ require "view_component/rendering_monkey_patch"
55
+ require "view_component/render_to_string_monkey_patch"
56
+ ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch
57
+ ActionController::Base.prepend ViewComponent::RenderToStringMonkeyPatch
58
+ end
51
59
  end
52
60
  end
53
61
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module RenderToStringMonkeyPatch # :nodoc:
5
+ def render_to_string(options = {}, args = {})
6
+ if options.respond_to?(:render_in)
7
+ options.render_in(self.view_context)
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "capybara/minitest"
4
-
5
3
  module ViewComponent
6
4
  module TestHelpers
7
- include Capybara::Minitest::Assertions
8
-
9
- def page
10
- Capybara::Node::Simple.new(@raw)
11
- end
12
-
13
- def refute_component_rendered
14
- assert_no_selector("body")
5
+ begin
6
+ require "capybara/minitest"
7
+ include Capybara::Minitest::Assertions
8
+
9
+ def page
10
+ Capybara::Node::Simple.new(@raw)
11
+ end
12
+
13
+ def refute_component_rendered
14
+ assert_no_selector("body")
15
+ end
16
+ rescue LoadError
17
+ warn "WARNING in `ViewComponent::TestHelpers`: You must add `capybara` to your Gemfile to use Capybara assertions."
15
18
  end
16
19
 
17
20
  def render_inline(component, **args, &block)
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 3
6
+ MINOR = 4
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: capybara
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '3'
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '3'
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +177,7 @@ files:
171
177
  - lib/view_component/preview.rb
172
178
  - lib/view_component/previewable.rb
173
179
  - lib/view_component/render_monkey_patch.rb
180
+ - lib/view_component/render_to_string_monkey_patch.rb
174
181
  - lib/view_component/rendering_monkey_patch.rb
175
182
  - lib/view_component/template_error.rb
176
183
  - lib/view_component/test_case.rb