autopilot-rails 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f1263c2b13ad874e16683c2592423a3f8c16fe2faaff652df9d58874228d1ad
4
+ data.tar.gz: c5521addd46867b05042f1d34f396ab9e5d493ec799444b63630585c532657d1
5
+ SHA512:
6
+ metadata.gz: 5fe3a57ef797c27e2f65b6e48dbabe94c9c6ffddf212a60518ffa8f984fcb594a382e0d0af3d51d651055e32aefc9dcd317cc4447517ce9db7f20f7d1d3e6c74
7
+ data.tar.gz: 969a72f022ec58114b76762124b6aa35575228ba73c99ac71496eb060c9153eee75ff3791c5f6b0c2dc9ade80cb36b90d60ac18c274d79cd730d3a2091fa75e6
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Dylan Feltus
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.
@@ -0,0 +1,42 @@
1
+ # Autopilot Rails
2
+
3
+ _⚠️ This project is still a WIP. It currently works with a limited set of features._
4
+
5
+ Ship your next SaaS product in hours, not days or weeks.
6
+
7
+ This gem will help you to scaffold your next project. Currently it will add:
8
+ - Users with authentication via Devise
9
+ - Accounts with devise_invitable
10
+ - Super admin area with ActiveAdmin
11
+ - Default routes and pages
12
+
13
+ More features coming soon:
14
+ - User roles & permissions
15
+ - Stripe billing with optional annual plans
16
+ - Feature flipper for super admins
17
+ - UI themes
18
+
19
+ ## Install
20
+
21
+ To install Autopilot, simply add the gem to your Gemfile:
22
+ `gem 'autopilot', git: 'https://github.com/stratuslabs/autopilot.git'`
23
+
24
+ ## Usage
25
+
26
+ To generate a project run `rails generate autopilot:go` to get started. The generator will ask a few questions to customize the output.
27
+
28
+ | Option | Description |
29
+ | --- | --- |
30
+ | Do you want to have multiple users per account? | This will add an Account model, some account related helpers, and [Devise Invitable](https://github.com/scambra/devise_invitable). You will also get a `account/users` page with a list of users and the invite form. |
31
+ | Do you want to include ActiveAdmin? | This will install ActiveAdmin with a few extra features like "Log in as user" and an account growth chart. |
32
+ | Do you want to include a home page? | This will add a blank html page and set it as your unauthenticated root path. When set to false your log in page will be the root. |
33
+
34
+ ## Starting from scratch
35
+
36
+ Here are some instructions to help you start a Rails app from scratch:
37
+
38
+ - rails new example --database=postgresql
39
+ - ~~Add config~~
40
+ - gem 'autopilot', git: 'https://github.com/stratuslabs/autopilot.git'
41
+ - `bundle install`
42
+ - Set up database
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Autopilot'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,4 @@
1
+ require "autopilot/railtie"
2
+
3
+ module Autopilot
4
+ end
@@ -0,0 +1,44 @@
1
+ module Autopilot
2
+ module Generators
3
+ class AccountsGenerator < Rails::Generators::Base
4
+ desc "Generate Account model with devise_invitable"
5
+ source_root File.expand_path("../../../templates", __FILE__)
6
+
7
+ def do_magic
8
+ puts "Setting up multiple users per accounts"
9
+
10
+ gem 'devise_invitable', '~> 2.0.0'
11
+ Bundler.with_clean_env do
12
+ run "bundle install"
13
+ end
14
+ generate "devise_invitable:install"
15
+ generate "devise_invitable User"
16
+
17
+ generate "model Account"
18
+ template "account.rb", "app/models/account.rb", force: true
19
+ template "user.rb", "app/models/user.rb", force: true
20
+
21
+ copy_file "controllers/accounts_controller.rb", "app/controllers/accounts_controller.rb", force: true
22
+ copy_file "controllers/application_controller.rb", "app/controllers/application_controller.rb", force: true
23
+
24
+ route "get 'account/users', to: 'accounts#users', as: :account_users"
25
+ route "post 'account/send_user_invite' => 'accounts#send_user_invite', as: :send_user_invite"
26
+ copy_file "views/accounts/users.html.erb", "app/views/accounts/users.html.erb"
27
+
28
+ inject_into_file 'app/views/layouts/_nav.html.erb', after: "dash_path %>\n" do <<-'RUBY'
29
+ <%= link_to "Users", account_users_path %>
30
+ RUBY
31
+ end
32
+
33
+ inject_into_file 'config/environments/development.rb', after: "Rails.application.configure do\n" do <<-'RUBY'
34
+ config.action_mailer.default_url_options = { :host => 'localhost' }
35
+ RUBY
36
+ end
37
+
38
+ generate "migration AddAccountToUsers account:references"
39
+ generate "migration AddOwnerIdToAccounts owner_id:integer"
40
+ generate "migration AddDeletedAtToAccounts deleted_at:datetime:index"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ module Autopilot
2
+ module Generators
3
+ class AdminGenerator < Rails::Generators::Base
4
+ desc "Add ActiveAdmin to your project"
5
+
6
+ def do_magic
7
+ puts "Set up active admin"
8
+
9
+ gem "activeadmin"
10
+ Bundler.with_clean_env do
11
+ run "bundle install"
12
+ end
13
+ generate "active_admin:install"
14
+ run "db:migrate"
15
+ run "db:seed"
16
+
17
+ puts "Admin account generated:"
18
+ puts "Email: admin@example.com"
19
+ puts "Password: password"
20
+ puts "Access your admin account at /admin"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module Autopilot
2
+ module Generators
3
+ class ExampleGenerator < Rails::Generators::Base
4
+ desc "WIP: Generate example Post and Comment model"
5
+
6
+ def do_magic
7
+ puts "Adding an example model..."
8
+ # TODO
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,44 @@
1
+ module Autopilot
2
+ module Generators
3
+ class GoGenerator < Rails::Generators::Base
4
+ desc "This generator will create your app based on the answers you provide."
5
+
6
+ def do_magic
7
+
8
+ if yes?("Do you want to have multiple users per account? [y|n]")
9
+ include_accounts = true
10
+ else
11
+ include_accounts = false
12
+ end
13
+
14
+ if yes?("Do you want to include ActiveAdmin? [y|n]")
15
+ include_admin = true
16
+ else
17
+ include_admin = false
18
+ end
19
+
20
+ if yes?("Do you want to include a home page? [y|n]")
21
+ include_home = true
22
+ else
23
+ include_home = false
24
+ end
25
+
26
+ gem "paranoia", "~> 2.2"
27
+
28
+ generate "autopilot:users"
29
+ generate "autopilot:routes #{include_home ? '--home' : nil}"
30
+
31
+ if include_accounts
32
+ generate "autopilot:accounts"
33
+ end
34
+
35
+ if include_admin
36
+ generate "autopilot:admin"
37
+ end
38
+
39
+ rake "db:migrate"
40
+ run "rails s"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ module Autopilot
2
+ module Generators
3
+ class RoutesGenerator < Rails::Generators::Base
4
+ desc "Generate basic routes and pages"
5
+ class_option :home, type: :boolean
6
+ source_root File.expand_path("../../../templates", __FILE__)
7
+
8
+ def do_magic
9
+ puts "Setting up routes..."
10
+ @home = options['home']
11
+
12
+ template "controllers/pages_controller.rb", "app/controllers/pages_controller.rb"
13
+ template "views/pages/dash.html.erb", "app/views/pages/dash.html.erb"
14
+ copy_file "views/layouts/_nav.html.erb", "app/views/layouts/_nav.html.erb"
15
+
16
+ inject_into_file 'app/views/layouts/application.html.erb', after: "<body>\n" do <<-'RUBY'
17
+ <%= render 'layouts/nav' %>
18
+ RUBY
19
+ end
20
+
21
+ if @home
22
+ puts "Set up marketing home page..."
23
+
24
+ template "views/pages/home.html.erb", "app/views/pages/home.html.erb"
25
+ template "routes-with-home.rb", "config/routes.rb", force: true
26
+
27
+ inject_into_file 'app/views/layouts/_nav.html.erb', after: "<% else %>\n" do <<-'RUBY'
28
+ <%= link_to "Home", root_path %>
29
+ RUBY
30
+ end
31
+ else
32
+ template "routes-without-home.rb", "config/routes.rb", force: true
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ module Autopilot
2
+ module Generators
3
+ class UsersGenerator < Rails::Generators::Base
4
+ desc "Generate User model with Devise"
5
+
6
+ def do_magic
7
+ puts "Setting up users & authentication..."
8
+ gem "devise"
9
+ Bundler.with_clean_env do
10
+ run "bundle install"
11
+ end
12
+ generate "devise:install"
13
+ generate "devise User"
14
+ generate "devise:views"
15
+ generate "migration AddDeletedAtToUsers deleted_at:datetime:index"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class Account < ApplicationRecord
2
+ acts_as_paranoid
3
+ has_many :users, dependent: :destroy
4
+ accepts_nested_attributes_for :users
5
+ end
@@ -0,0 +1,26 @@
1
+ class AccountsController < ApplicationController
2
+ before_action :authenticate_user!
3
+
4
+ def users
5
+ @users = current_account.users.all
6
+ end
7
+
8
+ def send_user_invite
9
+ email = params[:user][:email]
10
+
11
+ if User.only_deleted.where(email: email).any?
12
+ user = User.only_deleted.where(email: email).first
13
+ if user.deleted_at
14
+ user.restore
15
+ user.update(account: current_account)
16
+ user.invite!(user)
17
+ end
18
+ else
19
+ User.invite!(email: email, account: current_account)
20
+ end
21
+
22
+ respond_to do |format|
23
+ format.html { redirect_to account_users_path, notice: 'Invite sent successfully' }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ def current_account
4
+ current_user.account
5
+ end
6
+ helper_method :current_account
7
+
8
+ end
@@ -0,0 +1,10 @@
1
+ class PagesController < ApplicationController
2
+ before_action :authenticate_user!, only: :dash
3
+
4
+ def show
5
+ render template: "pages/#{params[:page]}"
6
+ end
7
+
8
+ def dash
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ Rails.application.routes.draw do
2
+ devise_for :users
3
+
4
+ authenticated :user do
5
+ root "pages#dash", as: :authenticated_root
6
+ end
7
+
8
+ devise_scope :user do
9
+ get "join", to: "devise/registrations#new"
10
+ get "login", to: "devise/sessions#new"
11
+ get "logout", to: "devise/sessions#destroy"
12
+ root to: 'pages#home'
13
+ end
14
+
15
+ get "/dash", to: "pages#dash", as: :dash
16
+ end
@@ -0,0 +1,16 @@
1
+ Rails.application.routes.draw do
2
+ devise_for :users
3
+
4
+ authenticated :user do
5
+ root "pages#dash", as: :authenticated_root
6
+ end
7
+
8
+ devise_scope :user do
9
+ get "join", to: "devise/registrations#new"
10
+ get "login", to: "devise/sessions#new"
11
+ get "logout", to: "devise/sessions#destroy"
12
+ root to: 'devise/sessions#new'
13
+ end
14
+
15
+ get "/dash", to: "pages#dash", as: :dash
16
+ end
@@ -0,0 +1,25 @@
1
+ class User < ApplicationRecord
2
+ acts_as_paranoid
3
+ devise :database_authenticatable, :registerable, :recoverable,
4
+ :rememberable, :validatable, :invitable
5
+
6
+ belongs_to :account, optional: true
7
+
8
+ validates_uniqueness_of :email
9
+
10
+ after_create :create_account, unless: :invited_to_sign_up?
11
+
12
+ def is_pending
13
+ owner = Account.find(self.account_id).users.first
14
+ true unless self.invitation_accepted_at || self == owner
15
+ end
16
+
17
+ private
18
+
19
+ def create_account
20
+ if self.account_id.nil?
21
+ account = Account.create(owner_id: self.id)
22
+ self.update(account: account)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ <h1>Users</h1>
2
+
3
+ <% @users.each do |u| %>
4
+ <div class="user" style="display: flex; border: 1px solid lightgrey; padding: 10px; margin-bottom: 15px;">
5
+ <p><%= u.email %></p>
6
+ <% if u.is_pending %>
7
+ <p class="pending">
8
+ Invite is pending.
9
+ <%= link_to "Resend", {
10
+ controller: 'accounts',
11
+ action: 'send_user_invite',
12
+ user: { email: u.email },
13
+ }, method: :post %>
14
+ </p>
15
+ <% end %>
16
+ </div>
17
+ <% end %>
18
+
19
+ <h3>Invite your team</h3>
20
+ <%= form_for [current_account, User.new], url: { action: "send_user_invite" } do |f| %>
21
+ <%= f.label :email, "Email address" %>
22
+ <%= f.text_field :email, placeholder: "example@gmail.com", required: true %>
23
+ <%= f.submit "Send invite" %>
24
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <nav>
2
+ <% if current_user %>
3
+ <%= link_to "Dash", dash_path %>
4
+ <%= link_to "Log out", destroy_user_session_path, method: :delete %>
5
+ <% else %>
6
+ <%= link_to "Log in", new_user_session_path %>
7
+ <%= link_to "Create an account", new_user_registration_path %>
8
+ <% end %>
9
+ </nav>
@@ -0,0 +1,2 @@
1
+ <h1>Dashboard</h1>
2
+ <p>Welcome to your new application!</p>
@@ -0,0 +1,2 @@
1
+ <h3>Hello world!</h3>
2
+ <p>Welcome to your generated project! This is your home page for logged out users.</p>
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autopilot-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Feltus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.2.1
33
+ description: With Autopilot for Rails you can generate a starting point for your next
34
+ SaaS project. Add accounts with multiple users, Stripe billing, permissions, onboarding
35
+ flows, and more.
36
+ email:
37
+ - contact@dylanfeltus.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - MIT-LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - lib/autopilot.rb
46
+ - lib/generators/autopilot/accounts_generator.rb
47
+ - lib/generators/autopilot/admin_generator.rb
48
+ - lib/generators/autopilot/example_generator.rb
49
+ - lib/generators/autopilot/go_generator.rb
50
+ - lib/generators/autopilot/routes_generator.rb
51
+ - lib/generators/autopilot/users_generator.rb
52
+ - lib/templates/account.rb
53
+ - lib/templates/controllers/accounts_controller.rb
54
+ - lib/templates/controllers/application_controller.rb
55
+ - lib/templates/controllers/pages_controller.rb
56
+ - lib/templates/routes-with-home.rb
57
+ - lib/templates/routes-without-home.rb
58
+ - lib/templates/user.rb
59
+ - lib/templates/views/accounts/users.html.erb
60
+ - lib/templates/views/layouts/_nav.html.erb
61
+ - lib/templates/views/pages/dash.html.erb
62
+ - lib/templates/views/pages/home.html.erb
63
+ homepage: https://github.com/stratuslabs/autopilot
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.7.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Generate your next SaaS app using Rails
87
+ test_files: []