view_component 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +16 -5
- data/lib/view_component.rb +0 -3
- data/lib/view_component/engine.rb +10 -2
- data/lib/view_component/render_to_string_monkey_patch.rb +13 -0
- data/lib/view_component/test_helpers.rb +13 -10
- data/lib/view_component/version.rb +1 -1
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0004a178e80b26bc7c47af5ef2dab32cdb4f3c61d09a1b27e593cf8ec4f5ea
|
4
|
+
data.tar.gz: 16427ce66ee5872627dafd670799fe19c42bfec499163dcbbe4e643a0e3b34fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ea71f48ee58741b49df4818f0717328b715a1c11ebb0ecf0771c15aabb53fc3cdb51428c0b5f85781c04f113afca98fbe152083090f9f0b518f988cd60de3e9
|
7
|
+
data.tar.gz: 401537d259e436c9cb0ea7e3c4dc40af6c02f69013460583b4827795f9d615d79aa510aa9472840af05edea39d689d6cd785279a82c6e1b48ebb980654c03087
|
data/CHANGELOG.md
CHANGED
@@ -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
|
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
|
|
data/lib/view_component.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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)
|
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.
|
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-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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: '
|
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: '
|
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
|