Last active
May 18, 2025 05:27
-
-
Save RillonDodgers/7aa5e1807e79dd5f861e85940cd0529b to your computer and use it in GitHub Desktop.
rails 8 template
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
require "fileutils" | |
require "shellwords" | |
def add_gems | |
add_gem "devise" | |
add_gem "omniauth-google-oauth2" | |
add_gem "omniauth-microsoft_graph" | |
end | |
def rails_version | |
@rails_version ||= Gem::Version.new(Rails::VERSION::STRING) | |
end | |
def ensure_rails8_or_newer! | |
return if Gem::Requirement.new(">= 8.0.0.alpha").satisfied_by?(rails_version) | |
say "\n DaisyUI template requires Rails 8 or newer. You are using #{rails_version}.", :red | |
exit 1 | |
end | |
def add_daisyui | |
say " Installing Tailwind CSS (via cssbundling-rails)...", :green | |
rails_command "css:install:tailwind" | |
say " Downloading DaisyUI plugin files...", :green | |
run "mkdir -p app/assets/tailwind" | |
run %(curl -sLo app/assets/tailwind/daisyui.js https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js) | |
run %(curl -sLo app/assets/tailwind/daisyui-theme.js https://github.com/saadeghi/daisyui/releases/latest/download/daisyui-theme.js) | |
say " Configuring your Tailwind entrypoint...", :green | |
remove_file "app/assets/stylesheets/application.tailwind.css" | |
create_file "app/assets/stylesheets/application.tailwind.css", <<~CSS | |
@import "tailwindcss/base"; | |
@import "tailwindcss/components"; | |
@import "tailwindcss/utilities"; | |
@source "../../../public/*.html"; | |
@source "../../../app/helpers/**/*.rb"; | |
@source "../../../app/javascript/**/*.js"; | |
@source "../../../app/views/**/*"; | |
/* DaisyUI plugin loader */ | |
@plugin "./daisyui.js"; | |
CSS | |
say " Building initial Tailwind + DaisyUI styles...", :green | |
run "bin/rails tailwindcss:build" | |
end | |
def add_devise | |
say "Setting up Devise...", :green | |
generate "devise:install" | |
generate "devise User" # Or your preferred model name | |
rails_command "db:migrate" | |
end | |
def add_omniauth_providers | |
say "Configuring Omniauth...", :green | |
inject_into_file "config/initializers/devise.rb", after: "Devise.setup do |config|\n" do | |
<<-RUBY | |
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"] | |
config.omniauth :microsoft_graph, ENV["MICROSOFT_GRAPH_CLIENT_ID"], ENV["MICROSOFT_GRAPH_CLIENT_SECRET"], scope: "user.read" | |
RUBY | |
end | |
end | |
def configure_generators | |
say "Configuring generators for UUID primary keys...", :green | |
inject_into_file "config/application.rb", after: "class Application < Rails::Application\n" do | |
<<-RUBY | |
config.load_defaults Rails::VERSION::STRING.to_f | |
# Make the default PK type = uuid | |
config.generators do |g| | |
g.orm :active_record, primary_key_type: :uuid | |
end | |
RUBY | |
end | |
end | |
def add_gem(name, *options) | |
gem(name, *options) unless gem_exists?(name) | |
end | |
def gem_exists?(name) | |
IO.read("Gemfile") =~ /^\s*gem ['"]#{name}['"]/ | |
end | |
ensure_rails8_or_newer! | |
add_gems | |
configure_generators | |
after_bundle do | |
add_daisyui | |
add_devise | |
add_omniauth_providers | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment