view_component_subtemplates 0.1.0 → 0.1.1

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: 604c21a85c4afb58ae6b08b1bc1fcbc99ed132de60bb7d9e846b3fe0e50e0c25
4
- data.tar.gz: b5a0456d4a5d8f83d3368f03839a2d04ffbcb6edbc97e2d6224eaae30737a4d5
3
+ metadata.gz: f7f722cb0d9a6fcd6224817d0e22c98eac0e958fbc4e97fd40b756522aebe462
4
+ data.tar.gz: 23e07e652f582ed9827adb0ae6100c76587c9fd115346a5fe843f8cf0e8c881c
5
5
  SHA512:
6
- metadata.gz: 276d58f9205465d4c98cb4fe864764dd58d130a850b4b05bb3a5c21942f68edc8a5f123aa5d8dbe68ac4746ea282c97d299a44df5bae3bb4cddfc091182757a1
7
- data.tar.gz: f36101a4c89486232386935f7b1676a9b359aa1b0ede4b6df95fbf5ef371d4dc5b6633fb3cb59c86f73dc6fea20c60696e42059e447ce3a40934eb0dd8407290
6
+ metadata.gz: ac11be7bea5d9ecca0f28b03606a9044a75b3492f3e877bf0e73e97809e66e74d180bb595b314005e43176171889c4314fe60514e8a6ba63691261e04064922a
7
+ data.tar.gz: 88786270c38e3637cfbb5dc45ab0c4f44da14a06ed0c7a92f1d814f7bd09c2551739227172329fd02d035ddae1a834ffb3767c7afa14a16bd81a546d61ab7a48
data/.rubocop.yml CHANGED
@@ -1,8 +1,36 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 3.1
3
+ SuggestExtensions: false
3
4
 
4
5
  Style/StringLiterals:
5
6
  EnforcedStyle: double_quotes
6
7
 
7
8
  Style/StringLiteralsInInterpolation:
8
9
  EnforcedStyle: double_quotes
10
+
11
+ # Disable documentation requirements for this gem
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ # Allow longer methods in specific files
16
+ Metrics/MethodLength:
17
+ Max: 15
18
+
19
+ # Allow longer lines in gemspec
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - "*.gemspec"
23
+
24
+ # Disable metrics for tests
25
+ Metrics/ClassLength:
26
+ Exclude:
27
+ - "test/**/*"
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - "test/**/*"
32
+
33
+ # Tests may define classes without calling super
34
+ Lint/MissingSuper:
35
+ Exclude:
36
+ - "test/**/*"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2026-01-13
4
+
5
+ ### Changed
6
+ - Use official `after_compile` hook from ViewComponent 4.2.0 via `ActiveSupport.on_load(:view_component)`
7
+ - Expanded test matrix to Ruby 3.2, 3.3, and 3.4
8
+
9
+ ### Fixed
10
+ - Rubocop offenses
11
+
3
12
  ## [0.1.0] - 2025-07-18
4
13
 
5
14
  ### Agregado
@@ -1,32 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # compiler_extension.rb
2
4
  module ViewComponentSubtemplates
3
5
  module CompilerExtension
4
6
  # Processes a component class to compile its sub-templates.
5
7
  # Called from the after_compile hook.
6
8
  def self.process_component(component_class)
7
- gather_sub_templates_for(component_class).each do |sub_template|
8
- sub_template.compile_to_component
9
- end
9
+ gather_sub_templates_for(component_class).each(&:compile_to_component)
10
10
  end
11
11
 
12
- private
13
-
14
12
  def self.gather_sub_templates_for(component_class)
15
13
  component_subdir = ViewComponentSubtemplates.component_subdir_for(component_class)
16
14
  return [] unless Dir.exist?(component_subdir)
17
15
 
18
16
  template_extensions = ActionView::Template.template_handler_extensions
19
-
17
+
20
18
  Dir.glob(File.join(component_subdir, "*")).filter_map do |file_path|
21
19
  next unless File.file?(file_path)
22
-
20
+
23
21
  file_extension = File.extname(file_path)[1..] # Remove the leading dot
24
22
  next unless template_extensions.include?(file_extension)
25
-
23
+
26
24
  # Correctly extract template name by removing the first extension found.
27
25
  # e.g. "header.html.erb" -> "header"
