Skip to content

Instantly share code, notes, and snippets.

@olimart
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimart/11299909 to your computer and use it in GitHub Desktop.
Save olimart/11299909 to your computer and use it in GitHub Desktop.
RoR app generator
# rails new generator -d postgresql -m /path/to/app_template.rb
# FILES
# ------------------------------------------------------------------------------------------------------
remove_file 'README.rdoc'
create_file 'README.md', "# Readme
## Getting started
1. Clone and rename database.sample.yml
2. Clone and rename application.sample.yml
2. Run rake bs
3. Start server"
rakefile "sample_data.rake" do
"namespace :db do
desc 'Load sample data from db/sample_data.rb'
task sample_data: :environment do
seed_file = File.join(Rails.root, 'db', 'sample_data.rb')
load(seed_file) if File.exist?(seed_file)
end
desc 'Drop, create, migrate, seed and sample_data'
task bootstrap: [:drop, :create, :migrate, :seed, :sample_data]
end
task bs: 'db:bootstrap'"
end
uncomment_lines 'public/robots.txt', /User-agent: */
uncomment_lines 'public/robots.txt', /Disallow: */
insert_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do
"config.generators do |g|
g.stylesheets false
g.javascripts false
g.helper false
end\n\n"
end
remove_file "config/locales/en.yml"
create_file "config/locales/en.yml", "
en:
site_name: ''"
# RESOURCES
# ------------------------------------------------------------------------------------------------------
# CONTROLLER
if yes? 'Do you want to generate a public controller?'
name = ask('What should it be called? [pages]').underscore
name = 'pages' if name.blank?
generate :controller, "#{name} home"
route "
\n# PUBLIC ROUTES
# ----------------------------------------------------------------------------
root to: '#{name}\#home'\n"
end
if yes? 'Do you want to generate an admin controller?'
name = ask('What should it be called? [admin]').underscore
name = 'admin' if name.blank?
generate :controller, "#{name}/base"
generate :controller, "#{name}/dashboard show"
inject_into_class "app/controllers/#{name}/base_controller.rb", "#{name.upcase}::BaseController" do
"\n before_filter :verify_admin
private
def verify_admin
redirect_to login_url unless current_user && current_user.admin?
end\n"
end
route "
\n# ADMIN ROUTES
# ----------------------------------------------------------------------------
scope module: '#{name}', path: 'adm1nistr8tion', as: 'admin' do
root to: 'dashboard#show', as: :dashboard
end\n"
end
# MAILER
if yes? 'Do you need a mailer?'
name = ask('What should it be called? [user_mailer]').underscore
name = 'user_mailer' if name.blank?
generate :mailer, "#{name}"
create_file 'app/views/layouts/email_template.html.erb'
insert_into_file "app/mailers/#{name}.rb", before: "default from: 'from@example.com'" do
"\n layout 'email_template'"
end
end
# GEMS
# ------------------------------------------------------------------------------------------------------
append_file 'gemfile', "ruby '2.0.0'\n\n"
gem 'simple_form', '~> 3.1.0.rc2'
gem 'nested_form'
gem 'rails_bootstrap_helper', '~> 1.0.1', github: 'olimart/rails_bootstrap_helper', branch: 'bs3.1'
gem 'tabs_on_rails', '~> 2.1.1'
gem 'thin'
gem 'figaro', '~> 1.0.0.rc1', github: 'laserlemon/figaro'
gem 'compass-rails', '~> 2.0.0.pre', github: 'Compass/compass-rails'
gem_group :development, :test do
gem 'ffaker'
gem 'hirb'
end
gem_group :development do
gem 'rack-mini-profiler'
gem 'letter_opener'
gem 'better_errors'
end
gem_group :production do
gem 'exception_notification', '~> 4.0.0'
gem 'unicorn'
end
run 'bundle install'
generate 'simple_form:install'
generate 'figaro:install'
# generate 'exception_notification:install'
if yes? "Do you need users?"
gem 'sorcery', '~> 0.8.6'
route "
\n# USER ROUTES
# ----------------------------------------------------------------------------
delete 'logout' => 'sessions#destroy', as: 'logout'
get 'login' => 'sessions#new', as: 'login'
get 'signup' => 'registrations#new', as: 'signup'
get 'profile' => 'registrations#edit', as: 'profile'
post 'profile' => 'registrations#update', as: 'update_profile'
get 'paswords/:token/edit' => 'passwords#edit', as: 'change_password'
resource :password, only: [:new, :create, :edit, :update]
resources :registrations, except: [:index, :show, :destroy]
resources :sessions\n"
run 'bundle install'
generate "sorcery:install remember_me reset_password"
end
run 'cp config/database.yml config/database.sample.yml'
create_file 'config/application.yml'
run 'cp config/application.yml config/application.sample.yml'
create_file 'db/sample_data.rb'
inject_into_file 'db/sample_data.rb' do
"# encoding: utf-8
require 'ffaker'
puts 'GENERATING SAMPLE DATA ...'"
end
# GIT
# ------------------------------------------------------------------------------------------------------
git :init
append_file ".gitignore", "config/database.yml\n"
append_file ".gitignore", "public/assets/\n"
append_file ".gitignore", ".rvmrc\n"
append_file ".gitignore", "/public/cache\n"
append_file ".gitignore", "/public/system/*\n"
append_file ".gitignore", ".DS_Store\n"
append_file ".gitignore", "**/.DS_Store\n"
append_file ".gitignore", "config/application.yml\n"
append_file ".gitignore", "public/assets/\n"
append_file ".gitignore", "config/database.yml\n"
append_file ".gitignore", "public/assets/\n"
append_file ".gitignore", "config/database.yml\n"
append_file ".gitignore", "public/assets/\n"
append_file ".gitignore", "config/database.yml\n"
append_file ".gitignore", "public/assets/\n"
git add: ".", commit: "-m 'initial commit'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment