Adds Rails View Components for Bootstrap
Used 5 times
A
Alemaño
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/VZgs4q"
Template Source
Review the code before running this template on your machine.
def gem_installed?(name)
Gem::Specification.find_by_name(name)
true
rescue Gem::LoadError
false
end
unless gem_installed?("view_component")
if yes?("Do you want to install ViewComponent gem?[y/n]")
run "bundle add view_component"
end
end
after_bundle do
puts "Installing RailsbootUI components..."
zip_url = "https://railsbootui.com/templates/free"
zip_file = "railsbootui.zip"
destination_folder = "tmp/railsbootui"
require "open-uri"
File.open(zip_file, "wb") do |file|
file << URI.parse(zip_url).open.read
end
require "zip"
Zip::File.open(zip_file) do |zip_file|
zip_file.each do |entry|
file_path = File.join(destination_folder, entry.name)
FileUtils.mkdir_p(File.dirname(file_path))
entry.extract(file_path) { true }
end
end
def move_railsboot_folder(destination_folder, source_path, target_path, parent_dir)
extracted_path = File.join(destination_folder, source_path)
target_path_full = target_path
FileUtils.mkdir_p parent_dir unless Dir.exist?(parent_dir)
if Dir.exist?(extracted_path)
FileUtils.mv(extracted_path, target_path_full)
puts "Railsboot folder has been moved to #{target_path_full}."
else
puts "Railsboot folder not found in the extracted contents under #{source_path}."
end
end
if yes?("Do you want to copy RailsbootUI free components?[y/n]")
move_railsboot_folder(destination_folder, "app/components/railsboot", "app/components/railsboot", "app/components")
end
if yes?("Do you want to copy RailsbootUI free tests?[y/n]")
move_railsboot_folder(destination_folder, "test/components/railsboot", "test/components/railsboot", "test/components")
end
FileUtils.rm_rf(destination_folder)
File.delete(zip_file)
end