kickoff 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +1 -0
  3. data/CHANGELOG +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +20 -0
  6. data/README.md +41 -0
  7. data/Rakefile +5 -0
  8. data/features/nifty_authentication.feature +80 -0
  9. data/features/nifty_config.feature +17 -0
  10. data/features/nifty_layout.feature +20 -0
  11. data/features/nifty_scaffold.feature +80 -0
  12. data/features/step_definitions/common_steps.rb +62 -0
  13. data/features/step_definitions/rails_setup_steps.rb +6 -0
  14. data/features/support/env.rb +6 -0
  15. data/features/support/matchers.rb +7 -0
  16. data/kickoff.gemspec +24 -0
  17. data/lib/generators/kickoff/authentication/USAGE +50 -0
  18. data/lib/generators/kickoff/authentication/authentication_generator.rb +154 -0
  19. data/lib/generators/kickoff/authentication/templates/authlogic_session.rb +2 -0
  20. data/lib/generators/kickoff/authentication/templates/controller_authentication.rb +60 -0
  21. data/lib/generators/kickoff/authentication/templates/fixtures.yml +24 -0
  22. data/lib/generators/kickoff/authentication/templates/migration.rb +20 -0
  23. data/lib/generators/kickoff/authentication/templates/sessions_controller.rb +41 -0
  24. data/lib/generators/kickoff/authentication/templates/sessions_helper.rb +2 -0
  25. data/lib/generators/kickoff/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  26. data/lib/generators/kickoff/authentication/templates/tests/rspec/user.rb +83 -0
  27. data/lib/generators/kickoff/authentication/templates/tests/rspec/users_controller.rb +56 -0
  28. data/lib/generators/kickoff/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  29. data/lib/generators/kickoff/authentication/templates/tests/shoulda/user.rb +85 -0
  30. data/lib/generators/kickoff/authentication/templates/tests/shoulda/users_controller.rb +61 -0
  31. data/lib/generators/kickoff/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  32. data/lib/generators/kickoff/authentication/templates/tests/testunit/user.rb +88 -0
  33. data/lib/generators/kickoff/authentication/templates/tests/testunit/users_controller.rb +53 -0
  34. data/lib/generators/kickoff/authentication/templates/user.rb +38 -0
  35. data/lib/generators/kickoff/authentication/templates/users_controller.rb +32 -0
  36. data/lib/generators/kickoff/authentication/templates/users_helper.rb +2 -0
  37. data/lib/generators/kickoff/authentication/templates/views/erb/_form.html.erb +20 -0
  38. data/lib/generators/kickoff/authentication/templates/views/erb/edit.html.erb +3 -0
  39. data/lib/generators/kickoff/authentication/templates/views/erb/login.html.erb +30 -0
  40. data/lib/generators/kickoff/authentication/templates/views/erb/signup.html.erb +5 -0
  41. data/lib/generators/kickoff/authentication/templates/views/haml/_form.html.haml +16 -0
  42. data/lib/generators/kickoff/authentication/templates/views/haml/edit.html.haml +3 -0
  43. data/lib/generators/kickoff/authentication/templates/views/haml/login.html.haml +26 -0
  44. data/lib/generators/kickoff/authentication/templates/views/haml/signup.html.haml +5 -0
  45. data/lib/generators/kickoff/layout/USAGE +25 -0
  46. data/lib/generators/kickoff/layout/layout_generator.rb +38 -0
  47. data/lib/generators/kickoff/layout/templates/_forms.scss +417 -0
  48. data/lib/generators/kickoff/layout/templates/_mixins.scss +211 -0
  49. data/lib/generators/kickoff/layout/templates/_patterns.scss +960 -0
  50. data/lib/generators/kickoff/layout/templates/_reset.scss +141 -0
  51. data/lib/generators/kickoff/layout/templates/_scaffolding.scss +137 -0
  52. data/lib/generators/kickoff/layout/templates/_tables.scss +172 -0
  53. data/lib/generators/kickoff/layout/templates/_type.scss +185 -0
  54. data/lib/generators/kickoff/layout/templates/_variables.scss +50 -0
  55. data/lib/generators/kickoff/layout/templates/application.scss +21 -0
  56. data/lib/generators/kickoff/layout/templates/error_messages_helper.rb +23 -0
  57. data/lib/generators/kickoff/layout/templates/layout.html.erb +34 -0
  58. data/lib/generators/kickoff/layout/templates/layout.html.haml +21 -0
  59. data/lib/generators/kickoff/layout/templates/layout_helper.rb +22 -0
  60. data/lib/generators/kickoff/layout/templates/stylesheet.sass +73 -0
  61. data/lib/generators/kickoff/scaffold/USAGE +51 -0
  62. data/lib/generators/kickoff/scaffold/scaffold_generator.rb +318 -0
  63. data/lib/generators/kickoff/scaffold/templates/actions/create.rb +8 -0
  64. data/lib/generators/kickoff/scaffold/templates/actions/destroy.rb +5 -0
  65. data/lib/generators/kickoff/scaffold/templates/actions/edit.rb +3 -0
  66. data/lib/generators/kickoff/scaffold/templates/actions/index.rb +3 -0
  67. data/lib/generators/kickoff/scaffold/templates/actions/new.rb +3 -0
  68. data/lib/generators/kickoff/scaffold/templates/actions/show.rb +3 -0
  69. data/lib/generators/kickoff/scaffold/templates/actions/update.rb +8 -0
  70. data/lib/generators/kickoff/scaffold/templates/controller.rb +3 -0
  71. data/lib/generators/kickoff/scaffold/templates/fixtures.yml +9 -0
  72. data/lib/generators/kickoff/scaffold/templates/helper.rb +2 -0
  73. data/lib/generators/kickoff/scaffold/templates/migration.rb +16 -0
  74. data/lib/generators/kickoff/scaffold/templates/model.rb +4 -0
  75. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  76. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  77. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  78. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  79. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  80. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  81. data/lib/generators/kickoff/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  82. data/lib/generators/kickoff/scaffold/templates/tests/rspec/controller.rb +8 -0
  83. data/lib/generators/kickoff/scaffold/templates/tests/rspec/model.rb +7 -0
  84. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  85. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  86. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  87. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  88. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  89. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  90. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  91. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/controller.rb +5 -0
  92. data/lib/generators/kickoff/scaffold/templates/tests/shoulda/model.rb +7 -0
  93. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  94. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  95. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  96. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  97. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  98. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  99. data/lib/generators/kickoff/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  100. data/lib/generators/kickoff/scaffold/templates/tests/testunit/controller.rb +5 -0
  101. data/lib/generators/kickoff/scaffold/templates/tests/testunit/model.rb +7 -0
  102. data/lib/generators/kickoff/scaffold/templates/views/erb/_form.html.erb +10 -0
  103. data/lib/generators/kickoff/scaffold/templates/views/erb/edit.html.erb +14 -0
  104. data/lib/generators/kickoff/scaffold/templates/views/erb/index.html.erb +29 -0
  105. data/lib/generators/kickoff/scaffold/templates/views/erb/new.html.erb +7 -0
  106. data/lib/generators/kickoff/scaffold/templates/views/erb/show.html.erb +20 -0
  107. data/lib/generators/kickoff/scaffold/templates/views/haml/_form.html.haml +9 -0
  108. data/lib/generators/kickoff/scaffold/templates/views/haml/edit.html.haml +14 -0
  109. data/lib/generators/kickoff/scaffold/templates/views/haml/index.html.haml +25 -0
  110. data/lib/generators/kickoff/scaffold/templates/views/haml/new.html.haml +7 -0
  111. data/lib/generators/kickoff/scaffold/templates/views/haml/show.html.haml +20 -0
  112. data/lib/generators/kickoff/version.rb +3 -0
  113. data/lib/generators/kickoff.rb +29 -0
  114. data/spec/spec_helper.rb +1 -0
  115. metadata +179 -0
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_new
5
+ get :new
6
+ assert_template 'new'
7
+ end
8
+
9
+ def test_create_invalid
10
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
11
+ post :create
12
+ assert_template 'new'
13
+ end
14
+
15
+ def test_create_valid
16
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
17
+ post :create
18
+ assert_redirected_to root_url
19
+ <%- unless options[:authlogic] -%>
20
+ assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
21
+ <%- end -%>
22
+ end
23
+
24
+ def test_edit_without_user
25
+ get :edit, :id => "ignored"
26
+ assert_redirected_to login_url
27
+ end
28
+
29
+ def test_edit
30
+ @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
31
+ get :edit, :id => "ignored"
32
+ assert_template 'edit'
33
+ end
34
+
35
+ def test_update_without_user
36
+ put :update, :id => "ignored"
37
+ assert_redirected_to login_url
38
+ end
39
+
40
+ def test_update_invalid
41
+ @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
42
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
43
+ put :update, :id => "ignored"
44
+ assert_template 'edit'
45
+ end
46
+
47
+ def test_update_valid
48
+ @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
49
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
50
+ put :update, :id => "ignored"
51
+ assert_redirected_to root_url
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ class <%= user_class_name %> < ActiveRecord::Base
2
+ <%- if options[:authlogic] -%>
3
+ acts_as_authentic
4
+ <%- else -%>
5
+ # new columns need to be added here to be writable through mass assignment
6
+ attr_accessible :username, :email, :password, :password_confirmation
7
+
8
+ attr_accessor :password
9
+ before_save :prepare_password
10
+
11
+ validates_presence_of :username
12
+ validates_uniqueness_of :username, :email, :allow_blank => true
13
+ validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
14
+ validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
15
+ validates_presence_of :password, :on => :create
16
+ validates_confirmation_of :password
17
+ validates_length_of :password, :minimum => 4, :allow_blank => true
18
+
19
+ # login can be either username or email address
20
+ def self.authenticate(login, pass)
21
+ <%= user_singular_name %> = find_by_username(login) || find_by_email(login)
22
+ return <%= user_singular_name %> if <%= user_singular_name %> && <%= user_singular_name %>.password_hash == <%= user_singular_name %>.encrypt_password(pass)
23
+ end
24
+
25
+ def encrypt_password(pass)
26
+ BCrypt::Engine.hash_secret(pass, password_salt)
27
+ end
28
+
29
+ private
30
+
31
+ def prepare_password
32
+ unless password.blank?
33
+ self.password_salt = BCrypt::Engine.generate_salt
34
+ self.password_hash = encrypt_password(password)
35
+ end
36
+ end
37
+ <%- end -%>
38
+ end
@@ -0,0 +1,32 @@
1
+ class <%= user_plural_class_name %>Controller < ApplicationController
2
+ before_filter :login_required, :except => [:new, :create]
3
+
4
+ def new
5
+ @<%= user_singular_name %> = <%= user_class_name %>.new
6
+ end
7
+
8
+ def create
9
+ @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
10
+ if @<%= user_singular_name %>.save
11
+ <%- unless options[:authlogic] -%>
12
+ session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
13
+ <%- end -%>
14
+ redirect_to root_url, :notice => "Thank you for signing up! You are now logged in."
15
+ else
16
+ render :new
17
+ end
18
+ end
19
+
20
+ def edit
21
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
22
+ end
23
+
24
+ def update
25
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
26
+ if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
27
+ redirect_to root_url, :notice => "Your profile has been updated."
28
+ else
29
+ render :edit
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,2 @@
1
+ module <%= user_plural_class_name %>Helper
2
+ end
@@ -0,0 +1,20 @@
1
+ <%%= form_for @<%= user_singular_name %> do |f| %>
2
+ <%%= f.error_messages %>
3
+ <div class="field">
4
+ <%%= f.label :username %>
5
+ <%%= f.text_field :username %>
6
+ </div>
7
+ <div class="field">
8
+ <%%= f.label :email, "Email Address" %>
9
+ <%%= f.text_field :email %>
10
+ </div>
11
+ <div class="field">
12
+ <%%= f.label :password %>
13
+ <%%= f.password_field :password %>
14
+ </div>
15
+ <div class="field">
16
+ <%%= f.label :password_confirmation, "Confirm Password" %>
17
+ <%%= f.password_field :password_confirmation %>
18
+ </div>
19
+ <div class="actions"><%%= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update") %></div>
20
+ <%% end %>
@@ -0,0 +1,3 @@
1
+ <%% title "Update Profile" %>
2
+
3
+ <%%= render "form" %>
@@ -0,0 +1,30 @@
1
+ <%% title "Log in" %>
2
+
3
+ <p>Don't have an account? <%%= link_to "Sign up!", signup_path %></p>
4
+
5
+ <%- if options[:authlogic] -%>
6
+ <%%= form_for @<%= session_singular_name %> do |f| %>
7
+ <%%= f.error_messages %>
8
+ <div class="field">
9
+ <%%= f.label :username %>
10
+ <%%= f.text_field :username %>
11
+ </div>
12
+ <div class="field">
13
+ <%%= f.label :password %>
14
+ <%%= f.password_field :password %>
15
+ </div>
16
+ <div class="actions"><%%= f.submit "Log in" %></div>
17
+ <%% end %>
18
+ <%- else -%>
19
+ <%%= form_tag <%= session_plural_name %>_path do %>
20
+ <div class="field">
21
+ <%%= label_tag :login, "Username or Email Address" %>
22
+ <%%= text_field_tag :login, params[:login] %>
23
+ </div>
24
+ <div class="field">
25
+ <%%= label_tag :password %>
26
+ <%%= password_field_tag :password %>
27
+ </div>
28
+ <div class="actions"><%%= submit_tag "Log in" %></div>
29
+ <%% end %>
30
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ <%% title "Sign up" %>
2
+
3
+ <p>Already have an account? <%%= link_to "Log in", login_path %>.</p>
4
+
5
+ <%%= render "form" %>
@@ -0,0 +1,16 @@
1
+ = form_for @<%= user_singular_name %> do |f|
2
+ = f.error_messages
3
+ .field
4
+ = f.label :username
5
+ = f.text_field :username
6
+ .field
7
+ = f.label :email, "Email Address"
8
+ = f.text_field :email
9
+ .field
10
+ = f.label :password
11
+ = f.password_field :password
12
+ .field
13
+ = f.label :password_confirmation, "Confirm Password"
14
+ = f.password_field :password_confirmation
15
+ .actions
16
+ = f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update")
@@ -0,0 +1,3 @@
1
+ - title "Sign up"
2
+
3
+ = render "form"
@@ -0,0 +1,26 @@
1
+ - title "Log in"
2
+
3
+ %p== Don't have an account? #{link_to "Sign up!", signup_path}
4
+
5
+ <%- if options[:authlogic] -%>
6
+ = form_for @<%= session_singular_name %> do |f|
7
+ = f.error_messages
8
+ .field
9
+ = f.label :username
10
+ = f.text_field :username
11
+ .field
12
+ = f.label :password
13
+ = f.password_field :password
14
+ .actions
15
+ = f.submit "Log in"
16
+ <%- else -%>
17
+ - form_tag <%= session_plural_name %>_path do
18
+ .field
19
+ = label_tag :login, "Username or Email Address"
20
+ = text_field_tag :login, params[:login]
21
+ .field
22
+ = label_tag :password
23
+ = password_field_tag :password
24
+ .actions
25
+ = submit_tag "Log in"
26
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ - title "Sign up"
2
+
3
+ %p== Already have an account? #{link_to "Log in", login_path}.
4
+
5
+ = render "form"
@@ -0,0 +1,25 @@
1
+ Description:
2
+ The nifty_layout generator creates a basic layout, stylesheet and
3
+ helper which will give some structure to a starting Rails app.
4
+
5
+ The generator takes one argument which will be the name of the
6
+ layout and stylesheet files. If no argument is passed then it defaults
7
+ to "application".
8
+
9
+ The helper module includes some methods which can be called in any
10
+ template or partial to set variables to be used in the layout, such as
11
+ page title and javascript/stylesheet includes.
12
+
13
+ Examples:
14
+ rails generate kickoff:layout
15
+
16
+ Layout: app/views/layouts/application.html.erb
17
+ Stylesheet: public/stylesheets/application.css
18
+ Helper: app/helpers/layout_helper.rb
19
+
20
+
21
+ rails generate kickoff:layout admin
22
+
23
+ Layout: app/views/layouts/admin.html.erb
24
+ Stylesheet: public/stylesheets/admin.css
25
+ Helper: app/helpers/layout_helper.rb
@@ -0,0 +1,38 @@
1
+ require 'generators/kickoff'
2
+
3
+ module Kickoff
4
+ module Generators
5
+ class LayoutGenerator < Base
6
+ argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
7
+
8
+ class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
9
+
10
+ def create_layout
11
+ if options.haml?
12
+ template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
13
+ copy_file 'stylesheet.sass', "public/stylesheets/sass/#{file_name}.sass"
14
+ else
15
+ template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
16
+ copy_file 'application.scss', "app/assets/stylesheets/application.scss"
17
+ copy_file '_reset.scss', "app/assets/stylesheets/_reset.scss"
18
+ copy_file '_variables.scss', "app/assets/stylesheets/_variables.scss"
19
+ copy_file '_mixins.scss', "app/assets/stylesheets/_mixins.scss"
20
+ copy_file '_scaffolding.scss', "app/assets/stylesheets/_scaffolding.scss"
21
+ copy_file '_type.scss', "app/assets/stylesheets/_type.scss"
22
+ copy_file '_forms.scss', "app/assets/stylesheets/_forms.scss"
23
+ copy_file '_tables.scss', "app/assets/stylesheets/_tables.scss"
24
+ copy_file '_patterns.scss', "app/assets/stylesheets/_patterns.scss"
25
+ remove_file 'app/assets/stylesheets/application.css'
26
+ end
27
+ copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
28
+ copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
29
+ end
30
+
31
+ private
32
+
33
+ def file_name
34
+ layout_name.underscore
35
+ end
36
+ end
37
+ end
38
+ end