28
- template_name = File.basename(file_path).split('.').first
29
-
26
+ template_name = File.basename(file_path).split(".").first
27
+
30
28
  SubTemplate.new(
31
29
  component: component_class,
32
30
  path: file_path,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # sub_template.rb
2
4
  module ViewComponentSubtemplates
3
5
  # Represents a single sub-template file associated with a ViewComponent.
@@ -42,9 +44,9 @@ module ViewComponentSubtemplates
42
44
  private
43
45
 
44
46
  def validate_file_exists!
45
- unless File.exist?(path)
46
- raise ViewComponentSubtemplates::Error, "Template file not found: #{path}"
47
- end
47
+ return if File.exist?(path)
48
+
49
+ raise ViewComponentSubtemplates::Error, "Template file not found: #{path}"
48
50
  end
49
51
 
50
52
  def extract_explicit_locals_from_source
@@ -70,9 +72,9 @@ module ViewComponentSubtemplates
70
72
  end
71
73
 
72
74
  def define_private_render_method(name, compiled_source, args)
73
- @component.class_eval <<~RUBY, path, 1
75
+ @component.class_eval <<~RUBY, __FILE__, __LINE__ + 1
74
76
  private
75
- def #{name}(#{args.join(', ')})
77
+ def #{name}(#{args.join(", ")})
76
78
  (#{compiled_source}).html_safe
77
79
  end
78
80
  RUBY
@@ -85,13 +87,13 @@ module ViewComponentSubtemplates
85
87
  signature = args.map { |arg| "#{arg}:" }.join(", ")
86
88
  forwarded_args = args.join(", ")
87
89
 
88
- @component.class_eval <<~RUBY, path, 1
90
+ @component.class_eval <<~RUBY, __FILE__, __LINE__ + 1
89
91
  def #{call_name}(#{signature})
90
92
  #{render_name}(#{forwarded_args})
91
93
  end
92
94
  RUBY
93
95
  else
94
- @component.class_eval <<~RUBY, path, 1
96
+ @component.class_eval <<~RUBY, __FILE__, __LINE__ + 1
95
97
  def #{call_name}
96
98
  #{render_name}
97
99
  end
@@ -100,7 +102,3 @@ module ViewComponentSubtemplates
100
102
  end
101
103
  end
102
104
  end
103
-
104
-
105
-
106
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentSubtemplates
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,11 +1,7 @@
1
1
  # view_component_subtemplates.rb
2
2
  # frozen_string_literal: true
3
3
 
4
- require "view_component"
5
-
6
- # Ensure ViewComponent internals are loaded
7
- require "view_component/base"
8
- require "view_component/compiler"
4
+ require "active_support"
9
5
 
10
6
  require_relative "view_component_subtemplates/version"
11
7
  require_relative "view_component_subtemplates/compiler_extension"
@@ -38,6 +34,7 @@ end
38
34
  # Load SubTemplate after the module is fully configured
39
35
  require_relative "view_component_subtemplates/sub_template"
40
36
 
41
- # Extend ViewComponent::Base class methods to hook into after_compile
42
- # This uses prepend on the singleton class to extend the class method
43
- ViewComponent::Base.singleton_class.prepend(ViewComponentSubtemplates::AfterCompileHook)
37
+ # Hook into ViewComponent when it loads (lazy loading for faster boot in development)
38
+ ActiveSupport.on_load(:view_component) do
39
+ ViewComponent::Base.singleton_class.prepend(ViewComponentSubtemplates::AfterCompileHook)
40
+ end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_subtemplates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-13 00:00:00.000000000 Z
11
+ date: 2026-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: view_component
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: view_component
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '7.0'
33
+ version: 4.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '7.0'
40
+ version: 4.2.0
41
41
  description: Adds support for sub-templates with arguments to ViewComponent, allowing
42
42
  components to have multiple templates in their sidecar directory.
43
43
  email:
@@ -55,7 +55,6 @@ files:
55
55
  - lib/view_component_subtemplates/compiler_extension.rb
56
56
  - lib/view_component_subtemplates/sub_template.rb
57
57
  - lib/view_component_subtemplates/version.rb
58
- - sig/view_component_subtemplates.rbs
59
58
  homepage: https://github.com/bukhr/view_component_subtemplates
60
59
  licenses:
61
60
  - MIT
@@ -1,4 +0,0 @@
1
- module ViewComponentSubtemplates
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end