sorbet_erb 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.ruby-version +1 -0
- data/lib/sorbet_erb/version.rb +1 -1
- data/lib/sorbet_erb.rb +39 -2
- data/lib/tapioca/dsl/compilers/view_component_slotables.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1243e1d235eda3fa678fb4cc05edf42af42548b453d679058cf3a84ab1bfe405
|
4
|
+
data.tar.gz: cd5c593cb18eef72cbe4a8bf3ba9209b3090b462714187ed1d36fedb7a5e1a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4a0d9521a33594a74488a6ae3e1ee62d8f970209f75190cdb67a61a90ddb4010702071c3a81b27e97b4c5f3374c518b3374196d88b65601316477498c97413
|
7
|
+
data.tar.gz: d01ca6fbcbdb67752099e2d9602ee41bedb6fc4ef5322be0d6c66c939bdf27608edb4041f2d0db788c64062d84d2f3a0e23da78aca84b633333f3cad3ca3e8a8
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.6
|
data/lib/sorbet_erb/version.rb
CHANGED
data/lib/sorbet_erb.rb
CHANGED
@@ -28,7 +28,7 @@ module SorbetErb
|
|
28
28
|
|
29
29
|
ERB_TEMPLATE = <<~ERB_TEMPLATE
|
30
30
|
# typed: true
|
31
|
-
class
|
31
|
+
class <%= class_name %><%= extend_app_controller ? " < ApplicationController" : "" %>
|
32
32
|
extend T::Sig
|
33
33
|
include ActionView::Helpers
|
34
34
|
include ApplicationController::HelperMethods
|
@@ -87,6 +87,8 @@ module SorbetErb
|
|
87
87
|
locals ||= '()'
|
88
88
|
locals_sig ||= ''
|
89
89
|
|
90
|
+
class_name, extend_app_controller = class_name_from_path(pathname)
|
91
|
+
|
90
92
|
rel_output_dir = File.join(
|
91
93
|
output_dir,
|
92
94
|
pathname.dirname.relative_path_from(d)
|
@@ -100,7 +102,8 @@ module SorbetErb
|
|
100
102
|
erb = ERB.new(ERB_TEMPLATE)
|
101
103
|
File.open(output_path, 'w') do |f|
|
102
104
|
result = erb.result_with_hash(
|
103
|
-
|
105
|
+
class_name: class_name,
|
106
|
+
extend_app_controller: extend_app_controller,
|
104
107
|
locals: locals,
|
105
108
|
locals_sig: locals_sig,
|
106
109
|
extra_includes: config.fetch('extra_includes'),
|
@@ -127,6 +130,40 @@ module SorbetErb
|
|
127
130
|
file_name.start_with?('_') || file_name.end_with?('.turbo_stream.erb')
|
128
131
|
end
|
129
132
|
|
133
|
+
def self.class_name_from_path(pathname)
|
134
|
+
# ViewComponents are stored under app/components, and the partials need access to the instance
|
135
|
+
# methods and variables available on the component class, so set the class name to the component
|
136
|
+
# class name.
|
137
|
+
# TODO: support namespacing
|
138
|
+
if pathname.to_s.start_with?('app/components')
|
139
|
+
return [
|
140
|
+
extract_class_name(pathname).map do |part|
|
141
|
+
ActiveSupport::Inflector.camelize(part)
|
142
|
+
end.join('::'),
|
143
|
+
false
|
144
|
+
]
|
145
|
+
end
|
146
|
+
|
147
|
+
# Otherwise make a random class so this doesn't collide with any existing code
|
148
|
+
["SorbetErb#{SecureRandom.hex(6)}", true]
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.extract_class_name(pathname)
|
152
|
+
return [] if pathname.to_s == 'app/components' || pathname.to_s == '.'
|
153
|
+
|
154
|
+
# Strip template suffix
|
155
|
+
basename = File.basename(pathname.basename, '.html.erb')
|
156
|
+
|
157
|
+
# We need to handle the cases where the dirname matches the component name, or if there's
|
158
|
+
# a namespace
|
159
|
+
# `app/components/my_component/my_component.html.erb`
|
160
|
+
# `app/components/namespace/my_component/my_component.html.erb`
|
161
|
+
dirname = pathname.dirname
|
162
|
+
dirname = dirname.dirname if basename.to_s == dirname.basename.to_s
|
163
|
+
|
164
|
+
extract_class_name(dirname) + [basename]
|
165
|
+
end
|
166
|
+
|
130
167
|
def self.start(argv)
|
131
168
|
input = argv[0]
|
132
169
|
output = argv[1]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet_erb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franklin Hu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".rubocop.yml"
|
64
|
+
- ".ruby-version"
|
64
65
|
- README.md
|
65
66
|
- Rakefile
|
66
67
|
- exe/sorbet_erb
|
@@ -76,7 +77,7 @@ metadata:
|
|
76
77
|
homepage_uri: https://github.com/franklinhu/sorbet_erb
|
77
78
|
source_code_uri: https://github.com/franklinhu/sorbet_erb
|
78
79
|
changelog_uri: https://github.com/franklinhu/sorbet_erb
|
79
|
-
post_install_message:
|
80
|
+
post_install_message:
|
80
81
|
rdoc_options: []
|
81
82
|
require_paths:
|
82
83
|
- lib
|
@@ -84,15 +85,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
85
|
requirements:
|
85
86
|
- - ">="
|
86
87
|
- !ruby/object:Gem::Version
|
87
|
-
version: 3.
|
88
|
+
version: 3.1.0
|
88
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
91
|
- - ">="
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.5.
|
95
|
-
signing_key:
|
95
|
+
rubygems_version: 3.5.22
|
96
|
+
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Extracts Ruby code from ERB files for Sorbet
|
98
99
|
test_files: []
|