|
| 1 | +module Components |
| 2 | + module ComponentSetup |
| 3 | + class ManualSteps < Components::Base |
| 4 | + def initialize(component_name:) |
| 5 | + @component_name = component_name |
| 6 | + @dependencies = RubyUI::FileManager.dependencies(@component_name) |
| 7 | + end |
| 8 | + |
| 9 | + private |
| 10 | + |
| 11 | + attr_reader :component_name, :dependencies |
| 12 | + |
| 13 | + def view_template |
| 14 | + div(class: "max-w-2xl mx-auto w-full py-10 space-y-6") do |
| 15 | + Heading(level: 4, class: "pb-4 border-b") { "Manual installation" } |
| 16 | + |
| 17 | + render Steps::Builder.new do |steps| |
| 18 | + main_component_step(steps) |
| 19 | + related_component_steps(steps) |
| 20 | + stimulus_controller_steps(steps) |
| 21 | + js_dependencies_steps(steps) |
| 22 | + ruby_dependencies_steps(steps) |
| 23 | + component_dependencies_steps(steps) |
| 24 | + end |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + def main_component_step(steps) |
| 29 | + main_component_code = RubyUI::FileManager.main_component_code(component_name) |
| 30 | + |
| 31 | + return if main_component_code.blank? |
| 32 | + |
| 33 | + steps.add_step do |
| 34 | + render Steps::Container do |
| 35 | + Text(size: "4", weight: "semibold") do |
| 36 | + plain "Add " |
| 37 | + InlineCode(class: "whitespace-nowrap") { "RubyUI::#{component_name.camelcase}" } |
| 38 | + plain " to " |
| 39 | + InlineCode(class: "whitespace-nowrap") { "app/components/ruby_ui/#{component_name.underscore}.rb" } |
| 40 | + end |
| 41 | + |
| 42 | + div(class: "w-full") do |
| 43 | + Codeblock(main_component_code, syntax: :ruby) |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + def related_component_steps(steps) |
| 50 | + related_component_file_paths = RubyUI::FileManager.related_component_file_paths(component_name) |
| 51 | + |
| 52 | + return if related_component_file_paths.empty? |
| 53 | + |
| 54 | + related_component_file_paths.each do |component_path| |
| 55 | + related_component_class = component_path.split("/").last.delete_suffix(".rb").camelcase |
| 56 | + related_component_file_name = component_path.split("/").last |
| 57 | + related_component_code = RubyUI::FileManager.component_code(component_path) |
| 58 | + steps.add_step do |
| 59 | + render Steps::Container do |
| 60 | + Text(size: "4", weight: "semibold") do |
| 61 | + plain "Add " |
| 62 | + InlineCode(class: "whitespace-nowrap") { "RubyUI::#{related_component_class}" } |
| 63 | + plain " to " |
| 64 | + InlineCode(class: "whitespace-nowrap") { "app/components/ruby_ui/#{component_name.underscore}/#{related_component_file_name}" } |
| 65 | + end |
| 66 | + |
| 67 | + div(class: "w-full") do |
| 68 | + Codeblock(related_component_code, syntax: :ruby) |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + def stimulus_controller_steps(steps) |
| 76 | + stimulus_controller_file_paths = RubyUI::FileManager.stimulus_controller_file_paths(component_name) |
| 77 | + |
| 78 | + return if stimulus_controller_file_paths.empty? |
| 79 | + |
| 80 | + stimulus_controller_file_paths.each do |controller_path| |
| 81 | + controller_file_name = controller_path.split("/").last |
| 82 | + controller_code = RubyUI::FileManager.component_code(controller_path) |
| 83 | + steps.add_step do |
| 84 | + render Steps::Container do |
| 85 | + Text(size: "4", weight: "semibold") do |
| 86 | + plain "Add " |
| 87 | + InlineCode(class: "whitespace-nowrap") { controller_file_name } |
| 88 | + plain " to " |
| 89 | + InlineCode(class: "whitespace-nowrap") { "app/javascript/controllers/ruby_ui/#{controller_file_name}" } |
| 90 | + end |
| 91 | + |
| 92 | + div(class: "w-full") do |
| 93 | + Codeblock(controller_code, syntax: :javascript) |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + steps.add_step do |
| 100 | + render Steps::Container do |
| 101 | + Text(size: "4", weight: "semibold") do |
| 102 | + plain "Update the Stimulus controllers manifest file" |
| 103 | + end |
| 104 | + |
| 105 | + Alert(variant: :destructive) do |
| 106 | + AlertTitle { "Importmap!" } |
| 107 | + AlertDescription { "You don't need to run this command if you are using Importmap" } |
| 108 | + end |
| 109 | + |
| 110 | + div(class: "w-full") do |
| 111 | + Codeblock("rake stimulus:manifest:update", syntax: :javascript) |
| 112 | + end |
| 113 | + end |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + def js_dependencies_steps(steps) |
| 118 | + return unless dependencies["js_packages"].present? |
| 119 | + |
| 120 | + dependencies["js_packages"].each do |js_package| |
| 121 | + steps.add_step do |
| 122 | + code = <<~CODE |
| 123 | + // with yarn |
| 124 | + yarn add #{js_package} |
| 125 | + // with npm |
| 126 | + npm install #{js_package} |
| 127 | + // with importmaps |
| 128 | + #{pin_importmap_instructions(js_package)} |
| 129 | + CODE |
| 130 | + |
| 131 | + render Steps::Container do |
| 132 | + Text(size: "4", weight: "semibold") do |
| 133 | + plain "Install " |
| 134 | + InlineCode(class: "whitespace-nowrap") { js_package } |
| 135 | + plain " Javascript dependency" |
| 136 | + end |
| 137 | + |
| 138 | + div(class: "w-full") do |
| 139 | + Codeblock(code, syntax: :javascript) |
| 140 | + end |
| 141 | + end |
| 142 | + end |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + def ruby_dependencies_steps(steps) |
| 147 | + return unless dependencies["gems"].present? |
| 148 | + |
| 149 | + dependencies["gems"].each do |gem| |
| 150 | + steps.add_step do |
| 151 | + code = <<~CODE |
| 152 | + bundle add #{gem} |
| 153 | + CODE |
| 154 | + |
| 155 | + render Steps::Container do |
| 156 | + Text(size: "4", weight: "semibold") do |
| 157 | + plain "Install " |
| 158 | + InlineCode(class: "whitespace-nowrap") { gem } |
| 159 | + plain " Ruby gem" |
| 160 | + end |
| 161 | + |
| 162 | + div(class: "w-full") do |
| 163 | + Codeblock(code, syntax: :javascript) |
| 164 | + end |
| 165 | + end |
| 166 | + end |
| 167 | + end |
| 168 | + end |
| 169 | + |
| 170 | + def component_dependencies_steps(steps) |
| 171 | + return unless dependencies["components"].present? |
| 172 | + |
| 173 | + steps.add_step do |
| 174 | + render Steps::Container do |
| 175 | + Text(size: "4", weight: "semibold") do |
| 176 | + plain "Install required components" |
| 177 | + end |
| 178 | + |
| 179 | + Text do |
| 180 | + plain "Component " |
| 181 | + InlineCode(class: "whitespace-nowrap") { component_name.camelcase } |
| 182 | + plain " relies on the following RubyUI components. Refer to their individual installation guides for setup instructions:" |
| 183 | + end |
| 184 | + |
| 185 | + TypographyList do |
| 186 | + dependencies["components"].each do |component| |
| 187 | + TypographyListItem do |
| 188 | + Link(size: :lg, target: "_blank", href: public_send(:"docs_#{component.underscore}_path")) do |
| 189 | + span(class: "font-bold") { component.camelcase } |
| 190 | + span { " - Installation guide" } |
| 191 | + end |
| 192 | + end |
| 193 | + end |
| 194 | + end |
| 195 | + end |
| 196 | + end |
| 197 | + end |
| 198 | + |
| 199 | + # Temporary solution while we don't remove |
| 200 | + # motion adn tippy.js dependencies |
| 201 | + def pin_importmap_instructions(js_package) |
| 202 | + case js_package |
| 203 | + when "motion" |
| 204 | + <<~CODE |
| 205 | + // Add to your config/importmap.rb |
| 206 | + pin "motion", to: "https://cdn.jsdelivr.net/npm/[email protected]/+esm" |
| 207 | + CODE |
| 208 | + when "tippy.js" |
| 209 | + <<~CODE |
| 210 | + // Add to your config/importmap.rb |
| 211 | + pin "tippy.js", to: "https://cdn.jsdelivr.net/npm/[email protected]/+esm" |
| 212 | + pin "@popperjs/core", to: "https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/+esm"\n |
| 213 | + CODE |
| 214 | + else |
| 215 | + "bin/importmap pin #{js_package}" |
| 216 | + end |
| 217 | + end |
| 218 | + end |
| 219 | + end |
| 220 | +end |
0 commit comments