view_component 4.1.0 → 4.2.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.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +70 -110
- data/lib/view_component/base.rb +25 -11
- data/lib/view_component/collection.rb +1 -1
- data/lib/view_component/compiler.rb +2 -0
- data/lib/view_component/config.rb +1 -1
- data/lib/view_component/configurable.rb +18 -2
- data/lib/view_component/slot.rb +3 -3
- data/lib/view_component/slotable.rb +9 -2
- data/lib/view_component/template.rb +20 -2
- data/lib/view_component/test_helpers.rb +1 -1
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +2 -1
- metadata +14 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79d1337f1589a6e9ec7617c7d07917825c4f90b2e6093e6e925ef9fad3e06937
|
|
4
|
+
data.tar.gz: aaa0ddcd3a30c628409a4001efdd99c702ff5b97ff7873a3f3e092e05b54c3f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98381938a50a979a6ee135dff98c4e3b13a4a1b5ac8ee2f19c7e5f9b1bdc04470b355c55696d2724c733fab29a9379fe59c0a8e4273374e9db5210202be2dc06
|
|
7
|
+
data.tar.gz: 0b5276ff41b7b7ff493f935c75e8c3e8cc604decc42a950c97f1da3becccfba3446b40178c35b9b54578a47f3718bfa53ba2c6e91ec7b929a6adc7f26f41f782
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,15 +10,83 @@ nav_order: 6
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 4.2.0
|
|
14
|
+
|
|
15
|
+
* Fix translation scope resolution in deeply nested component blocks (3+ levels). Translations called inside deeply nested slot blocks using `renders_many`/`renders_one` were incorrectly resolving to an intermediate component's scope instead of the partial's scope where the block was defined. The fix captures the virtual path at block definition time and restores it during block execution, ensuring translations always resolve relative to where the block was created regardless of nesting depth.
|
|
16
|
+
|
|
17
|
+
*Nathaniel Watts*
|
|
18
|
+
|
|
19
|
+
* Allow `render_inline` with Nokogiri::HTML5 to parse more arbitrary content including bare table content otherwise illegal fragments like `<td>`.
|
|
20
|
+
|
|
21
|
+
*Jonathan Rochkind*
|
|
22
|
+
|
|
23
|
+
* Remove known issue from docs as ActiveScaffold is [now compatible](https://github.com/activescaffold/active_scaffold/pull/743) with ViewComponent.
|
|
24
|
+
|
|
25
|
+
*David Löwenfels*
|
|
26
|
+
|
|
27
|
+
* Add test to document the current behavior for resolving relative translation keys within partial blocks. When rendering a partial, relative translation keys are resolved relative to the partial's own path rather than the caller’s path. This test ensures that this behavior remains consistent.
|
|
28
|
+
|
|
29
|
+
*Oussama Hilal*
|
|
30
|
+
|
|
31
|
+
* Allow I18n calls in `render?`.
|
|
32
|
+
|
|
33
|
+
*23tux*
|
|
34
|
+
|
|
35
|
+
* ViewComponent now works without `rails` and `railties` gems loaded, enabling compatibility with Bridgetown 2.0.
|
|
36
|
+
|
|
37
|
+
*Tom Lord*
|
|
38
|
+
|
|
39
|
+
* Capture partial block in the component's context, allowing access to the component instance inside the block.
|
|
40
|
+
|
|
41
|
+
*23tux*
|
|
42
|
+
|
|
43
|
+
* Add `after_compile` class method hook to enable extensions to run logic after component compilation.
|
|
44
|
+
|
|
45
|
+
*Jose Solás*
|
|
46
|
+
|
|
47
|
+
* Fix outdated reference to preview layout configuration in docs.
|
|
48
|
+
|
|
49
|
+
*Lucas Geron*
|
|
50
|
+
|
|
51
|
+
* Allow ruby-head CI job to fail without failing workflow.
|
|
52
|
+
|
|
53
|
+
*Hakan Ensari*
|
|
54
|
+
|
|
55
|
+
* Fix bug where error line numbers were incorrect in Rails 8.1.
|
|
56
|
+
|
|
57
|
+
*Joel Hawksley*
|
|
58
|
+
|
|
59
|
+
* Remove `< 8.2` upper bound for `activesupport` and `actionview` dependencies.
|
|
60
|
+
|
|
61
|
+
*Hans Lemuet*
|
|
62
|
+
|
|
63
|
+
* Test compatibility with Herb/ReActionView.
|
|
64
|
+
|
|
65
|
+
*Joel Hawksley*
|
|
66
|
+
|
|
67
|
+
* Remove Who Uses ViewComponent section from docs.
|
|
68
|
+
|
|
69
|
+
*Joel Hawksley*
|
|
70
|
+
|
|
71
|
+
## 4.1.1
|
|
72
|
+
|
|
73
|
+
* Resolve deprecation warning for `ActiveSupport::Configurable`.
|
|
74
|
+
|
|
75
|
+
*Simon Fish*
|
|
76
|
+
|
|
77
|
+
* Make `ViewComponent::VERSION` accessible to other gems by default.
|
|
78
|
+
|
|
79
|
+
*Hans Lemuet*
|
|
80
|
+
|
|
13
81
|
## 4.1.0
|
|
14
82
|
|
|
15
83
|
* Add Rails 8.1 support.
|
|
16
84
|
|
|
17
85
|
*Hans Lemuet*
|
|
18
86
|
|
|
19
|
-
*
|
|
87
|
+
* Declare `actionview` as a `view_component` gem dependency.
|
|
20
88
|
|
|
21
|
-
*
|
|
89
|
+
*Michal Cichra*
|
|
22
90
|
|
|
23
91
|
## 4.0.2
|
|
24
92
|
|
|
@@ -498,10 +566,6 @@ This release makes the following breaking changes:
|
|
|
498
566
|
|
|
499
567
|
*Martin Meyerhoff*, *Joel Hawksley*
|
|
500
568
|
|
|
501
|
-
* Add Content Harmony & Learn To Be to list of companies using ViewComponent.
|
|
502
|
-
|
|
503
|
-
*Kane Jamison*
|
|
504
|
-
|
|
505
569
|
* Clarify error message about render-dependent logic.
|
|
506
570
|
|
|
507
571
|
Error messages about render-dependent logic were sometimes inaccurate, saying `during initialization` despite also being raised after a component had been initialized but before it was rendered.
|
|
@@ -520,10 +584,6 @@ This release makes the following breaking changes:
|
|
|
520
584
|
|
|
521
585
|
*Reegan Viljoen*
|
|
522
586
|
|
|
523
|
-
* Add HomeStyler AI to list of companies using ViewComponent.
|
|
524
|
-
|
|
525
|
-
*JP Balarini*
|
|
526
|
-
|
|
527
587
|
## 3.21.0
|
|
528
588
|
|
|
529
589
|
* Updates testing docs to include an example of how to use with RSpec.
|
|
@@ -534,10 +594,6 @@ This release makes the following breaking changes:
|
|
|
534
594
|
|
|
535
595
|
*KAWAKAMI Moeki*
|
|
536
596
|
|
|
537
|
-
* Add FreeATS to list of companies using ViewComponent.
|
|
538
|
-
|
|
539
|
-
*Ilia Liamshin*
|
|
540
|
-
|
|
541
597
|
* Ensure HTML output safety wrapper is used for all inline templates.
|
|
542
598
|
|
|
543
599
|
*Joel Hawksley*
|
|
@@ -588,10 +644,6 @@ This release makes the following breaking changes:
|
|
|
588
644
|
|
|
589
645
|
*Blake Williams*
|
|
590
646
|
|
|
591
|
-
* Add [Niva]([niva.co](https://www.niva.co/)) to companies who use `ViewComponent`.
|
|
592
|
-
|
|
593
|
-
*Daniel Vu Dao*
|
|
594
|
-
|
|
595
647
|
* Fix `preview_paths` in docs.
|
|
596
648
|
|
|
597
649
|
*Javier Aranda*
|
|
@@ -656,10 +708,6 @@ This release makes the following breaking changes:
|
|
|
656
708
|
|
|
657
709
|
*Joel Hawksley*
|
|
658
710
|
|
|
659
|
-
* Add Kicksite to list of companies using ViewComponent.
|
|
660
|
-
|
|
661
|
-
*Adil Lari*
|
|
662
|
-
|
|
663
711
|
* Allow overridden slot methods to use `super`.
|
|
664
712
|
|
|
665
713
|
*Andrew Schwartz*
|
|
@@ -899,10 +947,6 @@ This release makes the following breaking changes:
|
|
|
899
947
|
|
|
900
948
|
*Simon Fish*
|
|
901
949
|
|
|
902
|
-
* Add Simundia to list of companies using ViewComponent.
|
|
903
|
-
|
|
904
|
-
*Alexandre Ignjatovic*
|
|
905
|
-
|
|
906
950
|
* Reduce UnboundMethod objects by memoizing initialize_parameters.
|
|
907
951
|
|
|
908
952
|
*Rainer Borene*
|
|
@@ -953,10 +997,6 @@ This release makes the following breaking changes:
|
|
|
953
997
|
|
|
954
998
|
*milk1000cc*
|
|
955
999
|
|
|
956
|
-
* Add PeopleForce to list of companies using ViewComponent.
|
|
957
|
-
|
|
958
|
-
*Volodymyr Khandiuk*
|
|
959
|
-
|
|
960
1000
|
## 3.5.0
|
|
961
1001
|
|
|
962
1002
|
* Add Skroutz to users list.
|
|
@@ -1031,14 +1071,6 @@ This release makes the following breaking changes:
|
|
|
1031
1071
|
|
|
1032
1072
|
*Joel Hawksley*
|
|
1033
1073
|
|
|
1034
|
-
* Add Ophelos to list of companies using ViewComponent.
|
|
1035
|
-
|
|
1036
|
-
*Graham Rogers*
|
|
1037
|
-
|
|
1038
|
-
* Add FlightLogger to list of companies using ViewComponent.
|
|
1039
|
-
|
|
1040
|
-
*Joseph Carpenter*
|
|
1041
|
-
|
|
1042
1074
|
* Fix coverage reports overwriting each other when running locally.
|
|
1043
1075
|
|
|
1044
1076
|
*Jonathan del Strother*
|
|
@@ -1278,14 +1310,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1278
1310
|
|
|
1279
1311
|
*Graham Rogers*
|
|
1280
1312
|
|
|
1281
|
-
* Add Krystal to list of companies using ViewComponent.
|
|
1282
|
-
|
|
1283
|
-
*Matt Bearman*
|
|
1284
|
-
|
|
1285
|
-
* Add Mon Ami to list of companies using ViewComponent.
|
|
1286
|
-
|
|
1287
|
-
*Ethan Lee-Tyson*
|
|
1288
|
-
|
|
1289
1313
|
## 3.0.0.rc1
|
|
1290
1314
|
|
|
1291
1315
|
1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
|
|
@@ -1434,10 +1458,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1434
1458
|
|
|
1435
1459
|
*Hans Lemuet*
|
|
1436
1460
|
|
|
1437
|
-
* Add Startup Jobs to list of companies using ViewComponent.
|
|
1438
|
-
|
|
1439
|
-
*Marc Köhlbrugge*
|
|
1440
|
-
|
|
1441
1461
|
* Run PVC's accessibility tests in a single process to avoid resource contention in CI.
|
|
1442
1462
|
|
|
1443
1463
|
*Cameron Dutro*
|
|
@@ -1478,10 +1498,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1478
1498
|
|
|
1479
1499
|
## 2.74.0
|
|
1480
1500
|
|
|
1481
|
-
* Add Avo to list of companies using ViewComponent.
|
|
1482
|
-
|
|
1483
|
-
*Adrian Marin*
|
|
1484
|
-
|
|
1485
1501
|
* Promote experimental `_output_postamble` method to public API as `output_postamble`.
|
|
1486
1502
|
|
|
1487
1503
|
*Joel Hawksley*
|
|
@@ -1508,10 +1524,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1508
1524
|
|
|
1509
1525
|
*Erinna Chen*
|
|
1510
1526
|
|
|
1511
|
-
* Add PrintReleaf to list of companies using ViewComponent.
|
|
1512
|
-
|
|
1513
|
-
*Ry Kulp*
|
|
1514
|
-
|
|
1515
1527
|
* Simplify CI configuration to a single build per Ruby/Rails version.
|
|
1516
1528
|
|
|
1517
1529
|
*Joel Hawksley*
|
|
@@ -1520,10 +1532,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1520
1532
|
|
|
1521
1533
|
*Ruben Smit*
|
|
1522
1534
|
|
|
1523
|
-
* Add Yobbers to list of companies using ViewComponent.
|
|
1524
|
-
|
|
1525
|
-
*Anton Prins*
|
|
1526
|
-
|
|
1527
1535
|
## 2.72.0
|
|
1528
1536
|
|
|
1529
1537
|
* Deprecate support for Ruby < 2.7 for removal in v3.0.0.
|
|
@@ -1538,10 +1546,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1538
1546
|
|
|
1539
1547
|
*Joel Hawksley.
|
|
1540
1548
|
|
|
1541
|
-
* Add Aluuno to list of companies using ViewComponent.
|
|
1542
|
-
|
|
1543
|
-
*Daniel Naves de Carvalho*
|
|
1544
|
-
|
|
1545
1549
|
* Add `source_code_uri` to gemspec.
|
|
1546
1550
|
|
|
1547
1551
|
*Yoshiyuki Hirano*
|
|
@@ -1576,22 +1580,10 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1576
1580
|
|
|
1577
1581
|
*Joel Hawksley*
|
|
1578
1582
|
|
|
1579
|
-
* Add Arrows to list of companies using ViewComponent.
|
|
1580
|
-
|
|
1581
|
-
*Matt Swanson*
|
|
1582
|
-
|
|
1583
|
-
* Add WIP to list of companies using ViewComponent.
|
|
1584
|
-
|
|
1585
|
-
*Marc Köhlbrugge*
|
|
1586
|
-
|
|
1587
1583
|
* Update slots documentation to include how to reference slots.
|
|
1588
1584
|
|
|
1589
1585
|
*Brittany Ellich*
|
|
1590
1586
|
|
|
1591
|
-
* Add Clio to list of companies using ViewComponent.
|
|
1592
|
-
|
|
1593
|
-
*Mike Buckley*
|
|
1594
|
-
|
|
1595
1587
|
## 2.69.0
|
|
1596
1588
|
|
|
1597
1589
|
* Add missing `require` to fix `pvc` build.
|
|
@@ -1709,10 +1701,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1709
1701
|
|
|
1710
1702
|
*Vikram Dighe*
|
|
1711
1703
|
|
|
1712
|
-
* Add HappyCo to list of companies using ViewComponent.
|
|
1713
|
-
|
|
1714
|
-
*Josh Clayton*
|
|
1715
|
-
|
|
1716
1704
|
* Add predicate method support to polymorphic slots.
|
|
1717
1705
|
|
|
1718
1706
|
*Graham Rogers*
|
|
@@ -1823,10 +1811,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1823
1811
|
|
|
1824
1812
|
*Thomas Hutterer*
|
|
1825
1813
|
|
|
1826
|
-
* Add FreeAgent to list of companies using ViewComponent.
|
|
1827
|
-
|
|
1828
|
-
*Simon Fish*
|
|
1829
|
-
|
|
1830
1814
|
* Include polymorphic slots in `ViewComponent::Base` by default.
|
|
1831
1815
|
|
|
1832
1816
|
*Cameron Dutro*
|
|
@@ -1882,18 +1866,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1882
1866
|
|
|
1883
1867
|
*Joel Hawksley*
|
|
1884
1868
|
|
|
1885
|
-
* Add G2 to list of companies that use ViewComponent.
|
|
1886
|
-
|
|
1887
|
-
*Jack Shuff*
|
|
1888
|
-
|
|
1889
|
-
* Add Within3 to list of companies that use ViewComponent.
|
|
1890
|
-
|
|
1891
|
-
*Drew Bragg*
|
|
1892
|
-
|
|
1893
|
-
* Add Mission Met to list of companies that use ViewComponent.
|
|
1894
|
-
|
|
1895
|
-
*Nick Smith*
|
|
1896
|
-
|
|
1897
1869
|
* Fix `#with_request_url` test helper not parsing nested query parameters into nested hashes.
|
|
1898
1870
|
|
|
1899
1871
|
*Richard Marbach*
|
|
@@ -1933,10 +1905,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1933
1905
|
|
|
1934
1906
|
*Blake Williams*
|
|
1935
1907
|
|
|
1936
|
-
* Add QuickNode to list of companies that use ViewComponent.
|
|
1937
|
-
|
|
1938
|
-
*Luc Castera*
|
|
1939
|
-
|
|
1940
1908
|
* Include the `Translatable` module by default.
|
|
1941
1909
|
|
|
1942
1910
|
*Elia Schito*
|
|
@@ -1967,10 +1935,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
1967
1935
|
|
|
1968
1936
|
*Jason Swett*
|
|
1969
1937
|
|
|
1970
|
-
* Add Bearer to list of companies that use ViewComponent.
|
|
1971
|
-
|
|
1972
|
-
*Yaroslav Shmarov*
|
|
1973
|
-
|
|
1974
1938
|
* Add articles to resources page.
|
|
1975
1939
|
|
|
1976
1940
|
*Joel Hawksley*
|
|
@@ -2000,10 +1964,6 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon
|
|
|
2000
1964
|
|
|
2001
1965
|
*Hans Lemuet*
|
|
2002
1966
|
|
|
2003
|
-
* Alphabetize companies using ViewComponent and add Brightline to the list.
|
|
2004
|
-
|
|
2005
|
-
*Jack Schuss*
|
|
2006
|
-
|
|
2007
1967
|
* Add CMYK value for ViewComponent Red color on logo page.
|
|
2008
1968
|
|
|
2009
1969
|
*Dylan Smith*
|
data/lib/view_component/base.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "action_view"
|
|
4
|
-
require "active_support/configurable"
|
|
5
4
|
require "view_component/collection"
|
|
6
5
|
require "view_component/compile_cache"
|
|
7
6
|
require "view_component/compiler"
|
|
@@ -47,7 +46,7 @@ module ViewComponent
|
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
include ActionView::Helpers
|
|
50
|
-
include Rails.application.routes.url_helpers if defined?(Rails
|
|
49
|
+
include Rails.application.routes.url_helpers if defined?(Rails.application.routes)
|
|
51
50
|
include ERB::Escape
|
|
52
51
|
include ActiveSupport::CoreExt::ERBUtil
|
|
53
52
|
|
|
@@ -132,6 +131,7 @@ module ViewComponent
|
|
|
132
131
|
|
|
133
132
|
@__vc_content_evaluated = false
|
|
134
133
|
@__vc_render_in_block = block
|
|
134
|
+
@view_context.instance_variable_set(:@virtual_path, virtual_path)
|
|
135
135
|
|
|
136
136
|
before_render
|
|
137
137
|
|
|
@@ -139,8 +139,6 @@ module ViewComponent
|
|
|
139
139
|
value = nil
|
|
140
140
|
|
|
141
141
|
@output_buffer.with_buffer do
|
|
142
|
-
@view_context.instance_variable_set(:@virtual_path, virtual_path)
|
|
143
|
-
|
|
144
142
|
rendered_template =
|
|
145
143
|
around_render do
|
|
146
144
|
render_template_for(@__vc_requested_details).to_s
|
|
@@ -261,6 +259,9 @@ module ViewComponent
|
|
|
261
259
|
@view_context.render(options, args, &block)
|
|
262
260
|
elsif block
|
|
263
261
|
__vc_original_view_context.render(options, args) do
|
|
262
|
+
# capture the block output in the view context of the component
|
|
263
|
+
output = capture(&block)
|
|
264
|
+
|
|
264
265
|
# Partials are rendered to their own buffer and do not append to the
|
|
265
266
|
# original @output_buffer we retain a reference to in #render_in. This
|
|
266
267
|
# is a problem since the block passed to us here in the #render method
|
|
@@ -268,7 +269,7 @@ module ViewComponent
|
|
|
268
269
|
# appends to the original @output_buffer. To avoid this, we evaluate the
|
|
269
270
|
# block in the view context instead, which will append to the output buffer
|
|
270
271
|
# created for the partial.
|
|
271
|
-
__vc_original_view_context.
|
|
272
|
+
__vc_original_view_context.capture { output }
|
|
272
273
|
end
|
|
273
274
|
else
|
|
274
275
|
__vc_original_view_context.render(options, args)
|
|
@@ -302,7 +303,7 @@ module ViewComponent
|
|
|
302
303
|
@__vc_helpers ||= __vc_original_view_context || controller.view_context
|
|
303
304
|
end
|
|
304
305
|
|
|
305
|
-
if ::Rails.env.development? || ::Rails.env.test?
|
|
306
|
+
if defined?(Rails.env) && (::Rails.env.development? || ::Rails.env.test?)
|
|
306
307
|
# @private
|
|
307
308
|
def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToMissing
|
|
308
309
|
super
|
|
@@ -331,7 +332,7 @@ module ViewComponent
|
|
|
331
332
|
[]
|
|
332
333
|
end
|
|
333
334
|
|
|
334
|
-
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
|
335
|
+
if defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
|
335
336
|
# Rails expects us to define `format` on all renderables,
|
|
336
337
|
# but we do not know the `format` of a ViewComponent until runtime.
|
|
337
338
|
def format
|
|
@@ -362,7 +363,7 @@ module ViewComponent
|
|
|
362
363
|
|
|
363
364
|
@__vc_content =
|
|
364
365
|
if __vc_render_in_block_provided?
|
|
365
|
-
|
|
366
|
+
with_captured_virtual_path(@old_virtual_path) do
|
|
366
367
|
view_context.capture(self, &@__vc_render_in_block)
|
|
367
368
|
end
|
|
368
369
|
elsif __vc_content_set_by_with_content_defined?
|
|
@@ -378,11 +379,14 @@ module ViewComponent
|
|
|
378
379
|
end
|
|
379
380
|
|
|
380
381
|
# @private
|
|
381
|
-
|
|
382
|
-
|
|
382
|
+
# Temporarily sets the virtual path to the captured value, then restores it.
|
|
383
|
+
# This ensures translations and other path-dependent code execute with the correct scope.
|
|
384
|
+
def with_captured_virtual_path(captured_path)
|
|
385
|
+
old_virtual_path = @view_context.instance_variable_get(:@virtual_path)
|
|
386
|
+
@view_context.instance_variable_set(:@virtual_path, captured_path)
|
|
383
387
|
yield
|
|
384
388
|
ensure
|
|
385
|
-
@view_context.instance_variable_set(:@virtual_path,
|
|
389
|
+
@view_context.instance_variable_set(:@virtual_path, old_virtual_path)
|
|
386
390
|
end
|
|
387
391
|
|
|
388
392
|
private
|
|
@@ -611,6 +615,16 @@ module ViewComponent
|
|
|
611
615
|
__vc_compiler.compiled?
|
|
612
616
|
end
|
|
613
617
|
|
|
618
|
+
# Hook called by the compiler after a component is compiled.
|
|
619
|
+
#
|
|
620
|
+
# Extensions can override this class method to run logic after
|
|
621
|
+
# compilation (e.g., generate helpers, register metadata, etc.).
|
|
622
|
+
#
|
|
623
|
+
# By default, this is a no-op.
|
|
624
|
+
def after_compile
|
|
625
|
+
# no-op by default
|
|
626
|
+
end
|
|
627
|
+
|
|
614
628
|
# @private
|
|
615
629
|
def __vc_ensure_compiled
|
|
616
630
|
__vc_compile unless __vc_compiled?
|
|
@@ -20,7 +20,7 @@ module ViewComponent
|
|
|
20
20
|
components.each(&block)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
|
23
|
+
if defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
|
24
24
|
# Rails expects us to define `format` on all renderables,
|
|
25
25
|
# but we do not know the `format` of a ViewComponent until runtime.
|
|
26
26
|
def format
|
|
@@ -163,7 +163,7 @@ module ViewComponent
|
|
|
163
163
|
options = ActiveSupport::OrderedOptions.new
|
|
164
164
|
options.controller = "ViewComponentsController"
|
|
165
165
|
options.route = "/rails/view_components"
|
|
166
|
-
options.enabled = Rails.env.development? || Rails.env.test?
|
|
166
|
+
options.enabled = defined?(Rails.env) && (Rails.env.development? || Rails.env.test?)
|
|
167
167
|
options.default_layout = nil
|
|
168
168
|
options.paths = default_preview_paths
|
|
169
169
|
options
|
|
@@ -4,14 +4,30 @@ module ViewComponent
|
|
|
4
4
|
module Configurable
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
|
+
class_methods do
|
|
8
|
+
def config
|
|
9
|
+
@_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config)
|
|
10
|
+
superclass.config.inheritable_copy
|
|
11
|
+
else
|
|
12
|
+
ActiveSupport::OrderedOptions.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def configure
|
|
17
|
+
yield config
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
7
21
|
included do
|
|
8
22
|
next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:instrumentation_enabled)
|
|
9
23
|
|
|
10
|
-
include ActiveSupport::Configurable
|
|
11
|
-
|
|
12
24
|
configure do |config|
|
|
13
25
|
config.view_component ||= ActiveSupport::InheritableOptions.new
|
|
14
26
|
end
|
|
27
|
+
|
|
28
|
+
def config
|
|
29
|
+
self.class.config
|
|
30
|
+
end
|
|
15
31
|
end
|
|
16
32
|
end
|
|
17
33
|
end
|
data/lib/view_component/slot.rb
CHANGED
|
@@ -6,7 +6,7 @@ module ViewComponent
|
|
|
6
6
|
class Slot
|
|
7
7
|
include ViewComponent::WithContentHelper
|
|
8
8
|
|
|
9
|
-
attr_writer :__vc_component_instance, :__vc_content_block, :__vc_content
|
|
9
|
+
attr_writer :__vc_component_instance, :__vc_content_block, :__vc_content, :__vc_content_block_virtual_path
|
|
10
10
|
|
|
11
11
|
def initialize(parent)
|
|
12
12
|
@parent = parent
|
|
@@ -58,7 +58,7 @@ module ViewComponent
|
|
|
58
58
|
if defined?(@__vc_content_block)
|
|
59
59
|
# render_in is faster than `parent.render`
|
|
60
60
|
@__vc_component_instance.render_in(view_context) do |*args|
|
|
61
|
-
@parent.
|
|
61
|
+
@parent.with_captured_virtual_path(@__vc_content_block_virtual_path) do
|
|
62
62
|
@__vc_content_block.call(*args)
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -68,7 +68,7 @@ module ViewComponent
|
|
|
68
68
|
elsif defined?(@__vc_content)
|
|
69
69
|
@__vc_content
|
|
70
70
|
elsif defined?(@__vc_content_block)
|
|
71
|
-
@parent.
|
|
71
|
+
@parent.with_captured_virtual_path(@__vc_content_block_virtual_path) do
|
|
72
72
|
view_context.capture(&@__vc_content_block)
|
|
73
73
|
end
|
|
74
74
|
elsif defined?(@__vc_content_set_by_with_content)
|
|
@@ -390,7 +390,12 @@ module ViewComponent
|
|
|
390
390
|
# 2. Since we have to pass block content to components when calling
|
|
391
391
|
# `render`, evaluating the block here would require us to call
|
|
392
392
|
# `view_context.capture` twice, which is slower
|
|
393
|
-
|
|
393
|
+
if block
|
|
394
|
+
slot.__vc_content_block = block
|
|
395
|
+
# Capture the virtual path at the time the block is defined, so that
|
|
396
|
+
# translations resolve relative to where the block was created, not where it's rendered
|
|
397
|
+
slot.__vc_content_block_virtual_path = view_context.instance_variable_get(:@virtual_path)
|
|
398
|
+
end
|
|
394
399
|
|
|
395
400
|
# If class
|
|
396
401
|
if slot_definition[:renderable]
|
|
@@ -408,7 +413,9 @@ module ViewComponent
|
|
|
408
413
|
renderable_value =
|
|
409
414
|
if block
|
|
410
415
|
renderable_function.call(*args, **kwargs) do |*rargs|
|
|
411
|
-
|
|
416
|
+
with_captured_virtual_path(@old_virtual_path) do
|
|
417
|
+
view_context.capture(*rargs, &block)
|
|
418
|
+
end
|
|
412
419
|
end
|
|
413
420
|
else
|
|
414
421
|
renderable_function.call(*args, **kwargs)
|
|
@@ -21,11 +21,20 @@ module ViewComponent
|
|
|
21
21
|
|
|
22
22
|
class File < Template
|
|
23
23
|
def initialize(component:, details:, path:)
|
|
24
|
+
# Rails 8.1 added a newline to the compiled ERB output in
|
|
25
|
+
# https://github.com/rails/rails/pull/53731
|
|
26
|
+
lineno =
|
|
27
|
+
if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
|
|
28
|
+
- 1
|
|
29
|
+
else
|
|
30
|
+
0
|
|
31
|
+
end
|
|
32
|
+
|
|
24
33
|
super(
|
|
25
34
|
component: component,
|
|
26
35
|
details: details,
|
|
27
36
|
path: path,
|
|
28
|
-
lineno:
|
|
37
|
+
lineno: lineno
|
|
29
38
|
)
|
|
30
39
|
end
|
|
31
40
|
|
|
@@ -45,11 +54,20 @@ module ViewComponent
|
|
|
45
54
|
def initialize(component:, inline_template:)
|
|
46
55
|
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym, nil, nil)
|
|
47
56
|
|
|
57
|
+
# Rails 8.1 added a newline to the compiled ERB output in
|
|
58
|
+
# https://github.com/rails/rails/pull/53731
|
|
59
|
+
lineno =
|
|
60
|
+
if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
|
|
61
|
+
inline_template.lineno - 1
|
|
62
|
+
else
|
|
63
|
+
inline_template.lineno
|
|
64
|
+
end
|
|
65
|
+
|
|
48
66
|
super(
|
|
49
67
|
component: component,
|
|
50
68
|
details: details,
|
|
51
69
|
path: inline_template.path,
|
|
52
|
-
lineno:
|
|
70
|
+
lineno: lineno,
|
|
53
71
|
)
|
|
54
72
|
|
|
55
73
|
@source = inline_template.source.dup
|
|
@@ -40,7 +40,7 @@ module ViewComponent
|
|
|
40
40
|
@page = nil
|
|
41
41
|
@rendered_content = vc_test_view_context.render(component, args, &block)
|
|
42
42
|
|
|
43
|
-
fragment = Nokogiri::HTML5.fragment(@rendered_content)
|
|
43
|
+
fragment = Nokogiri::HTML5.fragment(@rendered_content, context: "template")
|
|
44
44
|
@vc_test_view_context = nil
|
|
45
45
|
fragment
|
|
46
46
|
end
|
data/lib/view_component.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "action_view"
|
|
4
4
|
require "active_support/dependencies/autoload"
|
|
5
|
+
require "view_component/version"
|
|
5
6
|
|
|
6
7
|
module ViewComponent
|
|
7
8
|
extend ActiveSupport::Autoload
|
|
@@ -16,7 +17,7 @@ module ViewComponent
|
|
|
16
17
|
autoload :Preview
|
|
17
18
|
autoload :Translatable
|
|
18
19
|
|
|
19
|
-
if Rails.env.test?
|
|
20
|
+
if defined?(Rails.env) && Rails.env.test?
|
|
20
21
|
autoload :TestHelpers
|
|
21
22
|
autoload :SystemSpecHelpers
|
|
22
23
|
autoload :SystemTestHelpers
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ViewComponent Team
|
|
@@ -16,9 +16,6 @@ dependencies:
|
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: 7.1.0
|
|
19
|
-
- - "<"
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: '8.2'
|
|
22
19
|
type: :runtime
|
|
23
20
|
prerelease: false
|
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -26,9 +23,20 @@ dependencies:
|
|
|
26
23
|
- - ">="
|
|
27
24
|
- !ruby/object:Gem::Version
|
|
28
25
|
version: 7.1.0
|
|
29
|
-
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: actionview
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
30
31
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
32
|
+
version: 7.1.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 7.1.0
|
|
32
40
|
- !ruby/object:Gem::Dependency
|
|
33
41
|
name: concurrent-ruby
|
|
34
42
|
requirement: !ruby/object:Gem::Requirement
|