dumpling.rb
· 2.2 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',
"\n\nsource 'https://git.gyozaguy.com/api/packages/GyozaGuy/rubygems' do\n\tgem 'dumpling', '~> 1.0'\nend"
# 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 | "\n\nsource 'https://git.gyozaguy.com/api/packages/GyozaGuy/rubygems' do\n\tgem 'dumpling', '~> 1.0'\nend" |
| 15 | |
| 16 | # Add dumpling gem using the custom :gg git source shorthand |
| 17 | # This will fetch the gem from https://git.gyozaguy.com/GyozaGuy/dumpling.git |
| 18 | gem 'dumpling', gg: 'GyozaGuy/dumpling' |
| 19 | |
| 20 | # Create application_layout.rb |
| 21 | file 'app/views/layouts/application_layout.rb', <<~RUBY |
| 22 | class Layouts::ApplicationLayout < Components::Layout |
| 23 | def view_template(&) |
| 24 | doctype |
| 25 | |
| 26 | html(**locale_props, **theme_props) { |
| 27 | head { |
| 28 | title { "\#{content_for(:page_title) || 'Loading...'} :: Replace Me" } |
| 29 | default_meta |
| 30 | link(href: '/icon.png', rel: 'icon', type: 'image/png') |
| 31 | link(href: '/icon.svg', rel: 'icon', type: 'image/svg+xml') |
| 32 | link(href: '/icon.png', rel: 'apple-touch-icon') |
| 33 | default_stylesheets |
| 34 | default_javascript |
| 35 | } |
| 36 | |
| 37 | body(id: page_id) { |
| 38 | main(&) |
| 39 | } |
| 40 | } |
| 41 | end |
| 42 | end |
| 43 | RUBY |
| 44 | |
| 45 | # Modify application_controller.rb |
| 46 | gsub_file 'app/controllers/application_controller.rb', |
| 47 | 'class ApplicationController < ActionController::Base', |
| 48 | 'class ApplicationController < Dumpling::ApplicationController' |
| 49 | |
| 50 | # Run RuboCop auto-correct to standardize quotes and other style issues |
| 51 | after_bundle do |
| 52 | say 'Running RuboCop auto-correct to standardize quotes and other style issues...' |
| 53 | run 'bundle exec rubocop -a' |
| 54 | say 'RuboCop auto-correction completed!' |
| 55 | end |
| 56 | |
| 57 | # Remove default application.html.erb layout as we're using application_layout.rb instead |
| 58 | remove_file 'app/views/layouts/application.html.erb' |
| 59 | |
| 60 | puts 'Template applied successfully!' |
| 61 | puts 'Remember to run bundle install to update your gems' |