bootup 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bootup
2
2
 
3
- Provides a rails generator which installs a few useful gems & sets up authentication using sorcery along with scaffolding.
3
+ Provides a rails generator to install a few useful gems & set up authentication along with scaffolding.
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,3 +1,3 @@
1
1
  module Bootup
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,52 @@
1
+ module HelperMethods
2
+ def setup_authentication
3
+ @model = ask("\n\n What would you like to call your user model? Default: User", :blue)
4
+ @model = "user" if @model.blank?
5
+ @model = @model.downcase.singularize
6
+ @models = @model.pluralize
7
+
8
+ log :bootup_log, "Installing Sorcery"
9
+ generate "sorcery:install --model #{@model.classify}"
10
+
11
+
12
+ log :bootup_log, "Copying models and migrations"
13
+
14
+ case @db
15
+ when 'mongoid'
16
+ template "authentication/models/user_mongoid.rb.erb", "app/models/#{@model}.rb"
17
+ inside Rails.root do
18
+ run "rm db/migrate/*"
19
+ end
20
+ else
21
+ template "authentication/models/user_others.rb.erb", "app/models/#{@model}.rb"
22
+ rake("db:migrate")
23
+ end
24
+
25
+ log :bootup_log, "Copying controllers"
26
+ template "authentication/controllers/users_controller.rb.erb", "app/controllers/#{@models}_controller.rb"
27
+ template "authentication/controllers/user_sessions_controller.rb.erb", "app/controllers/#{@model}_sessions_controller.rb"
28
+ copy_file "authentication/controllers/pages_controller.rb", "app/controllers/pages_controller.rb"
29
+ copy_file "authentication/controllers/application_controller.rb", "app/controllers/application_controller.rb"
30
+
31
+ log :bootup_log, "Copying views"
32
+ directory "authentication/views", "app/views"
33
+ unless @model.blank?
34
+ inside Rails.root do
35
+ run "mv app/views/user_sessions app/views/#{@model}_sessions"
36
+ run "mv app/views/users app/views/#{@models}"
37
+ end
38
+ end
39
+
40
+ log :bootup_log, "Copying initializers"
41
+ template "authentication/sorcery.rb.erb", "config/initializers/sorcery.rb"
42
+
43
+ log :bootup_log, "Copying initializers"
44
+ template "authentication/routes.rb.erb", "config/routes.rb"
45
+
46
+ inside Rails.root do
47
+ run "git add ."
48
+ run "git commit -am 'Authentication with sorcery.'"
49
+ end
50
+ say "\n\n An application with basic authentication has been created for you. Start thin server by typing 'rails s' in your command line. Point your browser to localhost:3000 to see the application.\n\n", :green
51
+ end
52
+ end
@@ -1,134 +1,51 @@
1
1
  class BootupGenerator < Rails::Generators::Base
2
+ require_relative 'authentication'
3
+ require_relative 'methods'
4
+
5
+ include HelperMethods
6
+
2
7
  source_root File.expand_path('../templates', __FILE__)
3
8
  argument :app_name, type: :string, default: Rails.application.class.parent
4
9
 
5
10
  def generate_bootup
6
11
  log :bootup, "Booting #{app_name}......"
7
12
 
8
- db = ask("\n\nWhat database would you like to start off with? P-Postgres / M-Mongoid / Default-SQLite", :blue)
9
- case db
10
- when "P","p"
11
- @db = 'postgres'
12
- when "M","m"
13
- @db = 'mongoid'
14
- else
15
- @db = 'sqlite'
16
- end
17
-
18
- log :bootup_log, "Copying Gemfile"
19
- template "Gemfile.erb", "Gemfile"
13
+ #Get database from User
14
+ @db = fetch_database
20
15
 
21
- log :bootup_log, "Running Bundler"
22
- Bundler.with_clean_env do
23
- run "bundle install"
24
- end
16
+ #Setup & bundle the Gemfile
17
+ setup_gems
25
18
 
26
19
  log :bootup_log, "Removing public/index.."
27
20
  inside Rails.root do
28
21
  run "rm public/index.html"
29
22
  end
30
23
 
31
- if @db == 'postgres'
32
- @username = ask("\n\nPlease enter you postgres username", :blue)
33
- @password = ask("\n\nPlease enter you postgres password. Leave blank if not applicable", :blue)
34
- log :bootup_log, "Initializing database.yml"
35
- template 'database.yml.erb', 'config/database.yml'
36
-
37
- log :bootup_log, "Creating database"
38
- rake("db:create")
39
- elsif @db == 'mongoid'
40
- log :bootup_log, "Generating Mongoid config"
41
- generate "mongoid:config"
42
- end
24
+ #For postgres databases, a username password needs to be part of database.yml. This data needs to come from the user. For mongoid, the mongoid:config generator is run
25
+ @db == 'postgres' ? create_postgres : create_mongoid
43
26
 
44
-
45
- log :bootup_log, "Installing Twitter Bootstrap"
46
- generate "bootstrap:install"
47
-
48
- log :bootup_log, "Copy application.js & initialize datatables to #datatables - Remember to change sorting"
49
- copy_file "application.js", "app/assets/javascripts/application.js"
50
-
51
- log :bootup_log, "Copying stylesheets"
52
- copy_file "application.css", "app/assets/stylesheets/application.css"
53
-
54
- log :bootup_log, "Installing Simple Form"
55
- generate "simple_form:install --bootstrap"
27
+ #Run generators for all view related gems
28
+ setup_view_stuff
56
29
 
57
30
  tests = ask("\n\n Would you like to get rid of the default testing framework & install Rspec with Guard?", :blue)
58
31
  if %w(y yes).include? tests
59
- log :bootup_log, "Removing Tests.."
60
- inside Rails.root do
61
- run "rm -rf test/"
62
- end
63
-
64
- log :bootup_log, "Setting up Rspec.."
65
- generate "rspec:install"
66
-
67
- log :bootup_log, "Setting up Guard with a custom guardfile.."
68
- copy_file "Guardfile", "Guardfile"
69
-
70
- log :bootup_log, "Setting up spork"
71
- copy_file "spec_helper.rb", "spec/spec_helper.rb"
32
+ #Setup Rspec & Guard
33
+ setup_testing
72
34
  else
73
35
  log :bootup_log, "Skipping removal of tests"
74
36
  end
75
- log :bootup_log, "Initializing git repo"
76
- inside Rails.root do
77
- run "git init"
78
- end
79
- copy_file ".gitignore", "spec/spec_helper.rb"
80
- inside Rails.root do
81
- run "git add ."
82
- run "git commit -m 'Initial Commit'"
83
- end
84
-
85
- auth = ask("\n\n Would you like authentication & related scaffolding to be setup?", :blue)
86
-
87
- if %w(Y y Yes YES yes).include? auth
88
- @model = ask("\n\n What would you like to call your user model? Default: User", :blue)
89
- @model = "user" if @model.blank?
90
- @model = @model.downcase.singularize
91
- @models = @model.pluralize
92
37
 
93
- log :bootup_log, "Installing Sorcery"
94
- generate "sorcery:install"
38
+ #Git init, git add & git commit
39
+ first_commit
95
40
 
41
+ auth = ask("\n\n Would you like Bootup to create an application with basic authentication to start off with?", :blue)
96
42
 
97
- log :bootup_log, "Copying models and migrations"
98
-
99
- case @db
100
- when 'mongoid'
101
- template "authentication/models/user_mongoid.rb.erb", "app/models/#{@model}.rb"
102
- inside Rails.root do
103
- run "rm db/migrate/*"
104
- end
105
- else
106
- template "authentication/models/user_others.rb.erb", "app/models/#{@model}.rb"
107
- rake("db:migrate")
108
- end
109
-
110
- log :bootup_log, "Copying controllers"
111
- template "authentication/controllers/users_controller.rb.erb", "app/controllers/#{@models}_controller.rb"
112
- template "authentication/controllers/user_sessions_controller.rb.erb", "app/controllers/#{@model}_sessions_controller.rb"
113
- copy_file "authentication/controllers/pages_controller.rb", "app/controllers/pages_controller.rb"
114
- copy_file "authentication/controllers/application_controller.rb", "app/controllers/application_controller.rb"
115
-
116
- log :bootup_log, "Copying views"
117
- directory "authentication/views", "app/views"
118
-
119
- log :bootup_log, "Copying initializers"
120
- copy_file "authentication/sorcery.rb", "config/initializers/sorcery.rb"
121
-
122
- log :bootup_log, "Copying initializers"
123
- template "authentication/routes.rb.erb", "config/routes.rb"
124
-
125
- inside Rails.root do
126
- run "git add ."
127
- run "git commit -am 'Authentication with sorcery.'"
128
- end
43
+ if %w(Y y Yes YES yes).include? auth
44
+ #This sets a complete web application with authentication
45
+ setup_authentication
129
46
  end
130
47
 
131
- log :Installation_complete, "\n\n\n Installation Complete! Hope you saved some time. \n\n\n"
48
+ say "\n Installation complete! Hope bootup helped you save some time. \n\n\n", :green
132
49
  end
133
50
  end
134
51
 
@@ -0,0 +1,84 @@
1
+ module HelperMethods
2
+
3
+ def fetch_database
4
+ db = ask("\n\nWhat database would you like to start off with? P-Postgres / M-Mongoid / Default-SQLite", :blue)
5
+ case db
6
+ when "P","p"
7
+ 'postgres'
8
+ when "M","m"
9
+ 'mongoid'
10
+ else
11
+ 'sqlite'
12
+ end
13
+ end
14
+
15
+ def create_postgres
16
+ @username = ask("\n\nPlease enter you postgres username", :blue)
17
+ @password = ask("\n\nPlease enter you postgres password. Leave blank if not applicable", :blue)
18
+ log :bootup_log, "Initializing database.yml"
19
+ template 'database.yml.erb', 'config/database.yml'
20
+
21
+ log :bootup_log, "Creating database"
22
+ rake("db:create")
23
+ end
24
+
25
+ def create_mongoid
26
+ unless @db == "sqlite"
27
+ log :bootup_log, "Generating Mongoid config"
28
+ generate "mongoid:config"
29
+ end
30
+ end
31
+
32
+ def setup_view_stuff
33
+ log :bootup_log, "Installing Twitter Bootstrap"
34
+ generate "bootstrap:install"
35
+
36
+ log :bootup_log, "Copy application.js & initialize datatables to #datatables - Remember to change sorting"
37
+ copy_file "application.js", "app/assets/javascripts/application.js"
38
+
39
+ log :bootup_log, "Copying stylesheets"
40
+ copy_file "application.css", "app/assets/stylesheets/application.css"
41
+
42
+ log :bootup_log, "Installing Simple Form"
43
+ generate "simple_form:install --bootstrap"
44
+ end
45
+
46
+ def setup_testing
47
+ log :bootup_log, "Removing Tests.."
48
+ inside Rails.root do
49
+ run "rm -rf test/"
50
+ end
51
+
52
+ log :bootup_log, "Setting up Rspec.."
53
+ generate "rspec:install"
54
+
55
+ log :bootup_log, "Setting up Guard with a custom guardfile.."
56
+ copy_file "Guardfile", "Guardfile"
57
+
58
+ log :bootup_log, "Setting up spork"
59
+ copy_file "spec_helper.rb", "spec/spec_helper.rb"
60
+ end
61
+
62
+
63
+ def setup_gems
64
+ log :bootup_log, "Copying Gemfile"
65
+ template "Gemfile.erb", "Gemfile"
66
+
67
+ log :bootup_log, "Running Bundler"
68
+ Bundler.with_clean_env do
69
+ run "bundle install"
70
+ end
71
+ end
72
+
73
+ def first_commit
74
+ log :bootup_log, "Initializing git repo"
75
+ inside Rails.root do
76
+ run "git init"
77
+ end
78
+ copy_file ".gitignore", "spec/spec_helper.rb"
79
+ inside Rails.root do
80
+ run "git add ."
81
+ run "git commit -m 'Initial Commit'"
82
+ end
83
+ end
84
+ end
@@ -8,7 +8,7 @@ class <%= "#{@model}_sessions_controller".classify %> < ApplicationController
8
8
  def create
9
9
  respond_to do |format|
10
10
  if @user = login(params[:email],params[:password])
11
- format.html { redirect_back_or_to(@user, :notice => 'Login successful.') }
11
+ format.html { redirect_back_or_to(user_path(@user), :notice => 'Login successful.') }
12
12
  format.xml { render :xml => @user, :status => :created, :location => @user }
13
13
  else
14
14
  format.html { flash.now[:alert] = "Login failed."; render :action => "new" }
@@ -41,7 +41,7 @@ class <%= "#{@models}_controller".classify %> < ApplicationController
41
41
  # POST /users
42
42
  # POST /users.json
43
43
  def create
44
- @user = <%= @model.classify %>.new(params[:user])
44
+ @user = <%= @model.classify %>.new(params[:<%= @model %>])
45
45
  if @user.save
46
46
  reset_session
47
47
  auto_login(@user)
@@ -57,7 +57,7 @@ class <%= "#{@models}_controller".classify %> < ApplicationController
57
57
  @user = <%= @model.classify %>.find(params[:id])
58
58
 
59
59
  respond_to do |format|
60
- if @user.update_attributes(params[:user])
60
+ if @user.update_attributes(params[:<%= @model %>])
61
61
  format.html { redirect_to @user, notice: '<%= @model.classify %> was successfully updated.' }
62
62
  format.json { head :no_content }
63
63
  else
@@ -3,8 +3,8 @@
3
3
  get "pages/home"
4
4
  root :to => 'pages#home'
5
5
 
6
- resources :<%= "#{@model}_sessions" %>
7
- resources :<%= @models %>
6
+ resources :<%= "#{@model}_sessions" %>, as: :user_sessions
7
+ resources :<%= @models %>, as: :users
8
8
 
9
9
  match 'login' => '<%= "#{@model}_sessions" %>#new', :as => :login
10
10
  match 'logout' => '<%= "#{@model}_sessions" %>#destroy', :as => :logout
@@ -394,5 +394,5 @@ Rails.application.config.sorcery.configure do |config|
394
394
 
395
395
  # This line must come after the 'user config' block.
396
396
  # Define which model authenticates with sorcery.
397
- config.user_class = "User"
397
+ config.user_class = "<%= @model.classify %>"
398
398
  end
@@ -1,4 +1,4 @@
1
- <%= simple_form_for(@user) do |f| %>
1
+ <%= simple_form_for(@user, url: user_path(@user), method: :put) do |f| %>
2
2
  <%= f.error_notification %>
3
3
 
4
4
  <div class="form-inputs">
@@ -10,6 +10,6 @@
10
10
 
11
11
  <div class="form-actions">
12
12
  <%= f.button :submit, class: "btn btn-primary" %>
13
- <%= link_to 'Back', root_path, class: "btn" %>
13
+ <%= link_to 'Back', user_path(@user), class: "btn" %>
14
14
  </div>
15
15
  <% end %>
@@ -1,6 +1,5 @@
1
- <h1>Editing user</h1>
1
+ <h1>Editing User</h1>
2
+ <hr>
2
3
 
3
4
  <%= render 'form' %>
4
5
 
5
- <%= link_to 'Show', @user %> |
6
- <%= link_to 'Back', users_path %>
@@ -1,4 +1,18 @@
1
- <h1>New user</h1>
1
+ <h1>New User</h1>
2
2
  <hr>
3
- <%= render 'form' %>
4
3
 
4
+ <%= simple_form_for(@user, url: users_path(@user)) do |f| %>
5
+ <%= f.error_notification %>
6
+
7
+ <div class="form-inputs">
8
+ <%= f.input :username %>
9
+ <%= f.input :email %>
10
+ <%= f.input :password %>
11
+ <%= f.input :password_confirmation %>
12
+ </div>
13
+
14
+ <div class="form-actions">
15
+ <%= f.button :submit, class: "btn btn-primary" %>
16
+ <%= link_to 'Back', root_path, class: "btn" %>
17
+ </div>
18
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helps create a new rails app quickly
15
15
  email:
@@ -28,7 +28,9 @@ files:
28
28
  - lib/bootup/engine.rb
29
29
  - lib/bootup/version.rb
30
30
  - lib/generators/bootup/USAGE
31
+ - lib/generators/bootup/authentication.rb
31
32
  - lib/generators/bootup/bootup_generator.rb
33
+ - lib/generators/bootup/methods.rb
32
34
  - lib/generators/bootup/templates/.gitignore
33
35
  - lib/generators/bootup/templates/Gemfile.erb
34
36
  - lib/generators/bootup/templates/Guardfile
@@ -44,7 +46,7 @@ files:
44
46
  - lib/generators/bootup/templates/authentication/models/user_mongoid.rb.erb
45
47
  - lib/generators/bootup/templates/authentication/models/user_others.rb.erb
46
48
  - lib/generators/bootup/templates/authentication/routes.rb.erb
47
- - lib/generators/bootup/templates/authentication/sorcery.rb
49
+ - lib/generators/bootup/templates/authentication/sorcery.rb.erb
48
50
  - lib/generators/bootup/templates/authentication/views/layouts/application.html.erb
49
51
  - lib/generators/bootup/templates/authentication/views/pages/home.html.erb
50
52
  - lib/generators/bootup/templates/authentication/views/user_sessions/_form.html.erb