nubis_rails_boilerplate 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Dropmysite.com. https://dropmyemail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,3 @@
1
+ This project is a collection of capistrano recipes, rails application templates and short commands to get common types of rails up and going in my preferred setup.
2
+
3
+ The generated applications are ready to be deployed to a pre-configured remote server, production assets are stored in S3.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/templates'
3
+ NubisRailsBoilerplate::Templates.expand_skeleton('real_estate_app', __FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV.size != 1
3
+ puts "Call like #{$0} appname"
4
+ exit 1
5
+ end
6
+
7
+ template = File.expand_path('../../lib/rails_app_templates/site_with_admin.rb', __FILE__)
8
+ exec("rails new #{ARGV.first} -d mysql -m #{template}")
data/bin/new_spree_app ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV.size != 1
3
+ puts "Call like #{$0} appname"
4
+ exit 1
5
+ end
6
+
7
+ template = File.expand_path('../../lib/rails_app_templates/spree.rb', __FILE__)
8
+ exec("rails new #{ARGV.first} -d mysql -m #{template}")
@@ -0,0 +1,38 @@
1
+ def template(from, to)
2
+ erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
3
+ put ERB.new(erb).result(binding), to
4
+ end
5
+
6
+ def set_default(name, *args, &block)
7
+ set(name, *args, &block) unless exists?(name)
8
+ end
9
+
10
+ def remote_file_exists?(full_path)
11
+ 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
12
+ end
13
+
14
+ namespace :deploy do
15
+ desc "Install everything onto the server"
16
+ task :install do
17
+ run "#{sudo} apt-get -y update"
18
+ run "#{sudo} apt-get -y install python-software-properties"
19
+ run "#{sudo} apt-get -y install libmysqlclient-dev mysql-client-5.5"
20
+ run "#{sudo} apt-get -y install libxml2 libxml2-dev libxslt-dev imagemagick"
21
+ end
22
+
23
+ desc "Check if server was installed correctly"
24
+ task :check_server do
25
+ unless remote_file_exists?(deploy_to)
26
+ puts "Your server is not setup yet. Please run: $ cap deploy:setup_server"
27
+ exit 1
28
+ end
29
+ end
30
+ before 'check:revision', 'deploy:check_server'
31
+
32
+ task :setup_server do
33
+ top.deploy.install
34
+ top.deploy.setup
35
+ top.deploy.cold
36
+ top.deploy.migrations
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ namespace :check do
2
+ desc "Make sure local git is in sync with remote."
3
+ task :revision, roles: :web do
4
+ unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
5
+ puts "WARNING: HEAD is not the same as origin/#{branch}"
6
+ puts "Run `git push` to sync changes."
7
+ exit
8
+ end
9
+ end
10
+ before "deploy", "check:revision"
11
+ before "deploy:migrations", "check:revision"
12
+ before "deploy:cold", "check:revision"
13
+ end
@@ -0,0 +1,7 @@
1
+ namespace :deploy_configs do
2
+ desc "Generate the deploy.yml configuration file."
3
+ task :setup, roles: :app do
4
+ upload File.expand_path("../../config/deploy.yml", host_app_path), "#{release_path}/config/deploy.yml"
5
+ end
6
+ after "deploy:finalize_update", "deploy_configs:setup"
7
+ end
@@ -0,0 +1,16 @@
1
+ set_default(:mysql_password) { Capistrano::CLI.password_prompt "Mysql Password: " }
2
+
3
+ namespace :mysql do
4
+ desc "Generate the database.yml configuration file."
5
+ task :setup, roles: :app do
6
+ run "mkdir -p #{shared_path}/config"
7
+ template "mysql.yml.erb", "#{shared_path}/config/database.yml"
8
+ end
9
+ after "deploy:setup", "mysql:setup"
10
+
11
+ desc "Symlink the database.yml file into latest release"
12
+ task :symlink, roles: :app do
13
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
14
+ end
15
+ after "deploy:finalize_update", "mysql:symlink"
16
+ end
@@ -0,0 +1,25 @@
1
+ namespace :nginx do
2
+ desc "Install latest stable release of nginx"
3
+ task :install, roles: :web do
4
+ run "#{sudo} add-apt-repository -y ppa:nginx/stable"
5
+ run "#{sudo} apt-get -y update"
6
+ run "#{sudo} apt-get -y install nginx"
7
+ end
8
+ after "deploy:install", "nginx:install"
9
+
10
+ desc "Setup nginx configuration for this application"
11
+ task :setup, roles: :web do
12
+ template "nginx_unicorn.erb", "/tmp/nginx_conf"
13
+ run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
14
+ run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
15
+ restart
16
+ end
17
+ after "deploy:setup", "nginx:setup"
18
+
19
+ %w[start stop restart].each do |command|
20
+ desc "#{command} nginx"
21
+ task command, roles: :web do
22
+ run "#{sudo} service nginx #{command}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ namespace :nodejs do
2
+ desc "Install the latest relase of Node.js"
3
+ task :install, roles: :app do
4
+ run "#{sudo} add-apt-repository -y ppa:chris-lea/node.js"
5
+ run "#{sudo} apt-get -y update"
6
+ run "#{sudo} apt-get -y install nodejs"
7
+ end
8
+ after "deploy:install", "nodejs:install"
9
+ end
@@ -0,0 +1,27 @@
1
+ set_default :ruby_version, "1.9.3-p125"
2
+ set_default :rbenv_bootstrap, "bootstrap-ubuntu-12-04"
3
+
4
+ namespace :rbenv do
5
+ desc "Install rbenv, Ruby, and the Bundler gem"
6
+ task :install, roles: :app do
7
+ run "#{sudo} apt-get -y install curl git-core"
8
+ run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
9
+ bashrc = <<-BASHRC
10
+ if [ -d $HOME/.rbenv ]; then
11
+ export PATH="$HOME/.rbenv/bin:$PATH"
12
+ eval "$(rbenv init -)"
13
+ fi
14
+ BASHRC
15
+ put bashrc, "/tmp/rbenvrc"
16
+ run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
17
+ run "mv ~/.bashrc.tmp ~/.bashrc"
18
+ run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
19
+ run %q{eval "$(rbenv init -)"}
20
+ run "rbenv #{rbenv_bootstrap}"
21
+ run "rbenv install #{ruby_version}"
22
+ run "rbenv global #{ruby_version}"
23
+ run "gem install bundler --no-ri --no-rdoc"
24
+ run "rbenv rehash"
25
+ end
26
+ after "deploy:install", "rbenv:install"
27
+ end
@@ -0,0 +1,8 @@
1
+ production:
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ database: <%= mysql_database %>
5
+ pool: 5
6
+ username: <%= mysql_username %>
7
+ password: <%= mysql_password %>
8
+ host: <%= mysql_host %>
@@ -0,0 +1,27 @@
1
+ upstream unicorn {
2
+ server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80 default deferred;
7
+ # server_name example.com;
8
+ root <%= current_path %>/public;
9
+
10
+ location ^~ /assets/ {
11
+ gzip_static on;
12
+ expires max;
13
+ add_header Cache-Control public;
14
+ }
15
+
16
+ try_files $uri/index.html $uri @unicorn;
17
+ location @unicorn {
18
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
+ proxy_set_header Host $http_host;
20
+ proxy_redirect off;
21
+ proxy_pass http://unicorn;
22
+ }
23
+
24
+ error_page 500 502 503 504 /500.html;
25
+ client_max_body_size 4G;
26
+ keepalive_timeout 10;
27
+ }
@@ -0,0 +1,29 @@
1
+ working_directory "<%= current_path %>"
2
+ pid "<%= unicorn_pid %>"
3
+ stderr_path "<%= unicorn_log %>"
4
+ stdout_path "<%= unicorn_log %>"
5
+
6
+ listen "/tmp/unicorn.<%= application %>.sock"
7
+ worker_processes <%= unicorn_workers %>
8
+ timeout 30
9
+ preload_app true
10
+
11
+ before_exec do |server|
12
+ ENV["BUNDLE_GEMFILE"] = "<%= current_path %>/Gemfile"
13
+ end
14
+
15
+ before_fork do |server, worker|
16
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
17
+ old_pid = "#{server.config[:pid]}.oldbin"
18
+ if File.exists?(old_pid) && server.pid != old_pid
19
+ begin
20
+ Process.kill("QUIT", File.read(old_pid).to_i)
21
+ rescue Errno::ENOENT, Errno::ESRCH
22
+ end
23
+ end
24
+ end
25
+
26
+ after_fork do |server, worker|
27
+ ActiveRecord::Base.establish_connection
28
+ ActiveRecord::Base.verify_active_connections!
29
+ end
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= unicorn_pid %>
17
+ CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production"
18
+ AS_USER=<%= unicorn_user %>
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
29
+ }
30
+
31
+ run () {
32
+ if [ "$(id -un)" = "$AS_USER" ]; then
33
+ eval $1
34
+ else
35
+ su -c "$1" - $AS_USER
36
+ fi
37
+ }
38
+
39
+ case "$1" in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ run "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig USR2 && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ run "$CMD"
56
+ ;;
57
+ upgrade)
58
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
59
+ then
60
+ n=$TIMEOUT
61
+ while test -s $OLD_PIN && test $n -ge 0
62
+ do
63
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
64
+ done
65
+ echo
66
+
67
+ if test $n -lt 0 && test -s $OLD_PIN
68
+ then
69
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
70
+ exit 1
71
+ fi
72
+ exit 0
73
+ fi
74
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
75
+ run "$CMD"
76
+ ;;
77
+ reopen-logs)
78
+ sig USR1
79
+ ;;
80
+ *)
81
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
82
+ exit 1
83
+ ;;
84
+ esac
@@ -0,0 +1,26 @@
1
+ set_default(:unicorn_user) { user }
2
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
3
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
4
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
5
+ set_default(:unicorn_workers, 2)
6
+
7
+ namespace :unicorn do
8
+ desc "Setup Unicorn initializer and app configuration"
9
+ task :setup, roles: :app do
10
+ run "mkdir -p #{shared_path}/config"
11
+ template "unicorn.rb.erb", unicorn_config
12
+ template "unicorn_init.erb", "/tmp/unicorn_init"
13
+ run "chmod +x /tmp/unicorn_init"
14
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
15
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
16
+ end
17
+ after "deploy:setup", "unicorn:setup"
18
+
19
+ %w[start stop restart].each do |command|
20
+ desc "#{command} unicorn"
21
+ task command, roles: :app do
22
+ run "service unicorn_#{application} #{command}"
23
+ end
24
+ after "deploy:#{command}", "unicorn:#{command}"
25
+ end
26
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,5 @@
1
+ module NubisRailsBoilerplate
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
5
+
@@ -0,0 +1,45 @@
1
+ # Helps rendering a form which is associated to image models.
2
+ require 'activeadmin'
3
+
4
+ module NubisRailsBoilerplate
5
+ module ActiveAdminHelpers
6
+ def form_with_images(section_title = "Images", &config)
7
+ form html: {id: 'has_many_images', multipart: true} do |f|
8
+ f.inputs("#{f.object.class.to_s} Details"){ config.call(f) }
9
+
10
+ f.has_many :images, title: 'images' do |fi|
11
+ fi.inputs "Images" do
12
+ if fi.object.new_record?
13
+ fi.input :file, as: :file
14
+ else
15
+ fi.input :_destroy, :as => :boolean, :label => "Destroy?",
16
+ :hint => fi.template.image_tag(fi.object.file.url(:small))
17
+ end
18
+ end
19
+ end
20
+
21
+ f.actions
22
+ end
23
+ end
24
+
25
+ def attributes_table_with_images(&config)
26
+ attributes_table do
27
+ config.call
28
+ row :images do |item|
29
+ item.images.collect do |image|
30
+ image_tag(image.file.url(:small))
31
+ end.join.html_safe
32
+ end
33
+ end
34
+ active_admin_comments
35
+ end
36
+ end
37
+ end
38
+
39
+ class ActiveAdmin::ResourceDSL
40
+ include NubisRailsBoilerplate::ActiveAdminHelpers
41
+ end
42
+
43
+ class ActiveAdmin::Views::Pages::Show
44
+ include NubisRailsBoilerplate::ActiveAdminHelpers
45
+ end
@@ -0,0 +1,80 @@
1
+ module NubisRailsBoilerplate
2
+ class Capistrano
3
+ attr_accessor :cap, :cap_path, :app_name
4
+ def initialize(cap, cap_path, app_name)
5
+ self.cap = cap
6
+ self.cap_path = cap_path
7
+ self.app_name = app_name
8
+
9
+ cap.set :host_app_path, cap_path
10
+ cap.set :repository, "git@github.com:nubis/#{app_name}.git"
11
+ check_git_repo
12
+ load_modules
13
+ load_permission
14
+ load_configs
15
+
16
+ cap.set :user, "ubuntu"
17
+ cap.set :application, app_name
18
+ cap.set :deploy_to, "/home/ubuntu/apps/#{app_name}"
19
+ cap.set :deploy_via, :remote_cache
20
+ cap.set :use_sudo, false
21
+ cap.set :scm, "git"
22
+ cap.set :branch, "master"
23
+ cap.set :keep_releases, 2
24
+ cap.default_run_options[:pty] = true
25
+ cap.ssh_options[:forward_agent] = true
26
+ cap.after "deploy", "deploy:cleanup" # keep only the last 5 releases
27
+ end
28
+
29
+ def check_git_repo
30
+ output = `git pull origin master 2>&1`
31
+ unless $?.success?
32
+ puts "You need to be able to access #{cap.repository} before you deploy."
33
+ puts "Make sure that it exists and you can access it before you continue."
34
+ puts "The error was:"
35
+
36
+ puts output
37
+ exit 1
38
+ end
39
+ end
40
+
41
+ def load_modules
42
+ path = File.expand_path('../capistrano_recipes', __FILE__)
43
+ modules = Dir["#{path}/*.rb"].collect{|f| File.basename(f)}
44
+ modules.sort.each do |m|
45
+ puts "Loading cap module #{m}"
46
+ cap.load File.join(path, m)
47
+ end
48
+ end
49
+
50
+ def load_permission
51
+ permission_path = File.expand_path('../../config/permission.pem', cap_path)
52
+ unless File.file?(permission_path)
53
+ puts "You don't have permission to push to the server"
54
+ puts "I could not find a file named #{permission_path}"
55
+ puts "Please request one and try again"
56
+ exit 1
57
+ end
58
+ cap.ssh_options[:keys] = permission_path
59
+ end
60
+
61
+ def load_configs
62
+ configs_path = File.expand_path('../../config/deploy.yml', cap_path)
63
+ unless File.file?(configs_path)
64
+ puts "You don't have the required configuration options to push to production"
65
+ puts "I could not find a file named #{configs_path}"
66
+ puts "Please request one and try again"
67
+ exit 1
68
+ end
69
+ configs = YAML.load_file(configs_path)
70
+ unless configs.values.all?
71
+ puts "You need to provide your configuration options before you can push."
72
+ puts "Setup your server and database and input your data in: #{configs_path}"
73
+ end
74
+ configs.each do |key, value|
75
+ cap.set key, value
76
+ end
77
+ cap.server configs['server_url'], :web, :app, :db, primary: true
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'extra_capistrano'
2
+ require_relative 'extra_activeadmin'
3
+ require_relative 'engine'
@@ -0,0 +1,18 @@
1
+ run "bundle install"
2
+ rake "db:create"
3
+
4
+ # replace app_name in config/deploy
5
+ file 'config/deploy.rb', <<-CODE
6
+ require "bundler/capistrano"
7
+ require "nubis_rails_boilerplate"
8
+ NubisRailsBoilerplate::Capistrano.new(self, __FILE__, "#{app_name}")
9
+ CODE
10
+
11
+ rake 'db:migrate'
12
+ rake 'db:test:prepare'
13
+
14
+ git :init
15
+ git :add => "."
16
+ git :commit => %Q{ -m 'Initial commit' }
17
+ git remote: "add origin git@github.com:nubis/#{app_name}.git"
18
+
@@ -0,0 +1,227 @@
1
+ run "rm public/index.html"
2
+ # Some gems we always use
3
+ gem_group :development, :test do
4
+ gem "rspec-rails", ">= 2.11.0"
5
+ gem "factory_girl_rails", ">= 4.1.0"
6
+ gem "quiet_assets", ">= 1.0.1"
7
+ gem 'debugger'
8
+ end
9
+
10
+ gem_group :development do
11
+ gem "haml-rails", ">= 0.3.5"
12
+ gem "hpricot", ">= 0.8.6"
13
+ gem "ruby_parser", ">= 2.3.1"
14
+ end
15
+
16
+ gem_group :test do
17
+ gem "email_spec", ">= 1.2.1"
18
+ gem "capybara"
19
+ gem 'capybara-webkit', '0.12.0'
20
+ end
21
+
22
+ gem 'settingslogic'
23
+ gem 'unicorn'
24
+ gem 'capistrano'
25
+ gem "bootstrap-sass", ">= 2.1.0.0"
26
+ gem 'haml'
27
+ gem 'jquery-rails'
28
+ gem 'email_validator'
29
+ gem 'exception_notification', git: 'git://github.com/smartinez87/exception_notification.git'
30
+ gem 'nubis_rails_boilerplate', git: 'git://github.com/nubis/nubis_rails_boilerplate.git'
31
+ gem "simple_form"
32
+ gem 'activeadmin'
33
+
34
+ run "bundle install"
35
+
36
+ rake "db:create"
37
+
38
+ run 'rails generate rspec:install'
39
+
40
+ file 'Capfile', <<-CODE
41
+ load 'deploy'
42
+ load 'deploy/assets'
43
+ Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each do |plugin|
44
+ load(plugin)
45
+ end
46
+ load 'config/deploy'
47
+ CODE
48
+
49
+ file 'config/deploy.rb', <<-CODE
50
+ require "bundler/capistrano"
51
+ require "nubis_rails_boilerplate"
52
+ NubisRailsBoilerplate::Capistrano.new(self, __FILE__, "#{app_name}")
53
+ CODE
54
+
55
+ file 'config/deploy.yml', <<-CODE
56
+ mysql_database:
57
+ mysql_username:
58
+ mysql_host:
59
+ mysql_password:
60
+ server_url:
61
+ aws_access_key_id:
62
+ aws_secret_access_key:
63
+ s3_bucket_name:
64
+ CODE
65
+
66
+ file 'app/models/settings.rb', <<-CODE
67
+ class Settings < Settingslogic
68
+ source "\#{Rails.root}/config/deploy.yml"
69
+ end
70
+ CODE
71
+
72
+ run 'rm spec/spec_helper.rb'
73
+ file 'spec/spec_helper.rb', <<-CODE
74
+ ENV["RAILS_ENV"] ||= 'test'
75
+ require File.expand_path("../../config/environment", __FILE__)
76
+ require 'rspec/rails'
77
+ require 'email_spec'
78
+ require 'rspec/autorun'
79
+ require 'factory_girl_rails'
80
+ require 'capybara-webkit'
81
+ require 'capybara/rspec'
82
+ require 'capybara/rails'
83
+
84
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
85
+
86
+ RSpec.configure do |config|
87
+ config.include EmailSpec::Helpers
88
+ config.include EmailSpec::Matchers
89
+ config.include FactoryGirl::Syntax::Methods
90
+ config.include Devise::TestHelpers, :type => :controller
91
+
92
+ config.use_transactional_fixtures = true
93
+ config.infer_base_class_for_anonymous_controllers = false
94
+ config.order = "random"
95
+ end
96
+ CODE
97
+
98
+ run 'rails generate active_admin:install'
99
+ run 'rails generate active_admin:resource admin_user'
100
+
101
+ file 'spec/controllers/admin/admin_users_controller_spec.rb', <<-CODE
102
+ require 'spec_helper'
103
+
104
+ describe Admin::AdminUsersController do
105
+ render_views
106
+
107
+ it "gets the list of available pre_signups" do
108
+ sign_in create(:admin_user)
109
+ get :index
110
+ assigns(:admin_users).should == AdminUser.all
111
+ end
112
+ end
113
+ CODE
114
+
115
+ run 'rm app/admin/admin_user.rb'
116
+ file 'app/admin/admin_user.rb', <<-CODE
117
+ ActiveAdmin.register AdminUser do
118
+ index do
119
+ column :email
120
+ column :current_sign_in_at
121
+ column :last_sign_in_at
122
+ column :sign_in_count
123
+ default_actions
124
+ end
125
+
126
+ form do |f|
127
+ f.inputs "Admin Details" do
128
+ f.input :email
129
+ f.input :password
130
+ f.input :password_confirmation
131
+ end
132
+ f.buttons
133
+ end
134
+ end
135
+ CODE
136
+
137
+ run 'rm spec/factories/admin_users.rb'
138
+ file 'spec/factories/admin_users.rb', <<-CODE
139
+ FactoryGirl.define do
140
+ factory :admin_user do
141
+ email 'admin@example.com'
142
+ password 'password'
143
+ end
144
+ end
145
+ CODE
146
+
147
+ file 'db/migrate/00000001_initial_tables.rb', <<-CODE
148
+ class InitialTables < ActiveRecord::Migration
149
+ create_table :images, force: true do |t|
150
+ t.integer :viewable_id
151
+ t.string :viewable_type, limit: 50
152
+ t.attachment :file
153
+ t.integer :position
154
+ t.timestamps
155
+ end
156
+
157
+ add_index :images, [:viewable_id], name: :index_images_on_viewable_id
158
+ add_index :images, [:viewable_type], name: :index_images_on_viewable_type
159
+
160
+ create_table :properties, force: true do |t|
161
+ t.string :name
162
+ t.string :url_name
163
+ t.text :description
164
+ t.references :neighborhood
165
+ t.float :latitude
166
+ t.float :longitude
167
+ t.string :address
168
+ t.string :public_address
169
+ t.integer :covered_square_meters
170
+ t.integer :uncovered_square_meters
171
+ t.integer :rooms
172
+ t.integer :bathrooms
173
+ t.text :amenities
174
+ t.string :keywords
175
+ t.boolean :for_rent
176
+ t.boolean :for_sale
177
+ end
178
+
179
+ add_index :properties, [:neighborhood_id], name: :index_images_on_neighborhood_id
180
+
181
+ create_table :neighborhood, force: true do |t|
182
+ t.string :name
183
+ t.string :url_name
184
+ t.text :description
185
+ t.text :amenities
186
+ end
187
+ end
188
+ CODE
189
+
190
+ file 'app/models/image.rb', <<-CODE
191
+ class Image < ActiveRecord::Base
192
+ attr_accessible :file, as: :admin
193
+ has_attached_file :file, styles: {small: '240x240>', large: '600x600>'}
194
+ validates_attachment :file, presence: true,
195
+ content_type: { content_type: ['image/jpg', 'image/png', 'image/gif', 'image/jpeg'] }
196
+ belongs_to :viewable, :polymorphic => true
197
+ end
198
+ CODE
199
+
200
+ file 'app/models/property.rb', <<-CODE
201
+ class Property < ActiveRecord::Base
202
+ has_many :images, as: :viewable, order: :position, :dependent => :destroy
203
+ belongs_to :neighborhood
204
+ accepts_nested_attributes_for :images, allow_destroy: true
205
+ attr_protected
206
+ end
207
+ CODE
208
+
209
+ file 'app/models/neighborhood.rb', <<-CODE
210
+ class Neighborhood < ActiveRecord::Base
211
+ has_many :images, as: :viewable, order: :position, :dependent => :destroy
212
+ accepts_nested_attributes_for :images, allow_destroy: true
213
+ attr_protected
214
+ has_many :properties
215
+ end
216
+ CODE
217
+
218
+ file 'app/controllers/properties_controller.rb'
219
+
220
+ rake 'db:migrate'
221
+ rake 'db:test:prepare'
222
+
223
+ git :init
224
+ git :add => "."
225
+ git :commit => %Q{ -m 'Initial commit' }
226
+ git remote: "add origin git@github.com:nubis/#{app_name}.git"
227
+
@@ -0,0 +1,87 @@
1
+ run "rm public/index.html"
2
+ git :init
3
+ git :add => "."
4
+ git :commit => %Q{ -m 'Initial commit' }
5
+
6
+ # Some gems we always use
7
+ gem_group :development, :test do
8
+ gem "rspec-rails", ">= 2.11.0"
9
+ gem "capybara"
10
+ gem 'debugger'
11
+ end
12
+
13
+ gem 'settingslogic'
14
+ gem 'sass-rails', '~> 3.2.3'
15
+ gem 'unicorn'
16
+ gem 'capistrano'
17
+ gem 'spree', '1.2.0'
18
+ gem 'spree_gateway', :git => 'git://github.com/spree/spree_gateway.git', :branch => "1-2-stable"
19
+ gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'
20
+ gem 'spree_admin_dark', git: 'git://github.com/nubis/spree_admin_dark'
21
+ gem 'haml'
22
+ gem 'exception_notification', git: 'git://github.com/smartinez87/exception_notification.git'
23
+ gem 'nubis_rails_boilerplate', git: 'git://github.com/nubis/nubis_rails_boilerplate.git'
24
+
25
+ run "bundle install"
26
+
27
+ rake "db:create"
28
+
29
+ run "rails generate spree:install --user-class=Spree::User --sample=false --auto-accept=true"
30
+ run 'rails generate spree_admin_dark:install'
31
+
32
+ file 'Capfile', <<-CODE
33
+ load 'deploy'
34
+ load 'deploy/assets'
35
+ Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each do |plugin|
36
+ load(plugin)
37
+ end
38
+ load 'config/deploy'
39
+ CODE
40
+
41
+ file 'config/deploy.rb', <<-CODE
42
+ require "bundler/capistrano"
43
+ require "nubis_rails_boilerplate"
44
+ NubisRailsBoilerplate::Capistrano.new(self, __FILE__, "#{app_name}")
45
+ CODE
46
+
47
+ file 'config/deploy.yml', <<-CODE
48
+ mysql_database:
49
+ mysql_username:
50
+ mysql_host:
51
+ mysql_password:
52
+ server_url:
53
+ aws_access_key_id:
54
+ aws_secret_access_key:
55
+ s3_bucket_name:
56
+ CODE
57
+
58
+ file 'app/models/settings.rb', <<-CODE
59
+ class Settings < Settingslogic
60
+ source "\#{Rails.root}/config/deploy.yml"
61
+ end
62
+ CODE
63
+
64
+ initializer 'spree_s3_images.rb', <<-CODE
65
+ if Rails.env.production?
66
+ Spree::Image.class_eval do
67
+ definition = self.attachment_definitions[:attachment]
68
+ definition[:styles] = {
69
+ :mini => '48x48>',
70
+ :small => '55x80>',
71
+ :product => '160x232>',
72
+ :large => '320x464>'
73
+ }
74
+ definition.delete :url
75
+ definition[:path] = definition[:path].gsub(':rails_root/public/', '')
76
+ definition[:storage] = 's3'
77
+ definition[:bucket] = Settings.s3_bucket_name
78
+ definition[:s3_credentials] = {
79
+ access_key_id: Settings.aws_access_key_id,
80
+ secret_access_key: Settings.aws_secret_access_key
81
+ }
82
+ end
83
+ end
84
+ CODE
85
+
86
+ git :init
87
+ git remote: "add origin git@github.com:nubis/#{app_name}.git"
data/lib/templates.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'active_support/core_ext'
2
+ module NubisRailsBoilerplate
3
+ class Templates
4
+ def self.expand_skeleton(skeleton, basefile)
5
+ skeleton_path = File.absolute_path(File.expand_path("../../skeletons/#{skeleton}", basefile))
6
+ `cp -r #{skeleton_path} #{get_app_name}`
7
+ patch_module_name(skeleton, get_app_name)
8
+ run_setup_tasks(get_app_name)
9
+ puts "All done! Your app is ready to start customizing."
10
+ end
11
+
12
+ def self.patch_module_name(skeleton, app_name)
13
+ puts "Patching #{skeleton} files for #{app_name}"
14
+ %w(Rakefile config/application.rb config/environment.rb config/environments/development.rb
15
+ config/environments/test.rb config/environments/production.rb config/initializers/secret_token.rb
16
+ config/database.yml config/initializers/session_store.rb config/routes.rb config.ru).each do |filename|
17
+ full_path = File.expand_path(filename, app_name)
18
+ new_contents = File.read(full_path)
19
+ .gsub(skeleton.camelize, app_name.camelize)
20
+ .gsub(skeleton, app_name)
21
+ File.write(full_path, new_contents)
22
+ end
23
+ end
24
+
25
+ def self.run_setup_tasks(app_name)
26
+ puts "Installing gems and configuring databases"
27
+ Dir.chdir(app_name) do
28
+ `bundle install; rake db:create; rake db:migrate; rake db:test:prepare`
29
+ end
30
+ end
31
+
32
+ def self.get_app_name
33
+ if ARGV.size != 1
34
+ puts "Call it like this: #{$0} app_name"
35
+ exit 1
36
+ end
37
+
38
+ unless ARGV[0] =~ /^[a-z_]*$/
39
+ puts "The app_name can only be lowercase letters and underscores"
40
+ exit 1
41
+ end
42
+
43
+ return ARGV[0]
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nubis_rails_boilerplate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nubis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70133092875420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70133092875420
25
+ - !ruby/object:Gem::Dependency
26
+ name: activeadmin
27
+ requirement: &70133092887800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70133092887800
36
+ - !ruby/object:Gem::Dependency
37
+ name: settingslogic
38
+ requirement: &70133092885820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70133092885820
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: &70133092884080 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70133092884080
58
+ description: I usually start the same rails apps, running on the same infrastructure,
59
+ so this collection of recipes and application templates let me focus on what I care
60
+ about the most.
61
+ email: yo@nubis.im
62
+ executables:
63
+ - new_real_estate_app
64
+ - new_site_with_admin
65
+ - new_spree_app
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/capistrano_recipes/base.rb
70
+ - lib/capistrano_recipes/check.rb
71
+ - lib/capistrano_recipes/deploy_configs.rb
72
+ - lib/capistrano_recipes/mysql.rb
73
+ - lib/capistrano_recipes/nginx.rb
74
+ - lib/capistrano_recipes/nodejs.rb
75
+ - lib/capistrano_recipes/rbenv.rb
76
+ - lib/capistrano_recipes/templates/mysql.yml.erb
77
+ - lib/capistrano_recipes/templates/nginx_unicorn.erb
78
+ - lib/capistrano_recipes/templates/unicorn.rb.erb
79
+ - lib/capistrano_recipes/templates/unicorn_init.erb
80
+ - lib/capistrano_recipes/unicorn.rb
81
+ - lib/engine.rb
82
+ - lib/extra_activeadmin.rb
83
+ - lib/extra_capistrano.rb
84
+ - lib/nubis_rails_boilerplate.rb
85
+ - lib/rails_app_templates/real_estate_app.rb
86
+ - lib/rails_app_templates/site_with_admin.rb
87
+ - lib/rails_app_templates/spree.rb
88
+ - lib/templates.rb
89
+ - Readme.md
90
+ - MIT-LICENSE
91
+ - bin/new_real_estate_app
92
+ - bin/new_site_with_admin
93
+ - bin/new_spree_app
94
+ homepage: https://github.com/nubis/nubis_rails_boilerplate
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.15
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: My preferred rails application templates, capistrano tasks, etc
118
+ test_files: []
119
+ has_rdoc: