A template I use for creating Ruby on Rails apps
gem "bootstrap-sass", '~> 3.3.3' | |
gem "cancan" | |
gem "jquery-turbolinks" | |
gem "haml-rails" | |
gem "awesome_print" | |
gem "google-analytics-rails" | |
gem "ejs" | |
gem "paper_trail" | |
gem "nokogiri" | |
gem "dalli" | |
gem "rails_12factor", group: :production | |
gem "underscore-rails" | |
gem "devise" | |
gem "unicorn" | |
gem 'hashie' | |
gem 'memcachier' | |
gem 'has_scope' | |
gem 'font-awesome-rails' | |
gem 'bootswatch-rails' | |
gem 'nprogress-rails' | |
gem "sidekiq" | |
gem 'dotenv' | |
gem 'httparty' | |
# gem 'rails_admin' | |
gem_group :test, :development do | |
gem 'rspec' | |
gem 'rspec-rails' | |
gem "factory_girl_rails" | |
gem "capybara" | |
gem "capybara-webkit" | |
gem "listen" | |
gem "guard" | |
gem "rack-livereload" | |
gem "guard-rails" | |
gem "guard-livereload" | |
gem "ruby_gntp" | |
gem "rb-fsevent" | |
# gem "better_errors" | |
# gem "quiet_assets" | |
gem 'database_cleaner' | |
gem "webmock", "< 1.16" | |
gem "vcr" | |
gem 'coveralls', require: false | |
gem "simplecov", require: false | |
gem "guard-sidekiq" | |
gem 'guard-rspec' | |
gem 'spring-commands-rspec' | |
end | |
environment do | |
<<-eos | |
Dotenv.load | |
config.autoload_paths << "\#{config.root}/lib" | |
config.active_job.queue_adapter = :sidekiq | |
config.generators do |g| | |
g.template_engine :haml | |
g.test_framework :rspec | |
end | |
# require 'open-uri' | |
# uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379") | |
# redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) | |
# config.redis = redis | |
eos | |
end | |
environment nil, env: 'test' do | |
<<-eos | |
config.active_job.queue_adapter = :inline | |
ActiveJob::Base.logger.level = 2 | |
config.log_level = :error | |
eos | |
end | |
environment nil, env: 'development' do | |
<<-eos | |
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload) | |
config.action_mailer.delivery_method = :smtp | |
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 } | |
config.action_mailer.default_url_options = { | |
:host => "localhost", | |
:port => 3000 | |
} | |
WebMock.allow_net_connect! | |
eos | |
end | |
environment nil, env: 'production' do | |
<<-eos | |
config.cache_store = :dalli_store | |
GA.tracker = ENV['GOOGLE_ANALYTICS_ID'] | |
config.logger = Logger.new(STDOUT) | |
ActionMailer::Base.smtp_settings = { | |
:address => 'smtp.sendgrid.net', | |
:port => '587', | |
:authentication => :plain, | |
:user_name => ENV['SENDGRID_USERNAME'], | |
:password => ENV['SENDGRID_PASSWORD'], | |
:domain => 'heroku.com', | |
:enable_starttls_auto => true | |
} | |
eos | |
end | |
create_file "app/views/layouts/application.html.haml", <<-eos | |
!!! | |
%html | |
%head | |
%title | |
- if content_for? :title | |
= yield(:title) | |
= " - " | |
New Application | |
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"} | |
%meta{name: "viewport", content: "width=device-width, initial-scale=1.0"} | |
= stylesheet_link_tag "application" | |
= javascript_include_tag "application" | |
= csrf_meta_tag | |
-# = favicon_link_tag | |
= yield(:head) | |
= analytics_init if Rails.env.production? | |
%body | |
%nav.navbar.navbar-default | |
.container-fluid | |
/ Brand and toggle get grouped for better mobile display | |
.navbar-header | |
%button.navbar-toggle.collapsed{"data-target" => "#bs-example-navbar-collapse-1", "data-toggle" => "collapse", :type => "button"} | |
%span.sr-only Toggle navigation | |
%span.icon-bar | |
%span.icon-bar | |
%span.icon-bar | |
%a.navbar-brand{:href => "#"} Brand | |
/ Collect the nav links, forms, and other content for toggling | |
#bs-example-navbar-collapse-1.collapse.navbar-collapse | |
%ul.nav.navbar-nav | |
%li.active | |
%a{:href => "#"} | |
Link | |
%span.sr-only (current) | |
%li | |
%a{:href => "#"} Link | |
%li.dropdown | |
%a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", :href => "#", :role => "button"} | |
Dropdown | |
%span.caret | |
%ul.dropdown-menu{:role => "menu"} | |
%li | |
%a{:href => "#"} Action | |
%li | |
%a{:href => "#"} Another action | |
%li | |
%a{:href => "#"} Something else here | |
%li.divider | |
%li | |
%a{:href => "#"} Separated link | |
%li.divider | |
%li | |
%a{:href => "#"} One more separated link | |
%form.navbar-form.navbar-left{:role => "search"} | |
.form-group | |
%input.form-control{:placeholder => "Search", :type => "text"}/ | |
%button.btn.btn-default{:type => "submit"} Submit | |
%ul.nav.navbar-nav.navbar-right | |
%li | |
%a{:href => "#"} Link | |
%li.dropdown | |
%a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", :href => "#", :role => "button"} | |
Dropdown | |
%span.caret | |
%ul.dropdown-menu{:role => "menu"} | |
%li | |
%a{:href => "#"} Action | |
%li | |
%a{:href => "#"} Another action | |
%li | |
%a{:href => "#"} Something else here | |
%li.divider | |
%li | |
%a{:href => "#"} Separated link | |
/ /.navbar-collapse | |
/ /.container-fluid | |
.container | |
= yield | |
eos | |
remove_file "app/views/layouts/application.html.erb" | |
remove_file "app/assets/stylesheets/application.css" | |
create_file "app/assets/stylesheets/application.css.scss", <<-eos | |
/* | |
*= require_self | |
*/ | |
@import "bootstrap-sprockets"; | |
@import "bootstrap"; | |
eos | |
create_file "config/unicorn.rb", <<-eos | |
worker_processes 2 | |
timeout 30 | |
preload_app true | |
@jobs_pid = nil | |
before_fork do |server, worker| | |
@jobs_pid ||= spawn("bundle exec rake jobs:work") | |
# Replace with MongoDB or whatever | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.connection.disconnect! | |
Rails.logger.info('Disconnected from ActiveRecord') | |
end | |
# # If you are using Redis but not Resque, change this | |
# if defined?(Split) && !Split.redis.nil? | |
# Split.redis.quit | |
# Rails.logger.info('Disconnected from Redis') | |
# end | |
end | |
after_fork do |server, worker| | |
# Replace with MongoDB or whatever | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
Rails.logger.info('Connected to ActiveRecord') | |
end | |
end | |
eos | |
create_file "GuardFile", <<-eos | |
guard 'rails' do | |
watch('Gemfile.lock') | |
watch(%r{^(config)/.*}) | |
watch(%r{^(lib)/.*}) | |
end | |
guard 'livereload' do | |
watch(%r{app/views/.+\.(erb|haml|slim)$}) | |
watch(%r{app/helpers/.+\.rb}) | |
watch(%r{public/.+\.(css|js|html)}) | |
watch(%r{config/locales/.+\.yml}) | |
# Rails Assets Pipeline | |
watch(%r{(app|vendor)/assets/\w+/(.+\.(css|js|html)).*}) { |m| "/assets/\#{m[2]}" } | |
# watch(%r{(app|vendor)(/assets/\w+/(.+)\.(sass))}) { |m| "/assets/#{m[3]}.css" } | |
end | |
# Note: The cmd option is now required due to the increasing number of ways | |
# rspec may be run, below are examples of the most common uses. | |
# * bundler: 'bundle exec rspec' | |
# * bundler binstubs: 'bin/rspec' | |
# * spring: 'bin/rsspec' (This will use spring if running and you have | |
# installed the spring binstubs per the docs) | |
# * zeus: 'zeus rspec' (requires the server to be started separetly) | |
# * 'just' rspec: 'rspec' | |
guard :rspec, cmd: 'bundle exec bin/rspec', failed_mode: :focus do | |
watch(%r{^spec/.+_spec\.rb$}) | |
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/\#{m[1]}_spec.rb" } | |
watch('spec/rails_helper.rb') { "spec" } | |
# Rails example | |
watch(%r{^app/(.+)\.rb$}) { |m| "spec/\#{m[1]}_spec.rb" } | |
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/\#{m[1]}\#{m[2]}_spec.rb" } | |
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/\#{m[1]}_routing_spec.rb", "spec/\#{m[2]}s/\#{m[1]}_\#{m[2]}_spec.rb", "spec/acceptance/\#{m[1]}_spec.rb"] } | |
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } | |
watch('config/routes.rb') { "spec/routing" } | |
watch('app/controllers/application_controller.rb') { "spec/controllers" } | |
watch('spec/rails_helper.rb') { "spec" } | |
# Capybara features specs | |
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/\#{m[1]}_spec.rb" } | |
# Turnip features and steps | |
watch(%r{^spec/acceptance/(.+)\.feature$}) | |
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**\#{m[1]}.feature")][0] || 'spec/acceptance' } | |
end | |
### Guard::Sidekiq | |
# available options: | |
# - :verbose | |
# - :queue (defaults to "default") can be an array | |
# - :concurrency (defaults to 1) | |
# - :timeout | |
# - :environment (corresponds to RAILS_ENV for the Sidekiq worker) | |
# guard 'sidekiq', :environment => 'development' do | |
# watch(%r{^workers/(.+)\.rb$}) | |
# end | |
eos | |
create_file "spec/rails_helper.rb", <<-eos | |
require 'rubygems' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'dotenv' | |
Dotenv.load | |
require 'rspec/rails' | |
require 'capybara/rspec' | |
require 'database_cleaner' | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) | |
Capybara.javascript_driver = :webkit | |
VCR.configure do |c| | |
c.cassette_library_dir = 'spec/support/cassettes' | |
c.hook_into :webmock | |
c.ignore_localhost = true | |
c.configure_rspec_metadata! | |
end | |
RSpec.configure do |config| | |
config.include FactoryGirl::Syntax::Methods | |
config.include Capybara::DSL | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :truncation | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
config.infer_base_class_for_anonymous_controllers = false | |
config.order = "random" | |
end | |
eos | |
create_file "Procfile", <<-eos | |
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb | |
worker: bundle exec sidekiq | |
eos | |
create_file "config/sidekiq.yml", <<-eos | |
--- | |
:concurrency: <%= ENV['WORKER_CONCURRENCY'] || 4 %> | |
:queues: | |
- default | |
- active_jobs | |
eos | |
run "bundle" | |
run "bundle exec spring binstub rspec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment