niftier-generators 0.1.0

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 (106) hide show
  1. data/CHANGELOG +7 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +89 -0
  4. data/Rakefile +18 -0
  5. data/features/niftier_authentication.feature +59 -0
  6. data/features/niftier_config.feature +17 -0
  7. data/features/niftier_layout.feature +19 -0
  8. data/features/niftier_scaffold.feature +22 -0
  9. data/features/step_definitions/common_steps.rb +37 -0
  10. data/features/step_definitions/rails_setup_steps.rb +6 -0
  11. data/features/support/env.rb +6 -0
  12. data/features/support/matchers.rb +7 -0
  13. data/lib/generators/niftier/authentication/USAGE +55 -0
  14. data/lib/generators/niftier/authentication/authentication_generator.rb +145 -0
  15. data/lib/generators/niftier/authentication/templates/authentication.rb +60 -0
  16. data/lib/generators/niftier/authentication/templates/authlogic_session.rb +2 -0
  17. data/lib/generators/niftier/authentication/templates/fixtures.yml +24 -0
  18. data/lib/generators/niftier/authentication/templates/migration.rb +20 -0
  19. data/lib/generators/niftier/authentication/templates/sessions_controller.rb +45 -0
  20. data/lib/generators/niftier/authentication/templates/sessions_helper.rb +2 -0
  21. data/lib/generators/niftier/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  22. data/lib/generators/niftier/authentication/templates/tests/rspec/user.rb +83 -0
  23. data/lib/generators/niftier/authentication/templates/tests/rspec/users_controller.rb +26 -0
  24. data/lib/generators/niftier/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  25. data/lib/generators/niftier/authentication/templates/tests/shoulda/user.rb +85 -0
  26. data/lib/generators/niftier/authentication/templates/tests/shoulda/users_controller.rb +27 -0
  27. data/lib/generators/niftier/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  28. data/lib/generators/niftier/authentication/templates/tests/testunit/user.rb +88 -0
  29. data/lib/generators/niftier/authentication/templates/tests/testunit/users_controller.rb +23 -0
  30. data/lib/generators/niftier/authentication/templates/user.rb +42 -0
  31. data/lib/generators/niftier/authentication/templates/users_controller.rb +18 -0
  32. data/lib/generators/niftier/authentication/templates/users_helper.rb +2 -0
  33. data/lib/generators/niftier/authentication/templates/views/erb/login.html.erb +30 -0
  34. data/lib/generators/niftier/authentication/templates/views/erb/signup.html.erb +24 -0
  35. data/lib/generators/niftier/authentication/templates/views/haml/login.html.haml +30 -0
  36. data/lib/generators/niftier/authentication/templates/views/haml/signup.html.haml +24 -0
  37. data/lib/generators/niftier/config/USAGE +23 -0
  38. data/lib/generators/niftier/config/config_generator.rb +24 -0
  39. data/lib/generators/niftier/config/templates/config.yml +14 -0
  40. data/lib/generators/niftier/config/templates/load_config.rb +2 -0
  41. data/lib/generators/niftier/layout/USAGE +25 -0
  42. data/lib/generators/niftier/layout/layout_generator.rb +29 -0
  43. data/lib/generators/niftier/layout/templates/error_messages_helper.rb +23 -0
  44. data/lib/generators/niftier/layout/templates/layout.html.erb +24 -0
  45. data/lib/generators/niftier/layout/templates/layout.html.haml +26 -0
  46. data/lib/generators/niftier/layout/templates/layout_helper.rb +26 -0
  47. data/lib/generators/niftier/layout/templates/stylesheet.css +75 -0
  48. data/lib/generators/niftier/layout/templates/stylesheet.sass +66 -0
  49. data/lib/generators/niftier/scaffold/USAGE +51 -0
  50. data/lib/generators/niftier/scaffold/scaffold_generator.rb +241 -0
  51. data/lib/generators/niftier/scaffold/templates/actions/create.rb +9 -0
  52. data/lib/generators/niftier/scaffold/templates/actions/destroy.rb +6 -0
  53. data/lib/generators/niftier/scaffold/templates/actions/edit.rb +3 -0
  54. data/lib/generators/niftier/scaffold/templates/actions/index.rb +3 -0
  55. data/lib/generators/niftier/scaffold/templates/actions/new.rb +3 -0
  56. data/lib/generators/niftier/scaffold/templates/actions/show.rb +3 -0
  57. data/lib/generators/niftier/scaffold/templates/actions/update.rb +9 -0
  58. data/lib/generators/niftier/scaffold/templates/controller.rb +3 -0
  59. data/lib/generators/niftier/scaffold/templates/fixtures.yml +9 -0
  60. data/lib/generators/niftier/scaffold/templates/helper.rb +2 -0
  61. data/lib/generators/niftier/scaffold/templates/migration.rb +16 -0
  62. data/lib/generators/niftier/scaffold/templates/model.rb +3 -0
  63. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  64. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  65. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  66. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  67. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  68. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  69. data/lib/generators/niftier/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  70. data/lib/generators/niftier/scaffold/templates/tests/rspec/controller.rb +8 -0
  71. data/lib/generators/niftier/scaffold/templates/tests/rspec/model.rb +7 -0
  72. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  73. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  74. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  75. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  76. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  77. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  78. data/lib/generators/niftier/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  79. data/lib/generators/niftier/scaffold/templates/tests/shoulda/controller.rb +5 -0
  80. data/lib/generators/niftier/scaffold/templates/tests/shoulda/model.rb +7 -0
  81. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  82. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  83. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  84. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  85. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  86. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  87. data/lib/generators/niftier/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  88. data/lib/generators/niftier/scaffold/templates/tests/testunit/controller.rb +5 -0
  89. data/lib/generators/niftier/scaffold/templates/tests/testunit/model.rb +7 -0
  90. data/lib/generators/niftier/scaffold/templates/views/erb/_form.html.erb +10 -0
  91. data/lib/generators/niftier/scaffold/templates/views/erb/edit.html.erb +14 -0
  92. data/lib/generators/niftier/scaffold/templates/views/erb/index.html.erb +29 -0
  93. data/lib/generators/niftier/scaffold/templates/views/erb/new.html.erb +7 -0
  94. data/lib/generators/niftier/scaffold/templates/views/erb/show.html.erb +20 -0
  95. data/lib/generators/niftier/scaffold/templates/views/haml/_form.html.haml +10 -0
  96. data/lib/generators/niftier/scaffold/templates/views/haml/edit.html.haml +14 -0
  97. data/lib/generators/niftier/scaffold/templates/views/haml/index.html.haml +25 -0
  98. data/lib/generators/niftier/scaffold/templates/views/haml/new.html.haml +7 -0
  99. data/lib/generators/niftier/scaffold/templates/views/haml/show.html.haml +20 -0
  100. data/lib/generators/niftier.rb +15 -0
  101. data/test/test_helper.rb +119 -0
  102. data/test/test_niftier_authentication_generator.rb +274 -0
  103. data/test/test_niftier_config_generator.rb +37 -0
  104. data/test/test_niftier_layout_generator.rb +42 -0
  105. data/test/test_niftier_scaffold_generator.rb +534 -0
  106. metadata +173 -0
@@ -0,0 +1,9 @@
1
+ def create
2
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
3
+ if @<%= singular_name %>.save
4
+ flash[:notice] = "Successfully created <%= model_name.underscore.humanize.downcase %>."
5
+ redirect_to <%= item_path('url') %>
6
+ else
7
+ render :action => 'new'
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ def destroy
2
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
+ @<%= singular_name %>.destroy
4
+ flash[:notice] = "Successfully destroyed <%= model_name.underscore.humanize.downcase %>."
5
+ redirect_to <%= items_path('url') %>
6
+ end
@@ -0,0 +1,3 @@
1
+ def edit
2
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
+ end
@@ -0,0 +1,3 @@
1
+ def index
2
+ @<%= plural_name %> = <%= class_name %>.all
3
+ end
@@ -0,0 +1,3 @@
1
+ def new
2
+ @<%= singular_name %> = <%= class_name %>.new
3
+ end
@@ -0,0 +1,3 @@
1
+ def show
2
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
+ end
@@ -0,0 +1,9 @@
1
+ def update
2
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
4
+ flash[:notice] = "Successfully updated <%= model_name.underscore.humanize.downcase %>."
5
+ redirect_to <%= item_path('url') %>
6
+ else
7
+ render :action => 'edit'
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController
2
+ <%= controller_methods :actions %>
3
+ end
@@ -0,0 +1,9 @@
1
+ one:
2
+ <%- for attribute in model_attributes -%>
3
+ <%= attribute.name %>: <%= attribute.default %>
4
+ <%- end -%>
5
+
6
+ two:
7
+ <%- for attribute in model_attributes -%>
8
+ <%= attribute.name %>: <%= attribute.default %>
9
+ <%- end -%>
@@ -0,0 +1,2 @@
1
+ module <%= plural_class_name %>Helper
2
+ end
@@ -0,0 +1,16 @@
1
+ class Create<%= plural_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %> do |t|
4
+ <%- for attribute in model_attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ <%- unless options[:skip_timestamps] -%>
8
+ t.timestamps
9
+ <%- end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= plural_name %>
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
+ end
@@ -0,0 +1,11 @@
1
+ it "create action should render new template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ response.should render_template(:new)
5
+ end
6
+
7
+ it "create action should redirect when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ response.should redirect_to(<%= item_path_for_spec('url') %>)
11
+ end
@@ -0,0 +1,6 @@
1
+ it "destroy action should destroy model and redirect to index action" do
2
+ <%= singular_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= singular_name %>
4
+ response.should redirect_to(<%= items_path('url') %>)
5
+ <%= class_name %>.exists?(<%= singular_name %>.id).should be_false
6
+ end
@@ -0,0 +1,4 @@
1
+ it "edit action should render edit template" do
2
+ get :edit, :id => <%= class_name %>.first
3
+ response.should render_template(:edit)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "index action should render index template" do
2
+ get :index
3
+ response.should render_template(:index)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "new action should render new template" do
2
+ get :new
3
+ response.should render_template(:new)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "show action should render show template" do
2
+ get :show, :id => <%= class_name %>.first
3
+ response.should render_template(:show)
4
+ end
@@ -0,0 +1,11 @@
1
+ it "update action should render edit template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ response.should render_template(:edit)
5
+ end
6
+
7
+ it "update action should redirect when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ response.should redirect_to(<%= item_path_for_spec('url') %>)
11
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+ fixtures :all
5
+ integrate_views
6
+
7
+ <%= controller_methods 'tests/rspec/actions' %>
8
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ it "should be valid" do
5
+ <%= class_name %>.new.should be_valid
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ context "create action" do
2
+ should "render new template when model is invalid" do
3
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
4
+ post :create
5
+ assert_template 'new'
6
+ end
7
+
8
+ should "redirect when model is valid" do
9
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
+ post :create
11
+ assert_redirected_to <%= item_path_for_test('url') %>
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ context "destroy action" do
2
+ should "destroy model and redirect to index action" do
3
+ <%= singular_name %> = <%= class_name %>.first
4
+ delete :destroy, :id => <%= singular_name %>
5
+ assert_redirected_to <%= items_path('url') %>
6
+ assert !<%= class_name %>.exists?(<%= singular_name %>.id)
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ context "edit action" do
2
+ should "render edit template" do
3
+ get :edit, :id => <%= class_name %>.first
4
+ assert_template 'edit'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "index action" do
2
+ should "render index template" do
3
+ get :index
4
+ assert_template 'index'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "new action" do
2
+ should "render new template" do
3
+ get :new
4
+ assert_template 'new'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "show action" do
2
+ should "render show template" do
3
+ get :show, :id => <%= class_name %>.first
4
+ assert_template 'show'
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ context "update action" do
2
+ should "render edit template when model is invalid" do
3
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
4
+ put :update, :id => <%= class_name %>.first
5
+ assert_template 'edit'
6
+ end
7
+
8
+ should "redirect when model is valid" do
9
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
+ put :update, :id => <%= class_name %>.first
11
+ assert_redirected_to <%= item_path_for_test('url') %>
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class <%= plural_class_name %>ControllerTest < ActionController::TestCase
4
+ <%= controller_methods 'tests/shoulda/actions' %>
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ should "be valid" do
5
+ assert <%= class_name %>.new.valid?
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ def test_create_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ assert_template 'new'
5
+ end
6
+
7
+ def test_create_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ assert_redirected_to <%= item_path_for_test('url') %>
11
+ end
@@ -0,0 +1,6 @@
1
+ def test_destroy
2
+ <%= singular_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= singular_name %>
4
+ assert_redirected_to <%= items_path('url') %>
5
+ assert !<%= class_name %>.exists?(<%= singular_name %>.id)
6
+ end
@@ -0,0 +1,4 @@
1
+ def test_edit
2
+ get :edit, :id => <%= class_name %>.first
3
+ assert_template 'edit'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_index
2
+ get :index
3
+ assert_template 'index'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_new
2
+ get :new
3
+ assert_template 'new'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_show
2
+ get :show, :id => <%= class_name %>.first
3
+ assert_template 'show'
4
+ end
@@ -0,0 +1,11 @@
1
+ def test_update_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ assert_template 'edit'
5
+ end
6
+
7
+ def test_update_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ assert_redirected_to <%= item_path_for_test('url') %>
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class <%= plural_class_name %>ControllerTest < ActionController::TestCase
4
+ <%= controller_methods 'tests/testunit/actions' %>
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ def test_should_be_valid
5
+ assert <%= class_name %>.new.valid?
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ <%%= form_for @<%= singular_name %> do |f| %>
2
+ <%%= f.error_messages %>
3
+ <%- for attribute in model_attributes -%>
4
+ <p>
5
+ <%%= f.label :<%= attribute.name %> %><br />
6
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
7
+ </p>
8
+ <%- end -%>
9
+ <p><%%= f.submit %></p>
10
+ <%% end %>
@@ -0,0 +1,14 @@
1
+ <%% title "Edit <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if actions? :show, :index -%>
6
+ <p>
7
+ <%- if action? :show -%>
8
+ <%%= link_to "Show", @<%= singular_name %> %> |
9
+ <%- end -%>
10
+ <%- if action? :index -%>
11
+ <%%= link_to "View All", <%= plural_name %>_path %>
12
+ <%- end -%>
13
+ </p>
14
+ <%- end -%>
@@ -0,0 +1,29 @@
1
+ <%% title "<%= plural_name.titleize %>" %>
2
+
3
+ <table>
4
+ <tr>
5
+ <%- for attribute in model_attributes -%>
6
+ <th><%= attribute.human_name.titleize %></th>
7
+ <%- end -%>
8
+ </tr>
9
+ <%% for <%= singular_name %> in @<%= plural_name %> %>
10
+ <tr>
11
+ <%- for attribute in model_attributes -%>
12
+ <td><%%= <%= singular_name %>.<%= attribute.name %> %></td>
13
+ <%- end -%>
14
+ <%- if action? :show -%>
15
+ <td><%%= link_to "Show", <%= singular_name %> %></td>
16
+ <%- end -%>
17
+ <%- if action? :edit -%>
18
+ <td><%%= link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
19
+ <%- end -%>
20
+ <%- if action? :destroy -%>
21
+ <td><%%= link_to "Destroy", <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
22
+ <%- end -%>
23
+ </tr>
24
+ <%% end %>
25
+ </table>
26
+
27
+ <%- if action? :new -%>
28
+ <p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
29
+ <%- end -%>
@@ -0,0 +1,7 @@
1
+ <%% title "New <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ <p><%%= link_to "Back to List", <%= plural_name %>_path %></p>
7
+ <%- end -%>
@@ -0,0 +1,20 @@
1
+ <%% title "<%= singular_name.titleize %>" %>
2
+
3
+ <%- for attribute in model_attributes -%>
4
+ <p>
5
+ <strong><%= attribute.human_name.titleize %>:</strong>
6
+ <%%= @<%= singular_name %>.<%= attribute.name %> %>
7
+ </p>
8
+ <%- end -%>
9
+
10
+ <p>
11
+ <%- if action? :edit -%>
12
+ <%%= link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
13
+ <%- end -%>
14
+ <%- if action? :destroy -%>
15
+ <%%= link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %> |
16
+ <%- end -%>
17
+ <%- if action? :index -%>
18
+ <%%= link_to "View All", <%= plural_name %>_path %>
19
+ <%- end -%>
20
+ </p>
@@ -0,0 +1,10 @@
1
+ - form_for @<%= singular_name %> do |f|
2
+ = f.error_messages
3
+ <%- for attribute in model_attributes -%>
4
+ %p
5
+ = f.label :<%= attribute.name %>
6
+ %br
7
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
8
+ <%- end -%>
9
+ %p
10
+ = f.submit
@@ -0,0 +1,14 @@
1
+ - title "Edit <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if actions? :show, :index -%>
6
+ %p
7
+ <%- if action? :show -%>
8
+ = link_to "Show", <%= singular_name %>_path(@<%= singular_name %>)
9
+ |
10
+ <%- end -%>
11
+ <%- if action? :index -%>
12
+ = link_to "View All", <%= plural_name %>_path
13
+ <%- end -%>
14
+ <%- end -%>
@@ -0,0 +1,25 @@
1
+ - title "<%= plural_name.titleize %>"
2
+
3
+ %table
4
+ %tr
5
+ <%- for attribute in model_attributes -%>
6
+ %th <%= attribute.human_name %>
7
+ <%- end -%>
8
+ - for <%= singular_name %> in @<%= plural_name %>
9
+ %tr
10
+ <%- for attribute in model_attributes -%>
11
+ %td= <%= singular_name %>.<%= attribute.name %>
12
+ <%- end -%>
13
+ <%- if action? :show -%>
14
+ %td= link_to 'Show', <%= singular_name %>
15
+ <%- end -%>
16
+ <%- if action? :edit -%>
17
+ %td= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>)
18
+ <%- end -%>
19
+ <%- if action? :destroy -%>
20
+ %td= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
21
+ <%- end -%>
22
+
23
+ <%- if actions? :new -%>
24
+ %p= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path
25
+ <%- end -%>
@@ -0,0 +1,7 @@
1
+ - title "New <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ %p= link_to "Back to List", <%= plural_name %>_path
7
+ <%- end -%>
@@ -0,0 +1,20 @@
1
+ - title "<%= singular_name.titleize %>"
2
+
3
+ <%- for attribute in model_attributes -%>
4
+ %p
5
+ %strong <%= attribute.human_name.titleize %>:
6
+ = @<%= singular_name %>.<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ %p
10
+ <%- if action? :edit -%>
11
+ = link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>)
12
+ |
13
+ <%- end -%>
14
+ <%- if action? :destroy -%>
15
+ = link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
16
+ |
17
+ <%- end -%>
18
+ <%- if action? :index -%>
19
+ = link_to "View All", <%= plural_name %>_path
20
+ <%- end -%>
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Niftier
4
+ module Generators
5
+ class Base < Rails::Generators::Base #:nodoc:
6
+ def self.source_root
7
+ @_niftier_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'niftier', generator_name, 'templates'))
8
+ end
9
+
10
+ def self.banner
11
+ "#{$0} niftier:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,119 @@
1
+ require 'test/unit'
2
+
3
+ # Must set before requiring generator libs.
4
+ TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
5
+ PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
6
+ app_root = File.join(TMP_ROOT, PROJECT_NAME)
7
+ if defined?(APP_ROOT)
8
+ APP_ROOT.replace(app_root)
9
+ else
10
+ APP_ROOT = app_root
11
+ end
12
+ if defined?(RAILS_ROOT)
13
+ RAILS_ROOT.replace(app_root)
14
+ else
15
+ RAILS_ROOT = app_root
16
+ end
17
+
18
+ require 'rubygems'
19
+ gem 'rails', '2.0.2' # getting a Rails.configuration error with 2.1
20
+ gem 'rubigen', '1.4'
21
+ gem 'shoulda', '2.0.6'
22
+ require 'rubigen' # gem install rubigen --version=1.4
23
+ require 'rubigen/helpers/generator_test_helper'
24
+ require 'rails_generator'
25
+ require 'shoulda' # gem install shoulda --version=2.0.6
26
+ require 'mocha'
27
+
28
+ module NiftierGenerators
29
+ module TestHelper
30
+ include RubiGen::GeneratorTestHelper
31
+
32
+ def setup
33
+ bare_setup
34
+ end
35
+
36
+ def teardown
37
+ bare_teardown
38
+ end
39
+
40
+ protected
41
+
42
+ def run_rails_generator(generator, *args)
43
+ options = args.pop if args.last.kind_of? Hash
44
+ options ||= {}
45
+ run_generator(generator.to_s, args, generator_sources, options.reverse_merge(:quiet => true))
46
+ end
47
+
48
+ def generator_sources
49
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "rails_generators"))]
50
+ end
51
+ end
52
+
53
+ module ShouldaAdditions
54
+ def rails_generator(*args)
55
+ setup do
56
+ run_rails_generator(*args)
57
+ end
58
+ end
59
+
60
+ def should_generate_file(file, &block)
61
+ should "generate file #{file}" do
62
+ yield("foo") if block_given?
63
+ assert_generated_file(file)
64
+ end
65
+ end
66
+
67
+ def should_not_generate_file(file)
68
+ should "not generate file #{file}" do
69
+ assert !File.exists?("#{APP_ROOT}/#{file}"),"The file '#{file}' should not exist"
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ class Thoughtbot::Shoulda::Context
76
+ include NiftierGenerators::ShouldaAdditions
77
+ end
78
+
79
+ # Mock out what we need from AR::Base.
80
+ module ActiveRecord
81
+ class Base
82
+ class << self
83
+ attr_accessor :pluralize_table_names, :columns
84
+
85
+ def add_column(name, type = :string)
86
+ returning ActiveRecord::ConnectionAdapters::Column.new(name, nil) do |column|
87
+ column.type = type
88
+ @columns ||= []
89
+ @columns << column
90
+ end
91
+ end
92
+ end
93
+ self.pluralize_table_names = true
94
+ end
95
+
96
+ module ConnectionAdapters
97
+ class Column
98
+ attr_accessor :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
99
+
100
+ def initialize(name, default, sql_type = nil)
101
+ @name = name
102
+ @default = default
103
+ @type = @sql_type = sql_type
104
+ end
105
+
106
+ def human_name
107
+ @name.humanize
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ # And what we need from ActionView
114
+ module ActionView
115
+ module Helpers
116
+ module ActiveRecordHelper; end
117
+ class InstanceTag; end
118
+ end
119
+ end