fluxbit_view_components 0.1.0 → 0.3.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/README.md +7 -1
- data/app/components/fluxbit/form/check_box_component.rb +56 -0
- data/app/components/fluxbit/form/component.rb +20 -25
- data/app/components/fluxbit/form/dropzone_component.html.erb +39 -0
- data/app/components/fluxbit/form/dropzone_component.rb +39 -0
- data/app/components/fluxbit/form/field_component.rb +26 -0
- data/app/components/fluxbit/form/form_builder_component.rb +5 -7
- data/app/components/fluxbit/form/{helper_text_component.rb → help_text_component.rb} +8 -3
- data/app/components/fluxbit/form/label_component.rb +32 -29
- data/app/components/fluxbit/form/range_component.rb +52 -0
- data/app/components/fluxbit/form/select_component.rb +88 -0
- data/app/components/fluxbit/form/text_field_component.rb +168 -0
- data/app/components/fluxbit/form/toggle_component.html.erb +23 -0
- data/app/components/fluxbit/form/toggle_component.rb +81 -0
- data/app/components/fluxbit/form/upload_image_component.html.erb +50 -0
- data/app/components/fluxbit/form/upload_image_component.rb +50 -0
- data/app/helpers/fluxbit/classes_helper.rb +0 -12
- data/app/helpers/fluxbit/components_helper.rb +23 -51
- data/app/helpers/fluxbit/form_builder.rb +87 -0
- data/lib/fluxbit/config/form/check_box_component.rb +19 -0
- data/lib/fluxbit/config/form/dropzone_component.rb +20 -0
- data/lib/fluxbit/config/form/{helper_text_component.rb → help_text_component.rb} +1 -1
- data/lib/fluxbit/config/form/label_component.rb +30 -0
- data/lib/fluxbit/config/form/range_component.rb +15 -0
- data/lib/fluxbit/config/form/text_field_component.rb +76 -0
- data/{app/components/fluxbit/form/toggle_input_component.rb → lib/fluxbit/config/form/toggle_component.rb} +28 -115
- data/lib/fluxbit/templates/darkmode.js.template +7 -0
- data/lib/fluxbit/templates/tailwind.config.js.template +4 -0
- data/lib/fluxbit/view_components/version.rb +1 -3
- data/lib/fluxbit/view_components.rb +7 -1
- data/lib/install/install.rb +57 -47
- data/lib/tasks/fluxbit_view_components_tasks.rake +30 -10
- metadata +25 -25
- data/LICENSE.txt +0 -20
- data/app/components/fluxbit/form/checkbox_input_component.rb +0 -61
- data/app/components/fluxbit/form/datepicker_component.rb +0 -7
- data/app/components/fluxbit/form/radio_input_component.rb +0 -21
- data/app/components/fluxbit/form/range_input_component.rb +0 -51
- data/app/components/fluxbit/form/select_free_input_component.rb +0 -77
- data/app/components/fluxbit/form/select_input_component.rb +0 -21
- data/app/components/fluxbit/form/spacer_input_component.rb +0 -12
- data/app/components/fluxbit/form/text_input_component.rb +0 -225
- data/app/components/fluxbit/form/textarea_input_component.rb +0 -57
- data/app/components/fluxbit/form/upload_image_input_component.html.erb +0 -48
- data/app/components/fluxbit/form/upload_image_input_component.rb +0 -66
- data/app/components/fluxbit/form/upload_input_component.html.erb +0 -12
- data/app/components/fluxbit/form/upload_input_component.rb +0 -47
- data/lib/fluxbit/view_components/codemods/v3_slot_setters.rb +0 -222
@@ -1,222 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fluxbit
|
4
|
-
module ViewComponents
|
5
|
-
# Usage:
|
6
|
-
#
|
7
|
-
# Run via rake task:
|
8
|
-
#
|
9
|
-
# bin/rails fluxbit_view_components:detect_legacy_slots
|
10
|
-
# bin/rails fluxbit_view_components:migrate_legacy_slots
|
11
|
-
# bin/rails fluxbit_view_components:migrate_legacy_slots app/views
|
12
|
-
#
|
13
|
-
# Or run via rails console if you need to pass custom paths:
|
14
|
-
#
|
15
|
-
# Fluxbit::ViewComponents::Codemods::V3SlotSetters.new(
|
16
|
-
# view_path: Rails.root.join("app/views"),
|
17
|
-
# ).call
|
18
|
-
module Codemods
|
19
|
-
class V3SlotSetters
|
20
|
-
TEMPLATE_LANGUAGES = %w[erb slim haml].join(",").freeze
|
21
|
-
RENDER_REGEX = /render[( ](?<component>\w+(?:::\w+)*)\.new[) ]+(do|\{) \|(?<arg>\w+)\b/ # standard:disable Lint/MixedRegexpCaptureTypes
|
22
|
-
|
23
|
-
Suggestion = Struct.new(:file, :line, :message)
|
24
|
-
|
25
|
-
def initialize(view_component_path: [], view_path: [], migrate: false)
|
26
|
-
Rails.application.eager_load!
|
27
|
-
|
28
|
-
@view_component_path = view_component_path
|
29
|
-
@view_path = view_path
|
30
|
-
@migrate = migrate
|
31
|
-
end
|
32
|
-
|
33
|
-
def call
|
34
|
-
puts "Using ViewComponent path: #{view_component_paths.join(", ")}"
|
35
|
-
puts "Using Views path: #{view_paths.join(", ")}"
|
36
|
-
puts "#{view_components.size} ViewComponents found"
|
37
|
-
puts "#{slottable_components.size} ViewComponents using Slots found"
|
38
|
-
puts "#{view_component_files.size} ViewComponent templates found"
|
39
|
-
puts "#{view_files.size} view files found"
|
40
|
-
process_all_files
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_all_files
|
44
|
-
all_files.each do |file|
|
45
|
-
process_file(file)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def process_file(file)
|
50
|
-
@suggestions = []
|
51
|
-
@suggestions += scan_exact_matches(file)
|
52
|
-
@suggestions += scan_uncertain_matches(file)
|
53
|
-
|
54
|
-
return unless @suggestions.any?
|
55
|
-
|
56
|
-
puts
|
57
|
-
puts "File: #{file}"
|
58
|
-
@suggestions.each do |s|
|
59
|
-
puts "=> line #{s.line}: #{s.message}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def scan_exact_matches(file)
|
66
|
-
[].tap do |suggestions|
|
67
|
-
rendered_components = []
|
68
|
-
content = File.read(file)
|
69
|
-
|
70
|
-
if (render_match = content.match(RENDER_REGEX))
|
71
|
-
component = render_match[:component]
|
72
|
-
arg = render_match[:arg]
|
73
|
-
|
74
|
-
if registered_slots.key?(component.constantize)
|
75
|
-
used_slots_names = registered_slots[component.constantize]
|
76
|
-
rendered_components << { component: component, arg: arg, slots: used_slots_names }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
File.open(file, "r+") do |f|
|
81
|
-
lines = []
|
82
|
-
f.each_line do |line|
|
83
|
-
rendered_components.each do |rendered_component|
|
84
|
-
arg = rendered_component[:arg]
|
85
|
-
slots = rendered_component[:slots]
|
86
|
-
|
87
|
-
if (matches = line.scan(/#{arg}\.#{Regexp.union(slots)}/))
|
88
|
-
matches.each do |match|
|
89
|
-
new_value = match.gsub("#{arg}.", "#{arg}.with_")
|
90
|
-
message = if @migrate
|
91
|
-
"replaced `#{match}` with `#{new_value}`"
|
92
|
-
else
|
93
|
-
"probably replace `#{match}` with `#{new_value}`"
|
94
|
-
end
|
95
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
96
|
-
if @migrate
|
97
|
-
line.gsub!("#{arg}.", "#{arg}.with_")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
lines << line
|
103
|
-
end
|
104
|
-
|
105
|
-
if @migrate
|
106
|
-
f.rewind
|
107
|
-
f.write(lines.join)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def scan_uncertain_matches(file)
|
114
|
-
[].tap do |suggestions|
|
115
|
-
File.open(file, "r+") do |f|
|
116
|
-
lines = []
|
117
|
-
f.each_line do |line|
|
118
|
-
if (matches = line.scan(/(?<!\s)\.(?<slot>#{Regexp.union(all_registered_slot_names)})\b/))
|
119
|
-
matches.flatten.each do |match|
|
120
|
-
next if @suggestions.find { |s| s.file == file && s.line == f.lineno }
|
121
|
-
|
122
|
-
message = if @migrate
|
123
|
-
"replaced `#{match}` with `with_#{match}`"
|
124
|
-
else
|
125
|
-
"maybe replace `#{match}` with `with_#{match}`"
|
126
|
-
end
|
127
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
128
|
-
if @migrate
|
129
|
-
line.gsub!(/(?<!\s)\.(#{match})\b/, ".with_\\1")
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
lines << line
|
134
|
-
end
|
135
|
-
|
136
|
-
if @migrate
|
137
|
-
f.rewind
|
138
|
-
f.write(lines.join)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def view_components
|
145
|
-
ViewComponent::Base.descendants
|
146
|
-
end
|
147
|
-
|
148
|
-
def slottable_components
|
149
|
-
view_components.select do |comp|
|
150
|
-
comp.registered_slots.any?
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def registered_slots
|
155
|
-
@registered_slots ||= {}.tap do |slots|
|
156
|
-
puts
|
157
|
-
puts "Detected slots:"
|
158
|
-
slottable_components.each do |comp|
|
159
|
-
puts "- `#{comp}` has slots: #{comp.registered_slots.keys.join(", ")}"
|
160
|
-
slots[comp] = comp.registered_slots.map do |slot_name, slot|
|
161
|
-
normalized_slot_name(slot_name, slot)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def all_registered_slot_names
|
168
|
-
@all_registered_slot_names ||= registered_slots.values.flatten.uniq
|
169
|
-
end
|
170
|
-
|
171
|
-
def view_component_files
|
172
|
-
Dir.glob(Pathname.new(File.join(view_component_path_glob, "**", "*.{rb,#{TEMPLATE_LANGUAGES}}")))
|
173
|
-
end
|
174
|
-
|
175
|
-
def view_files
|
176
|
-
Dir.glob(Pathname.new(File.join(view_path_glob, "**", "*.{#{TEMPLATE_LANGUAGES}}")))
|
177
|
-
end
|
178
|
-
|
179
|
-
def all_files
|
180
|
-
view_component_files + view_files
|
181
|
-
end
|
182
|
-
|
183
|
-
def view_component_paths
|
184
|
-
@view_component_paths ||= [
|
185
|
-
Rails.application.config.view_component.view_component_path,
|
186
|
-
@view_component_path
|
187
|
-
].flatten.compact.uniq
|
188
|
-
end
|
189
|
-
|
190
|
-
def view_component_path_glob
|
191
|
-
return view_component_paths.first if view_component_paths.size == 1
|
192
|
-
|
193
|
-
"{#{view_component_paths.join(",")}}"
|
194
|
-
end
|
195
|
-
|
196
|
-
def rails_view_paths
|
197
|
-
ActionController::Base.view_paths.select do |path|
|
198
|
-
path.to_s.include?(Rails.root.to_s)
|
199
|
-
end.map(&:to_s)
|
200
|
-
end
|
201
|
-
|
202
|
-
def view_paths
|
203
|
-
@view_paths ||= [
|
204
|
-
rails_view_paths,
|
205
|
-
Rails.application.config.view_component.preview_paths,
|
206
|
-
@view_path
|
207
|
-
].flatten.compact.uniq
|
208
|
-
end
|
209
|
-
|
210
|
-
def view_path_glob
|
211
|
-
return view_paths.first if view_paths.size == 1
|
212
|
-
|
213
|
-
"{#{view_paths.join(",")}}"
|
214
|
-
end
|
215
|
-
|
216
|
-
def normalized_slot_name(slot_name, slot)
|
217
|
-
slot[:collection] ? ActiveSupport::Inflector.singularize(slot_name) : slot_name.to_s
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|