view_component_subtemplates 0.1.1 → 0.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ceb9e9e6a47b06706f7464baf5f4a2f5754b10b670ae3bf28dfed61ca3068027
|
|
4
|
+
data.tar.gz: 887ad1b1f30395592da4a3a90c78f22691715864f8e821e985c32cd4f0e1cf9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d00849719d594843981c36d0bf85a44fa933b31fe1e49034434e92d18a6af377d7e89391e105f623bcff3a1727620f799827775bcf6ace4aa1afb76fe76ee003
|
|
7
|
+
data.tar.gz: fe2554a34486b1c27e3a452d5b5bc3b9830bba3677f284c5d1a5ae8cef43be5359b44f0cf4f7e01b756fa26d73f7ce9008ac22bfb2e063d623cacff30a6eada5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-01-21
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Automatic subtemplate processing for ancestor components
|
|
7
|
+
- Support for multi-level inheritance (grandparent → parent → child)
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- Inheritance issue where child components miss parent's `call_*` methods
|
|
11
|
+
|
|
3
12
|
## [0.1.1] - 2026-01-13
|
|
4
13
|
|
|
5
14
|
### Changed
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# compiler_extension.rb
|
|
4
3
|
module ViewComponentSubtemplates
|
|
4
|
+
# Extends ViewComponent's compilation process to handle subtemplates.
|
|
5
5
|
module CompilerExtension
|
|
6
|
-
#
|
|
7
|
-
#
|
|
6
|
+
# Compiles all subtemplates for a component into call_* methods.
|
|
7
|
+
# Skips processing if already done for this component.
|
|
8
|
+
#
|
|
9
|
+
# @param component_class [Class] the component class to process
|
|
10
|
+
# @return [void]
|
|
8
11
|
def self.process_component(component_class)
|
|
12
|
+
return if component_class.instance_variable_get(:@__subtemplates_processed)
|
|
13
|
+
|
|
9
14
|
gather_sub_templates_for(component_class).each(&:compile_to_component)
|
|
15
|
+
component_class.instance_variable_set(:@__subtemplates_processed, true)
|
|
10
16
|
end
|
|
11
17
|
|
|
18
|
+
# Discovers subtemplate files in the component's subdirectory.
|
|
19
|
+
#
|
|
20
|
+
# @param component_class [Class] the component class
|
|
21
|
+
# @return [Array<SubTemplate>] array of subtemplate objects
|
|
12
22
|
def self.gather_sub_templates_for(component_class)
|
|
13
23
|
component_subdir = ViewComponentSubtemplates.component_subdir_for(component_class)
|
|
14
24
|
return [] unless Dir.exist?(component_subdir)
|
|
@@ -17,12 +27,8 @@ module ViewComponentSubtemplates
|
|
|
17
27
|
|
|
18
28
|
Dir.glob(File.join(component_subdir, "*")).filter_map do |file_path|
|
|
19
29
|
next unless File.file?(file_path)
|
|
30
|
+
next unless template_extensions.include?(File.extname(file_path)[1..])
|
|
20
31
|
|
|
21
|
-
file_extension = File.extname(file_path)[1..] # Remove the leading dot
|
|
22
|
-
next unless template_extensions.include?(file_extension)
|
|
23
|
-
|
|
24
|
-
# Correctly extract template name by removing the first extension found.
|
|
25
|
-
# e.g. "header.html.erb" -> "header"
|
|
26
32
|
template_name = File.basename(file_path).split(".").first
|
|
27
33
|
|
|
28
34
|
SubTemplate.new(
|
|
@@ -26,7 +26,11 @@ module ViewComponentSubtemplates
|
|
|
26
26
|
module AfterCompileHook
|
|
27
27
|
def after_compile
|
|
28
28
|
super
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
# Process subtemplates for all ancestors (top to bottom) and self
|
|
31
|
+
ancestors.select { |a| a.is_a?(Class) && a < ViewComponent::Base }
|
|
32
|
+
.reverse
|
|
33
|
+
.each { |ancestor| ViewComponentSubtemplates::CompilerExtension.process_component(ancestor) }
|
|
30
34
|
end
|
|
31
35
|
end
|
|
32
36
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component_subtemplates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jsolas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|