dumpling.rb
· 2.3 KiB · Ruby
Raw
# Rails Application Template
# Apply all uncommitted changes
# Download custom .rubocop.yml from URL
get 'https://gist.gyozaguy.dev/GyozaGuy/cdd6fa0cc913430d8951de685f840e6a/raw/HEAD/.rubocop.yml', '.rubocop.yml'
# Remove omakase rubocop gem and add standard rubocop
gsub_file 'Gemfile', /^\s+# Omakase Ruby styling.*\n\s+gem ['"]rubocop-rails-omakase['"], require: false\n/m, ''
insert_into_file 'Gemfile', " gem 'rubocop'\n", after: "group :development do\n"
# Define custom git source shorthand :gg
# This allows gems to be specified with `gem 'name', gg: 'repo'` syntax
insert_into_file 'Gemfile',
"\ngit_source(:gg) { |repo| \"https://git.gyozaguy.com/\#{repo}.git\" }\n",
after: 'source "https://rubygems.org"'
# Add dumpling gem using the custom :gg git source shorthand
# This will fetch the gem from https://git.gyozaguy.com/GyozaGuy/dumpling.git
gem 'dumpling', gg: 'GyozaGuy/dumpling'
# Create application_layout.rb
file 'app/views/layouts/application_layout.rb', <<~RUBY
class Layouts::ApplicationLayout < Components::Layout
def view_template(&)
doctype
html(**locale_props, **theme_props) {
head {
title { "\#{content_for(:page_title) || 'Loading...'} :: Replace Me" }
default_meta
link(href: '/icon.png', rel: 'icon', type: 'image/png')
link(href: '/icon.svg', rel: 'icon', type: 'image/svg+xml')
link(href: '/icon.png', rel: 'apple-touch-icon')
default_stylesheets
default_javascript
}
body(id: page_id) {
main(&)
}
}
end
end
RUBY
# Modify application_controller.rb
gsub_file 'app/controllers/application_controller.rb',
'class ApplicationController < ActionController::Base',
'class ApplicationController < Dumpling::ApplicationController'
# Run RuboCop auto-correct to standardize quotes and other style issues
after_bundle do
say 'Running RuboCop auto-correct to standardize quotes and other style issues...'
run 'bundle exec rubocop -a'
say 'RuboCop auto-correction completed!'
end
# Remove default application.html.erb layout as we're using application_layout.rb instead
remove_file 'app/views/layouts/application.html.erb'
puts 'Template applied successfully!'
puts 'Remember to run bundle install to update your gems'
| 1 | # Rails Application Template |
| 2 | # Apply all uncommitted changes |
| 3 | |
| 4 | # Download custom .rubocop.yml from URL |
| 5 | get 'https://gist.gyozaguy.dev/GyozaGuy/cdd6fa0cc913430d8951de685f840e6a/raw/HEAD/.rubocop.yml', '.rubocop.yml' |
| 6 | |
| 7 | # Remove omakase rubocop gem and add standard rubocop |
| 8 | gsub_file 'Gemfile', /^\s+# Omakase Ruby styling.*\n\s+gem ['"]rubocop-rails-omakase['"], require: false\n/m, '' |
| 9 | insert_into_file 'Gemfile', " gem 'rubocop'\n", after: "group :development do\n" |
| 10 | |
| 11 | # Define custom git source shorthand :gg |
| 12 | # This allows gems to be specified with `gem 'name', gg: 'repo'` syntax |
| 13 | insert_into_file 'Gemfile', |
| 14 | "\ngit_source(:gg) { |repo| \"https://git.gyozaguy.com/\#{repo}.git\" }\n", |
| 15 | after: 'source "https://rubygems.org"' |
| 16 | |
| 17 | # Add dumpling gem using the custom :gg git source shorthand |
| 18 | # This will fetch the gem from https://git.gyozaguy.com/GyozaGuy/dumpling.git |
| 19 | gem 'dumpling', gg: 'GyozaGuy/dumpling' |
| 20 | |
| 21 | # Create application_layout.rb |
| 22 | file 'app/views/layouts/application_layout.rb', <<~RUBY |
| 23 | class Layouts::ApplicationLayout < Components::Layout |
| 24 | def view_template(&) |
| 25 | doctype |
| 26 | |
| 27 | html(**locale_props, **theme_props) { |
| 28 | head { |
| 29 | title { "\#{content_for(:page_title) || 'Loading...'} :: Replace Me" } |
| 30 | default_meta |
| 31 | link(href: '/icon.png', rel: 'icon', type: 'image/png') |
| 32 | link(href: '/icon.svg', rel: 'icon', type: 'image/svg+xml') |
| 33 | link(href: '/icon.png', rel: 'apple-touch-icon') |
| 34 | default_stylesheets |
| 35 | default_javascript |
| 36 | } |
| 37 | |
| 38 | body(id: page_id) { |
| 39 | main(&) |
| 40 | } |
| 41 | } |
| 42 | end |
| 43 | end |
| 44 | RUBY |
| 45 | |
| 46 | # Modify application_controller.rb |
| 47 | gsub_file 'app/controllers/application_controller.rb', |
| 48 | 'class ApplicationController < ActionController::Base', |
| 49 | 'class ApplicationController < Dumpling::ApplicationController' |
| 50 | |
| 51 | # Run RuboCop auto-correct to standardize quotes and other style issues |
| 52 | after_bundle do |
| 53 | say 'Running RuboCop auto-correct to standardize quotes and other style issues...' |
| 54 | run 'bundle exec rubocop -a' |
| 55 | say 'RuboCop auto-correction completed!' |
| 56 | end |
| 57 | |
| 58 | # Remove default application.html.erb layout as we're using application_layout.rb instead |
| 59 | remove_file 'app/views/layouts/application.html.erb' |
| 60 | |
| 61 | puts 'Template applied successfully!' |
| 62 | puts 'Remember to run bundle install to update your gems' |