Stonerun - Tabler ready Rails template

https://github.com/nhcasanova/stonerun

Stonerun is an opinionated Rails template that includes all the basics to start a new project using Tabler as the frontend library.

Other than that it comes with Devise authentication including styled views for sign in and sign up along with pre-configured fields for lastname, names and avatar as an example for future customization of the User model.

720 1


nelson
nelson

Jan 19, 2022

Copy and paste this code into your terminal

DISCLAIMER: You should always review templates before running them. By running the template, you are agreeing to the terms of use.

The contents of this script as show. Any updates will be reflected in the below code and the snippet.

require 'uri'
require 'net/http'

REPO = 'https://raw.githubusercontent.com/nhcasanova/stonerun'.freeze

def go_bundle
Bundler.with_unbundled_env { run 'bundle install' }
end

gem 'devise'
gem 'aws-sdk-s3'
gem 'image_processing', '~> 1.2'
gem 'figaro'

gem_group :development, :test do
gem 'pry-rails'
gem 'better_errors'
gem 'binding_of_caller'
end

go_bundle

webpack_rails = File.directory?('config/webpack')

if webpack_rails
run 'yarn add @tabler/core'
inject_into_file "app/javascript/packs/application.js" do <<~EOF
 import tabler from "@tabler/core"
 require("@tabler/core/dist/css/tabler.css")
 EOF
end

inject_into_file "app/views/layouts/application.html.erb", before: "</head>" do <<~EOF
 <%= stylesheet_pack_tag "application", media: "all", "data-turbolinks-track": "reload" %>
 EOF
end
end

rails_command 'db:create'
rails_command 'generate controller dashboard index'
route "root to: 'dashboard#index'"

rails_command 'generate devise:install'
rails_command 'generate devise:views'
rails_command 'generate devise user first_name last_name'
rails_command 'generate devise:controllers users -c=registrations'
inject_into_file 'app/controllers/users/registrations_controller.rb', "layout 'layouts/application', only: [:edit]\n", after: "class Users::RegistrationsController < Devise::RegistrationsController\n"
gsub_file 'config/routes.rb', 'devise_for :users', "devise_for :users, controllers: { registrations: 'users/registrations' }"

rails_command 'db:migrate'

extra_devise_cols = <<~RUBY
 before_action :configure_permitted_parameters, if: :devise_controller?

 protected
 def configure_permitted_parameters
 sign_up_attrs = [:first_name, :last_name]
 update_attrs = [:first_name, :last_name, :avatar]
 devise_parameter_sanitizer.permit(:sign_up, keys: sign_up_attrs)
 devise_parameter_sanitizer.permit(:account_update, keys: update_attrs)
 end
RUBY

inject_into_file 'app/controllers/application_controller.rb', extra_devise_cols, after: "class ApplicationController < ActionController::Base\n"
inject_into_file 'app/controllers/dashboard_controller.rb', "before_action :authenticate_user!\n", after: "class DashboardController < ApplicationController\n"
inject_into_file 'app/models/user.rb', "has_one_attached :avatar\n", before: 'end'

run 'rm app/views/layouts/application.html.erb'
run 'rm app/views/devise/sessions/new.html.erb'
run 'rm app/views/devise/registrations/new.html.erb'
run 'rm app/views/devise/registrations/edit.html.erb'

layouts = %w[application devise _avatar _footer _header _title]

layouts.each do |layout|
create_file "app/views/layouts/#{layout}.html.erb" do
Net::HTTP.get(URI("#{REPO}/main/views/layouts/#{layout}.html.erb"))
end
end

create_file 'app/views/devise/sessions/new.html.erb' do
Net::HTTP.get(URI("#{REPO}/main/views/devise/sessions/new.html.erb"))
end

create_file 'app/views/devise/registrations/new.html.erb' do
Net::HTTP.get(URI("#{REPO}/main/views/devise/registrations/new.html.erb"))
end

create_file 'app/views/devise/registrations/edit.html.erb' do
Net::HTTP.get(URI("#{REPO}/main/views/devise/registrations/edit.html.erb"))
end

inject_into_file 'app/views/dashboard/index.html.erb' do <<~EOF
 <% provide(:pretitle, 'Index') %>
 <% provide(:title, 'Dashboard') %>
EOF
end

run 'rails action_text:install'
run 'rails active_storage:install'
run 'bundle exec figaro install'

rails_command 'db:migrate'

gsub_file 'config/environments/production.rb', 'config.active_storage.service = :local', 'config.active_storage.service = :amazon'

A place where you can thank the author, post problems, give constructive feedback, etc. Be nice!