wagon_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,198 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ module WagonRails
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+ class_option :database, type: :string, aliases: "-d", default: "postgresql",
7
+ desc: "Configure for selected database (options: #{DATABASES.join("/")})"
8
+
9
+ class_option :skip_heroku, type: :boolean, default: false,
10
+ desc: "Create production Heroku app"
11
+
12
+ class_option :skip_github, type: :boolean, default: false,
13
+ desc: "Create GitHub repository"
14
+
15
+ class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
16
+ desc: "Skip Test::Unit files"
17
+
18
+ class_option :skip_turbolinks, type: :boolean, default: true,
19
+ desc: "Skip turbolinks gem"
20
+
21
+ class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
22
+ desc: "Don't run bundle install"
23
+
24
+ def finish_template
25
+ invoke :wagon_rails_customization
26
+ super
27
+ end
28
+
29
+ def wagon_rails_customization
30
+ invoke :setup_git
31
+ invoke :customize_gemfile
32
+ invoke :setup_development_environment
33
+ invoke :setup_production_environment
34
+ invoke :create_wagon_rails_views
35
+ invoke :configure_app
36
+ invoke :setup_stylesheets
37
+ invoke :setup_javascripts
38
+ invoke :copy_miscellaneous_files
39
+ invoke :customize_error_pages
40
+ invoke :remove_routes_comment_lines
41
+ invoke :add_root_route
42
+ invoke :setup_auth
43
+ invoke :setup_database
44
+ invoke :create_github_repo
45
+ invoke :first_commit
46
+ invoke :create_heroku_app
47
+ invoke :outro
48
+ end
49
+
50
+ def customize_gemfile
51
+ build :replace_gemfile
52
+ build :set_ruby_to_version_being_used
53
+
54
+ bundle_command 'install'
55
+ end
56
+
57
+ def setup_database
58
+ say 'Setting up database'
59
+
60
+ if 'postgresql' ==
61
+ [:database]
62
+ build :use_postgres_config_template
63
+ end
64
+
65
+ build :create_database
66
+ end
67
+
68
+ def setup_development_environment
69
+ say 'Setting up the development environment'
70
+ build :raise_on_delivery_errors
71
+ build :set_development_delivery_method
72
+ build :raise_on_unpermitted_parameters
73
+ build :configure_generators
74
+ build :configure_i18n_for_missing_translations
75
+ end
76
+
77
+ def setup_production_environment
78
+ say 'Setting up the production environment'
79
+ build :configure_smtp
80
+ build :enable_rack_deflater
81
+ end
82
+
83
+ def create_wagon_rails_views
84
+ say 'Creating wagon_rails views'
85
+ build :create_partials_directory
86
+ build :create_shared_flashes
87
+ build :create_application_layout
88
+ end
89
+
90
+ def configure_app
91
+ say 'Configuring app'
92
+ build :configure_action_mailer
93
+ build :configure_rack_timeout
94
+ build :configure_simple_form
95
+ build :disable_xml_params
96
+ build :fix_i18n_deprecation_warning
97
+ build :configure_puma
98
+ build :setup_foreman
99
+ build :setup_figaro
100
+ build :setup_paperclip
101
+ build :copy_application_yml
102
+ end
103
+
104
+ def setup_stylesheets
105
+ say 'Set up stylesheets'
106
+ build :setup_stylesheets
107
+ end
108
+
109
+ def setup_javascripts
110
+ say 'Set up javascripts'
111
+ build :setup_javascripts
112
+ end
113
+
114
+ def setup_git
115
+ unless options[:skip_git]
116
+ say 'Initializing git'
117
+ invoke :setup_gitignore
118
+ invoke :init_git
119
+ end
120
+ end
121
+
122
+ def setup_auth
123
+ build :generate_devise
124
+ build :generate_user
125
+ build :install_navbar
126
+ build :generate_devise_views
127
+ build :generate_pundit
128
+ build :setup_application_controller
129
+ end
130
+
131
+ def create_heroku_app
132
+ unless options[:skip_heroku]
133
+ say "Creating Heroku app"
134
+ build :create_heroku_app
135
+ build :set_heroku_remote
136
+ build :provide_deploy_script
137
+ build :add_host_to_application_yml
138
+ build :commit, "Add heroku deploy script"
139
+ end
140
+ end
141
+
142
+ def create_github_repo
143
+ unless options[:skip_github]
144
+ say 'Creating Github repo'
145
+ build :create_github_repo
146
+ end
147
+ end
148
+
149
+ def setup_gitignore
150
+ build :gitignore_files
151
+ end
152
+
153
+ def init_git
154
+ build :init_git
155
+ end
156
+
157
+ def copy_miscellaneous_files
158
+ say 'Copying miscellaneous support files'
159
+ build :copy_miscellaneous_files
160
+ end
161
+
162
+ def customize_error_pages
163
+ say 'Customizing the 500/404/422 pages'
164
+ build :customize_error_pages
165
+ end
166
+
167
+ def remove_routes_comment_lines
168
+ build :remove_routes_comment_lines
169
+ end
170
+
171
+ def add_root_route
172
+ build :copy_home
173
+ build :configure_high_voltage
174
+ end
175
+
176
+ def first_commit
177
+ build :commit, "New rails app generated with lewagon/wagon-rails gem"
178
+ end
179
+
180
+ def outro
181
+ say "Congratulations! You're ready to rock!"
182
+ unless options[:skip_heroku]
183
+ say 'Once in the rails folder, you can deploy to Heroku with:'
184
+ say ' $ bin/deploy'
185
+ end
186
+ end
187
+
188
+ protected
189
+
190
+ def get_builder_class
191
+ WagonRails::AppBuilder
192
+ end
193
+
194
+ def using_active_record?
195
+ !options[:skip_active_record]
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,5 @@
1
+ module WagonRails
2
+ RAILS_VERSION = "4.2.0"
3
+ RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'wagon_rails/version'
2
+ require 'wagon_rails/generators/app_generator'
3
+ require 'wagon_rails/actions'
4
+ require 'wagon_rails/app_builder'
@@ -0,0 +1,42 @@
1
+ source "https://rubygems.org"
2
+ source "https://rails-assets.org"
3
+
4
+ ruby "<%= WagonRails::RUBY_VERSION %>"
5
+
6
+ gem "rails", "<%= WagonRails::RAILS_VERSION %>"
7
+ gem "pg"
8
+ gem "figaro"
9
+ gem "simple_form"
10
+ gem "country_select"
11
+ gem "high_voltage"
12
+ gem "devise"
13
+ gem "pundit"
14
+ gem "paperclip"
15
+ gem "aws-sdk"
16
+
17
+ gem "jquery-rails"
18
+ gem "sass-rails", "~> 5.0"
19
+ gem "uglifier"
20
+ gem "bootstrap-sass"
21
+ gem "font-awesome-sass"
22
+
23
+ gem "rails-i18n"
24
+ gem "devise-i18n"
25
+ gem "devise-i18n-views"
26
+
27
+ group :development, :test do
28
+ gem "spring"
29
+ gem "annotate"
30
+ gem "binding_of_caller"
31
+ gem "better_errors"
32
+ gem "quiet_assets"
33
+ gem "pry-byebug"
34
+ gem "pry-rails"
35
+ gem "letter_opener"
36
+ end
37
+
38
+ group :production do
39
+ gem "rails_12factor"
40
+ gem "puma"
41
+ gem "rack-timeout"
42
+ end
@@ -0,0 +1 @@
1
+ web: bundle exec puma -C config/puma.rb
@@ -0,0 +1,32 @@
1
+ # <%= app_name.humanize %>
2
+
3
+ ## Getting Started
4
+
5
+ After you have cloned this repo, run this setup script to set up your machine
6
+ with the necessary dependencies to run and test this app:
7
+
8
+ % ./bin/setup
9
+
10
+ It assumes you have a machine equipped with Ruby, Postgres, etc. If not, set up
11
+ your machine with [this script].
12
+
13
+ [this script]: https://github.com/thoughtbot/laptop
14
+
15
+ After setting up, you can run the application using [foreman]:
16
+
17
+ % foreman start
18
+
19
+ If you don't have `foreman`, see [Foreman's install instructions][foreman]. It
20
+ is [purposefully excluded from the project's `Gemfile`][exclude].
21
+
22
+ [foreman]: https://github.com/ddollar/foreman
23
+ [exclude]: https://github.com/ddollar/foreman/pull/437#issuecomment-41110407
24
+
25
+ ## Guidelines
26
+
27
+ Use the following guides for getting things done, programming well, and
28
+ programming in style.
29
+
30
+ * [Protocol](http://github.com/thoughtbot/guides/blob/master/protocol)
31
+ * [Best Practices](http://github.com/thoughtbot/guides/blob/master/best-practices)
32
+ * [Style](http://github.com/thoughtbot/guides/blob/master/style)
@@ -0,0 +1,18 @@
1
+ <div class="container">
2
+ <div class="row">
3
+ <div class="col-xs-12">
4
+ <% if notice %>
5
+ <div class="alert alert-info alert-dismissible" role="alert">
6
+ <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
7
+ <%= notice %>
8
+ </div>
9
+ <% end %>
10
+ <% if alert %>
11
+ <div class="alert alert-warning alert-dismissible" role="alert">
12
+ <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
13
+ <%= alert %>
14
+ </div>
15
+ <% end %>
16
+ </div>
17
+ </div>
18
+ </div>
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.before(:each) do
3
+ ActionMailer::Base.deliveries.clear
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require bootstrap-sprockets
4
+
5
+ //= require_tree ./app
6
+
7
+
8
+ // Please do not put any code in here. Create a new .js file in
9
+ // app/assets/javascripts/app instead, and put your code there
@@ -0,0 +1,6 @@
1
+ # This file is not versioned by git, so not shared on GitHub
2
+ # If you add something here, inform your colleagues over a **secure** channel.
3
+
4
+ S3_BUCKET_NAME: "TODO"
5
+ AWS_ACCESS_KEY_ID: "TODO"
6
+ AWS_SECRET_ACCESS_KEY: "TODO"
@@ -0,0 +1,26 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ before_filter :authenticate_user!, unless: :pages_controller?
4
+
5
+ include Pundit
6
+ protect_from_forgery
7
+ after_action :verify_authorized, except: :index, unless: :devise_or_pages_controller?
8
+ after_action :verify_policy_scoped, only: :index, unless: :devise_or_pages_controller?
9
+
10
+ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
11
+
12
+ private
13
+
14
+ def user_not_authorized
15
+ flash[:error] = I18n.t('controllers.application.user_not_authorized', default: "You can't access this page.")
16
+ redirect_to(tracks_path)
17
+ end
18
+
19
+ def devise_or_pages_controller?
20
+ devise_controller? || pages_controller?
21
+ end
22
+
23
+ def pages_controller?
24
+ controller_name == "pages" # Brought by the `high_voltage` gem
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ # Run this script to deploy the app to Heroku.
4
+
5
+ set -e
6
+
7
+ git push heroku master
8
+ heroku run rake db:migrate
9
+ heroku restart
@@ -0,0 +1,13 @@
1
+ search:
2
+ paths:
3
+ - "app/controllers"
4
+ - "app/helpers"
5
+ - "app/presenters"
6
+ - "app/views"
7
+
8
+ ignore_unused:
9
+ - activerecord.*
10
+ - date.*
11
+ - simple_form.*
12
+ - time.*
13
+ - titles.*
@@ -0,0 +1,16 @@
1
+ <div class="container">
2
+ <div class="row">
3
+ <div class="col-sm-6 col-sm-offset-3">
4
+ <h2><%= t('.sign_up', default: "Sign up") %></h2>
5
+ <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
6
+ <%= f.error_notification %>
7
+
8
+ <%= f.input :email, required: true, autofocus: true %>
9
+ <%= f.input :password, required: true %>
10
+ <%= f.button :submit, t('.sign_up', default: "Sign up"), class: "btn btn-primary" %>
11
+ <% end %>
12
+
13
+ <%= render "devise/shared/links" %>
14
+ </div>
15
+ </div>
16
+ </div>
@@ -0,0 +1,16 @@
1
+ <div class="container">
2
+ <div class="row">
3
+ <div class="col-xs-12 col-sm-6 col-sm-offset-3">
4
+ <h2><%= t(".sign_in", default: "Sign in") %></h2>
5
+
6
+ <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
7
+ <%= f.input :email, required: false, autofocus: true %>
8
+ <%= f.input :password, required: false %>
9
+ <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
10
+ <%= f.button :submit, t(".sign_in", default: "Sign in"), class: "btn btn-primary" %>
11
+ <% end %>
12
+
13
+ <%= render "devise/shared/links" %>
14
+ </div>
15
+ </div>
16
+ </div>
@@ -0,0 +1,3 @@
1
+ # Protect against injection attacks
2
+ # http://www.kb.cert.org/vuls/id/380039
3
+ ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
@@ -0,0 +1,34 @@
1
+ require "net/http"
2
+ require "net/smtp"
3
+
4
+ # Example:
5
+ # begin
6
+ # some http call
7
+ # rescue *HTTP_ERRORS => error
8
+ # notify_hoptoad error
9
+ # end
10
+
11
+ HTTP_ERRORS = [
12
+ EOFError,
13
+ Errno::ECONNRESET,
14
+ Errno::EINVAL,
15
+ Net::HTTPBadResponse,
16
+ Net::HTTPHeaderSyntaxError,
17
+ Net::ProtocolError,
18
+ Timeout::Error
19
+ ]
20
+
21
+ SMTP_SERVER_ERRORS = [
22
+ IOError,
23
+ Net::SMTPAuthenticationError,
24
+ Net::SMTPServerBusy,
25
+ Net::SMTPUnknownError,
26
+ TimeoutError
27
+ ]
28
+
29
+ SMTP_CLIENT_ERRORS = [
30
+ Net::SMTPFatalError,
31
+ Net::SMTPSyntaxError
32
+ ]
33
+
34
+ SMTP_ERRORS = SMTP_SERVER_ERRORS + SMTP_CLIENT_ERRORS
@@ -0,0 +1,4 @@
1
+ HighVoltage.configure do |config|
2
+ config.home_page = 'home'
3
+ config.route_drawer = HighVoltage::RouteDrawers::Root
4
+ end
@@ -0,0 +1 @@
1
+ ActiveSupport::JSON::Encoding.time_precision = 0
@@ -0,0 +1,8 @@
1
+ Paperclip::Attachment.default_options[:storage] = :s3
2
+ Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
3
+ Paperclip::Attachment.default_options[:path] = '/:rails_env/:class/:attachment/:id_partition/:style/:filename'
4
+ Paperclip::Attachment.default_options[:s3_credentials] = {
5
+ bucket: ENV['S3_BUCKET_NAME'], # \
6
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'], # |- DO NOT replace this
7
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] # /
8
+ }
@@ -0,0 +1,12 @@
1
+ development: &default
2
+ adapter: postgresql
3
+ database: <%= app_name %>_development
4
+ encoding: utf8
5
+ host: localhost
6
+ min_messages: warning
7
+ pool: 5
8
+ timeout: 5000
9
+
10
+ test:
11
+ <<: *default
12
+ database: <%= app_name %>_test
data/templates/puma.rb ADDED
@@ -0,0 +1,15 @@
1
+ workers Integer(ENV['WEB_CONCURRENCY'] || 2)
2
+ threads_count = Integer(ENV['MAX_THREADS'] || 5)
3
+ threads threads_count, threads_count
4
+
5
+ preload_app!
6
+
7
+ rackup DefaultRackup
8
+ port ENV['PORT'] || 3000
9
+ environment ENV['RACK_ENV'] || 'development'
10
+
11
+ on_worker_boot do
12
+ # Worker specific setup for Rails 4.1+
13
+ # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
14
+ ActiveRecord::Base.establish_connection
15
+ end
@@ -0,0 +1,3 @@
1
+ if defined?(Rack::Timeout)
2
+ Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 25).to_i
3
+ end
data/templates/smtp.rb ADDED
@@ -0,0 +1,8 @@
1
+ ActionMailer::Base.smtp_settings = {
2
+ :port => '587',
3
+ :address => 'smtp.mandrillapp.com',
4
+ :user_name => ENV['MANDRILL_USERNAME'],
5
+ :password => ENV['MANDRILL_APIKEY'],
6
+ :domain => 'heroku.com',
7
+ :authentication => :plain
8
+ }
@@ -0,0 +1,12 @@
1
+ !.keep
2
+ *.DS_Store
3
+ *.swo
4
+ *.swp
5
+ /.bundle
6
+ /.foreman
7
+ /log/*
8
+ /public/system
9
+ /public/assets
10
+ /tags
11
+ /tmp/*
12
+ /config/application.yml
@@ -0,0 +1,28 @@
1
+ <%= content_for(:title) do %>
2
+ Home
3
+ <% end %>
4
+
5
+ <%= content_for(:description) do %>
6
+ <%# TODO %>
7
+ <% end %>
8
+
9
+ <div class="container">
10
+ <div class="row">
11
+ <div class="col-xs-12 col-sm-8 col-sm-offset-2">
12
+ <h1>Welcome!</h1>
13
+
14
+ <h2>This is the homepage</h2>
15
+
16
+ <p>
17
+ Find me in <code>app/views/pages/home.html.erb</code>
18
+ </p>
19
+
20
+ <p>
21
+ Thanks to the <a href="https://github.com/thoughtbot/high_voltage">high_voltage</a>
22
+ gem, if you need more static pages (like <code>/contact</code> or <code>/about-us</code>),
23
+ just create a file in the <code>app/views/pages</code> folder, the route will be automatically
24
+ available without you adding any controller or touching the <code>config/routes.rb</code> file!
25
+ </p>
26
+ </div>
27
+ </div>
28
+ </div>
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%%= yield(:title) || "Wagon Rails" %></title>
5
+ <meta name="description" content="<%%= (yield(:description) || "").squish %>">
6
+
7
+ <meta charset="utf-8" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10
+ <%%= stylesheet_link_tag :application, media: "all" %>
11
+ <%%= csrf_meta_tags %>
12
+ </head>
13
+ <body>
14
+ <%%= render "shared/navbar" %>
15
+ <%%= render "shared/flashes" %>
16
+
17
+ <%%= yield %>
18
+
19
+ <%%= javascript_include_tag :application %>
20
+ <%%= yield(:after_js) %>
21
+
22
+ </body>
23
+ </html>
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'wagon_rails/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{WagonRails::RUBY_VERSION}"
8
+ s.authors = ['ssaunier']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ WagonRails is a base Rails project with all the best practises and gems
13
+ taught at Le Wagon's FullStack Bootcamp. Students can jump start their
14
+ project without losing one day to set up everything.
15
+ HERE
16
+
17
+ s.email = 'seb@lewagon_rails'
18
+ s.executables = ['wagon_rails']
19
+ s.extra_rdoc_files = %w[README.md LICENSE]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'https://github.com/lewagon/wagon_rails'
22
+ s.license = 'MIT'
23
+ s.name = 'wagon_rails'
24
+ s.rdoc_options = ['--charset=UTF-8']
25
+ s.require_paths = ['lib']
26
+ s.summary = "Generate a Rails app using Le Wagon's best practices (FullStack Bootcamp)"
27
+ # s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.version = WagonRails::VERSION
29
+
30
+ s.add_dependency 'bundler', '~> 1.3'
31
+ s.add_dependency 'rails', WagonRails::RAILS_VERSION
32
+
33
+ # s.add_development_dependency 'rspec', '~> 2.0'
34
+ # s.add_development_dependency 'capybara', '~> 2.2', '>= 2.2.0'
35
+ end