view_component-contrib 0.1.5 → 0.1.6
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cebcea7442b79ea935dd0039c361e813b597c8f63a15a9cd90407635a6a96856
|
4
|
+
data.tar.gz: 98e1aeecc1354a1e619bf75c765aa64f0051ac5ff4d7d0c81fb42425e7da7ae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427691d12a38bfcab3c0861506aade1ada63422badb1b207e5fff49cd72bc66c8a6aadfd220b51385ef5abc2166061cd8333afbf14e915058e98bf2899438ad5
|
7
|
+
data.tar.gz: 5eb44287d55acb724d458d6eca667296787215cafced750c9071834ee2203b89327d93ff983b1b2e9879b961e13eb8b5d4f2af237c690a4c3f6bc6cbdaa6654c
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.1.6 (2023-11-07)
|
6
|
+
|
7
|
+
- Support preview classes named `<component|partial>_preview.rb`. ([@palkan][])
|
8
|
+
|
9
|
+
It's also possible to explicitly specify the component class name for the preview class:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class MyComponentPreview
|
13
|
+
self.component_class_name = "SomeComponent"
|
14
|
+
|
15
|
+
def default
|
16
|
+
render_component
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
5
21
|
## 0.1.5 (2023-11-02)
|
6
22
|
|
7
23
|
- Support content blocks in `#render_component` and `#render_with`. ([@palkan][])
|
@@ -43,11 +43,29 @@ module ViewComponentContrib
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
# Infer component class name from preview class name:
|
47
|
+
# - Namespace::ButtonPreview => Namespace::Button::Component | Namespace::ButtonComponent | Namespace::Button
|
48
|
+
# - Button::Preview => Button::Component | ButtonComponent | Button
|
49
|
+
def component_class_name
|
50
|
+
@component_class_name ||= begin
|
51
|
+
component_name = name.sub(/(::Preview|Preview)$/, "")
|
52
|
+
[
|
53
|
+
"#{component_name}::Component",
|
54
|
+
"#{component_name}Component",
|
55
|
+
component_name
|
56
|
+
].find do
|
57
|
+
_1.safe_constantize
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_writer :component_class_name
|
63
|
+
|
46
64
|
private
|
47
65
|
|
48
66
|
def build_component_instance(locals)
|
49
67
|
return locals unless locals[:component].nil?
|
50
|
-
locals[:component] =
|
68
|
+
locals[:component] = component_class_name.safe_constantize&.new
|
51
69
|
rescue => e
|
52
70
|
locals[:component] = nil
|
53
71
|
locals[:error] = e.message
|
@@ -64,7 +82,7 @@ module ViewComponentContrib
|
|
64
82
|
component = if component_or_props.is_a?(::ViewComponent::Base)
|
65
83
|
component_or_props
|
66
84
|
else
|
67
|
-
self.class.
|
85
|
+
self.class.component_class_name.constantize.new(**(component_or_props || {}))
|
68
86
|
end
|
69
87
|
|
70
88
|
render_with(component: component, content_block: block)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module ViewComponentContrib
|
4
4
|
module Preview
|
5
5
|
module Sidecarable
|
6
|
-
PREVIEW_GLOB = "**/preview.rb"
|
6
|
+
PREVIEW_GLOB = "**/{preview.rb,*_preview.rb}"
|
7
7
|
|
8
8
|
def self.extended(base)
|
9
9
|
base.singleton_class.prepend(ClassMethods)
|
@@ -17,7 +17,7 @@ module ViewComponentContrib
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def preview_name
|
20
|
-
name.
|
20
|
+
name.sub(/(::Preview|Preview)$/, "").underscore
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: view_component
|