Created
August 15, 2025 17:31
-
-
Save jameskerr/b461a87a8cf76eabb3730295f039b05c to your computer and use it in GitHub Desktop.
View Component Generator Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Check for -d flag | |
| if ARGV[0] == "-d" | |
| name = ARGV[1] | |
| delete_mode = true | |
| else | |
| name = ARGV[0] | |
| delete_mode = false | |
| end | |
| if name.nil? || name.empty? | |
| puts "Error: Please provide a component name" | |
| exit 1 | |
| end | |
| if delete_mode | |
| # Delete mode | |
| File.delete("app/components/#{name}.css") if File.exist?("app/components/#{name}.css") | |
| puts "Removed: app/components/#{name}.css" | |
| File.delete("app/components/#{name}.rb") if File.exist?("app/components/#{name}.rb") | |
| puts "Removed: app/components/#{name}.rb" | |
| File.delete("app/components/#{name}.html.erb") if File.exist?("app/components/#{name}.html.erb") | |
| puts "Removed: app/components/#{name}.html.erb" | |
| puts "Removed component files for: #{name}" | |
| else | |
| # Create mode | |
| require 'fileutils' | |
| FileUtils.mkdir_p("app/components") | |
| css_class = name.tr('_', '-') | |
| File.write("app/components/#{name}.css", ".#{css_class} {\n}\n") | |
| puts "Created: app/components/#{name}.css" | |
| File.write("app/components/#{name}.html.erb", "<div class=\"#{css_class}\"></div>\n") | |
| puts "Created: app/components/#{name}.html.erb" | |
| class_name = name.split('_').map(&:capitalize).join | |
| File.write("app/components/#{name}.rb", "class #{class_name} < UI\nend\n") | |
| puts "Created: app/components/#{name}.rb" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment