Last active
June 5, 2025 22:05
-
-
Save jeffersonsc/39ad34eac7aa08dd5bf7599ef7d38273 to your computer and use it in GitHub Desktop.
Rails Jeff 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
| # rails_hot_template.rb | |
| # USO: rails new NOME_PROJETO -d postgresql --css=bootstrap -m https://gist.githubusercontent.com/jeffersonsc/39ad34eac7aa08dd5bf7599ef7d38273/raw/ea8357357358b5a1c028943838d657b50da87f9e/rails_hot_template.rb | |
| def apply_template! | |
| # -------------------------------------------- | |
| # 1. CONFIGURAÇÃO INICIAL | |
| # -------------------------------------------- | |
| run "echo '--> Iniciando template MVP simplificado'" | |
| remove_file "README.md" | |
| run "rm -rf test" if Dir.exist?("test") | |
| # -------------------------------------------- | |
| # 2. GEMS ESSENCIAIS (COMPATÍVEIS COM RAILS 8) | |
| # -------------------------------------------- | |
| run "echo '--> Adicionando gems atualizadas para Rails 8'" | |
| gem 'bootstrap', '~> 5.3' | |
| gem 'sass-rails', github: 'rails/sass-rails' | |
| gem 'devise', github: 'heartcombo/devise' | |
| gem 'pundit' | |
| gem 'simple_form' | |
| # -------------------------------------------- | |
| # 3. INSTALAÇÃO | |
| # -------------------------------------------- | |
| run "bundle install" | |
| # -------------------------------------------- | |
| # 4. ACTIVE STORAGE (UPLOAD DE IMAGENS) | |
| # -------------------------------------------- | |
| run "echo '--> Configurando Active Storage'" | |
| run "mkdir -p app/assets/config && echo '//= link_tree ../images\n//= link_directory ../javascripts .js\n//= link_directory ../stylesheets .css' > app/assets/config/manifest.js" | |
| rails_command "active_storage:install" | |
| rails_command "db:migrate" | |
| # -------------------------------------------- | |
| # 5. CONFIGURAÇÃO FRONTEND | |
| # -------------------------------------------- | |
| run "echo '--> Configurando Bootstrap via importmap'" | |
| run "bin/importmap pin bootstrap" | |
| run "echo \"import 'bootstrap';\" > app/javascript/bootstrap.js" | |
| remove_file "app/assets/stylesheets/application.css" | |
| file "app/assets/stylesheets/application.scss", <<-SCSS | |
| @import "bootstrap/scss/bootstrap"; | |
| SCSS | |
| rails_command "stimulus:install" | |
| generate "simple_form:install --bootstrap" | |
| # -------------------------------------------- | |
| # 6. ESTRUTURA DE LAYOUT PRONTA | |
| # -------------------------------------------- | |
| run "echo '--> Criando estrutura de layout padrão'" | |
| file "app/views/layouts/application.html.erb", <<-ERB | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>EscolaPro</title> | |
| <meta name="viewport" content="width=device-width,initial-scale=1"> | |
| <%= csrf_meta_tags %> | |
| <%= csp_meta_tag %> | |
| <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> | |
| <%= javascript_importmap_tags %> | |
| </head> | |
| <body> | |
| <% if user_signed_in? %> | |
| <%= render "layouts/sidebar" %> | |
| <div class="main-content" style="margin-left: 250px;"> | |
| <%= render "layouts/header" %> | |
| <main class="container-fluid mt-4"> | |
| <%= yield %> | |
| </main> | |
| </div> | |
| <% else %> | |
| <div class="container mt-5"> | |
| <%= yield %> | |
| </div> | |
| <% end %> | |
| </body> | |
| </html> | |
| ERB | |
| file "app/views/layouts/_sidebar.html.erb", <<-ERB | |
| <div class="sidebar bg-dark text-white p-3 d-none d-md-block" style="width: 250px; height: 100vh; position: fixed;"> | |
| <div class="d-flex flex-column h-100"> | |
| <div class="mb-4"> | |
| <h4>EscolaPro</h4> | |
| </div> | |
| <ul class="nav flex-column flex-grow-1"> | |
| <li class="nav-item"> | |
| <%= link_to "Dashboard", dashboard_path, class: "nav-link text-white" %> | |
| </li> | |
| <li class="nav-item"> | |
| <%= link_to "Alunos", students_path, class: "nav-link text-white" %> | |
| </li> | |
| </ul> | |
| <div class="mt-auto"> | |
| <%= button_to "Sair", destroy_user_session_path, method: :delete, class: "btn btn-danger w-100" %> | |
| </div> | |
| </div> | |
| </div> | |
| ERB | |
| file "app/views/layouts/_header.html.erb", <<-ERB | |
| <header class="navbar navbar-light bg-light border-bottom p-3" style="margin-left: 250px;"> | |
| <div class="container-fluid"> | |
| <div></div> | |
| <div> | |
| <span class="me-3"><%= current_user.name %></span> | |
| <%= image_tag "https://via.placeholder.com/40", class: "rounded-circle", alt: "User" %> | |
| </div> | |
| </div> | |
| </header> | |
| ERB | |
| # -------------------------------------------- | |
| # 7. AUTENTICAÇÃO (DEVISE) | |
| # -------------------------------------------- | |
| run "echo '--> Configurando Devise para Rails 8'" | |
| generate "devise:install" | |
| generate "devise User name:string" | |
| # Roda migration adicional para avatar no User | |
| run "rails db:migrate" | |
| # -------------------------------------------- | |
| # 8. POLICY (PUNDIT) | |
| # -------------------------------------------- | |
| run "echo '--> Configurando Pundit com policy base'" | |
| generate "pundit:install" | |
| file "app/policies/student_policy.rb", <<-RUBY | |
| class StudentPolicy < ApplicationPolicy | |
| def index? | |
| user.present? | |
| end | |
| def show? | |
| user.present? | |
| end | |
| def create? | |
| user.present? | |
| end | |
| def update? | |
| user.present? && (record.user == user || user.admin?) | |
| end | |
| def destroy? | |
| update? | |
| end | |
| end | |
| RUBY | |
| file "app/policies/application_policy.rb", <<-RUBY | |
| class ApplicationPolicy | |
| attr_reader :user, :record | |
| def initialize(user, record) | |
| @user = user | |
| @record = record | |
| end | |
| def index? | |
| false | |
| end | |
| def show? | |
| false | |
| end | |
| def create? | |
| false | |
| end | |
| def update? | |
| false | |
| end | |
| def destroy? | |
| false | |
| end | |
| class Scope | |
| attr_reader :user, :scope | |
| def initialize(user, scope) | |
| @user = user | |
| @scope = scope | |
| end | |
| def resolve | |
| scope.all | |
| end | |
| end | |
| end | |
| RUBY | |
| # -------------------------------------------- | |
| # 9. MODELO ALUNO (EXEMPLO PRONTO) | |
| # -------------------------------------------- | |
| run "echo '--> Criando modelo Aluno'" | |
| generate :model, "Student name:string parent_name:string birth_date:date phone:string avatar:image user:references" | |
| run "rails db:migrate" | |
| # -------------------------------------------- | |
| # 10. CONTROLLER DASHBOARD | |
| # -------------------------------------------- | |
| generate :controller, "Dashboard index" | |
| route "root to: 'dashboard#index'" | |
| # -------------------------------------------- | |
| # 11. CONFIGURAÇÕES FINAIS | |
| # -------------------------------------------- | |
| git :init | |
| git add: "." | |
| git commit: "-m 'Initial commit: MVP EscolaPro'" | |
| # -------------------------------------------- | |
| # MENSAGEM FINAL | |
| # -------------------------------------------- | |
| puts "\n✅ MVP PRONTO PARA USO NO RAILS 8!".green | |
| puts "\nPróximos passos:".yellow | |
| puts "1. Inicie o servidor:".blue + " rails s" | |
| puts "2. Acesse:".blue + " http://localhost:3000/users/sign_up" | |
| puts "3. Gere scaffolds:".blue + " rails g scaffold Payment value:decimal student:references" | |
| end | |
| apply_template! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment