diff --git a/lib/generators/tailwindcss/sessions/sessions_generator.rb b/lib/generators/tailwindcss/sessions/sessions_generator.rb new file mode 100644 index 00000000..cc97b34d --- /dev/null +++ b/lib/generators/tailwindcss/sessions/sessions_generator.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Tailwindcss + module Generators + class SessionsGenerator < Erb::Generators::ScaffoldGenerator + include Rails::Generators::ResourceHelpers + + source_root File.expand_path("templates", __dir__) + + def create_session_files + puts "😀 Logging from TailwindCSS forked gem" + template "models/session.rb", File.join("app/models/session.rb") + template "models/user.rb", File.join("app/models/user.rb") + template "models/current.rb", File.join("app/models/current.rb") + + template "controllers/sessions_controller.rb", File.join("app/controllers/sessions_controller.rb") + template "controllers/concerns/authentication.rb", File.join("app/controllers/concerns/authentication.rb") + + template "views/sessions/new.html.erb", File.join("app/views/sessions/new.html.erb") + end + + def configure_application + gsub_file "app/controllers/application_controller.rb", /(class ApplicationController < ActionController::Base)/, "\\1\n include Authentication" + route "resource :session" + end + + def enable_bcrypt + if File.read("Gemfile").include?('gem "bcrypt"') + uncomment_lines "Gemfile", /gem "bcrypt"/ + Bundler.with_original_env { execute_command :bundle, "" } + else + Bundler.with_original_env { execute_command :bundle, "add bcrypt" } + end + end + + def add_migrations + generate "migration CreateUsers email_address:string!:uniq password_digest:string! --force" + generate "migration CreateSessions user:references token:token ip_address:string user_agent:string --force" + end + end + end +end diff --git a/lib/generators/tailwindcss/sessions/templates/new.html.erb.tt b/lib/generators/tailwindcss/sessions/templates/new.html.erb.tt new file mode 100644 index 00000000..3acc3d7b --- /dev/null +++ b/lib/generators/tailwindcss/sessions/templates/new.html.erb.tt @@ -0,0 +1,19 @@ +