flockonus-nifty-generators 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +194 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +75 -0
- data/Rakefile +10 -0
- data/features/nifty_authentication.feature +80 -0
- data/features/nifty_config.feature +17 -0
- data/features/nifty_layout.feature +20 -0
- data/features/nifty_scaffold.feature +74 -0
- data/features/step_definitions/common_steps.rb +62 -0
- data/features/step_definitions/rails_setup_steps.rb +6 -0
- data/features/support/env.rb +6 -0
- data/features/support/matchers.rb +7 -0
- data/lib/generators/nifty/authentication/USAGE +50 -0
- data/lib/generators/nifty/authentication/authentication_generator.rb +154 -0
- data/lib/generators/nifty/authentication/templates/authlogic_session.rb +2 -0
- data/lib/generators/nifty/authentication/templates/controller_authentication.rb +60 -0
- data/lib/generators/nifty/authentication/templates/fixtures.yml +24 -0
- data/lib/generators/nifty/authentication/templates/migration.rb +20 -0
- data/lib/generators/nifty/authentication/templates/sessions_controller.rb +41 -0
- data/lib/generators/nifty/authentication/templates/sessions_helper.rb +2 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +83 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +56 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +85 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +61 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +88 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +53 -0
- data/lib/generators/nifty/authentication/templates/user.rb +38 -0
- data/lib/generators/nifty/authentication/templates/users_controller.rb +32 -0
- data/lib/generators/nifty/authentication/templates/users_helper.rb +2 -0
- data/lib/generators/nifty/authentication/templates/views/erb/_form.html.erb +20 -0
- data/lib/generators/nifty/authentication/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/nifty/authentication/templates/views/erb/login.html.erb +30 -0
- data/lib/generators/nifty/authentication/templates/views/erb/signup.html.erb +5 -0
- data/lib/generators/nifty/authentication/templates/views/haml/_form.html.haml +20 -0
- data/lib/generators/nifty/authentication/templates/views/haml/edit.html.haml +3 -0
- data/lib/generators/nifty/authentication/templates/views/haml/login.html.haml +30 -0
- data/lib/generators/nifty/authentication/templates/views/haml/signup.html.haml +5 -0
- data/lib/generators/nifty/config/USAGE +23 -0
- data/lib/generators/nifty/config/config_generator.rb +24 -0
- data/lib/generators/nifty/config/templates/config.yml +8 -0
- data/lib/generators/nifty/config/templates/load_config.rb +2 -0
- data/lib/generators/nifty/layout/USAGE +25 -0
- data/lib/generators/nifty/layout/layout_generator.rb +30 -0
- data/lib/generators/nifty/layout/templates/char_limit_form.js +36 -0
- data/lib/generators/nifty/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/nifty/layout/templates/layout.html.erb +19 -0
- data/lib/generators/nifty/layout/templates/layout.html.haml +21 -0
- data/lib/generators/nifty/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/nifty/layout/templates/stylesheet.css +92 -0
- data/lib/generators/nifty/layout/templates/stylesheet.sass +66 -0
- data/lib/generators/nifty/scaffold/USAGE +51 -0
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +319 -0
- data/lib/generators/nifty/scaffold/templates/actions/create.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/actions/destroy.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/update.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/controller.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/nifty/scaffold/templates/helper.rb +2 -0
- data/lib/generators/nifty/scaffold/templates/migration.rb +16 -0
- data/lib/generators/nifty/scaffold/templates/model.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/_form.html.erb +13 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/show.html.erb +20 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/_form.html.haml +10 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/index.html.haml +25 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/new.html.haml +7 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/show.html.haml +20 -0
- data/lib/generators/nifty.rb +28 -0
- data/rails_generators/nifty_authentication/USAGE +50 -0
- data/rails_generators/nifty_authentication/lib/insert_commands.rb +74 -0
- data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +128 -0
- data/rails_generators/nifty_authentication/templates/authentication.rb +61 -0
- data/rails_generators/nifty_authentication/templates/authlogic_session.rb +2 -0
- data/rails_generators/nifty_authentication/templates/fixtures.yml +24 -0
- data/rails_generators/nifty_authentication/templates/migration.rb +20 -0
- data/rails_generators/nifty_authentication/templates/sessions_controller.rb +45 -0
- data/rails_generators/nifty_authentication/templates/sessions_helper.rb +2 -0
- data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +83 -0
- data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +26 -0
- data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +85 -0
- data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +27 -0
- data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +88 -0
- data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +23 -0
- data/rails_generators/nifty_authentication/templates/user.rb +42 -0
- data/rails_generators/nifty_authentication/templates/users_controller.rb +18 -0
- data/rails_generators/nifty_authentication/templates/users_helper.rb +2 -0
- data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +30 -0
- data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +24 -0
- data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +30 -0
- data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +24 -0
- data/rails_generators/nifty_config/USAGE +23 -0
- data/rails_generators/nifty_config/nifty_config_generator.rb +32 -0
- data/rails_generators/nifty_config/templates/config.yml +8 -0
- data/rails_generators/nifty_config/templates/load_config.rb +2 -0
- data/rails_generators/nifty_layout/USAGE +25 -0
- data/rails_generators/nifty_layout/nifty_layout_generator.rb +44 -0
- data/rails_generators/nifty_layout/templates/helper.rb +22 -0
- data/rails_generators/nifty_layout/templates/layout.html.erb +22 -0
- data/rails_generators/nifty_layout/templates/layout.html.haml +19 -0
- data/rails_generators/nifty_layout/templates/stylesheet.css +97 -0
- data/rails_generators/nifty_layout/templates/stylesheet.sass +67 -0
- data/rails_generators/nifty_scaffold/USAGE +51 -0
- data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +232 -0
- data/rails_generators/nifty_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/nifty_scaffold/templates/controller.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/nifty_scaffold/templates/helper.rb +2 -0
- data/rails_generators/nifty_scaffold/templates/migration.rb +16 -0
- data/rails_generators/nifty_scaffold/templates/model.rb +3 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +7 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +5 -0
- data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +7 -0
- data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +10 -0
- data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +14 -0
- data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +29 -0
- data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +7 -0
- data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +20 -0
- data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +10 -0
- data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +20 -0
- data/test/test_helper.rb +119 -0
- data/test/test_nifty_authentication_generator.rb +274 -0
- data/test/test_nifty_config_generator.rb +37 -0
- data/test/test_nifty_layout_generator.rb +42 -0
- data/test/test_nifty_scaffold_generator.rb +534 -0
- metadata +313 -0
@@ -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
|
+
<%= instance_name %> = <%= class_name %>.first
|
4
|
+
delete :destroy, :id => <%= instance_name %>
|
5
|
+
assert_redirected_to <%= items_url %>
|
6
|
+
assert !<%= class_name %>.exists?(<%= instance_name %>.id)
|
7
|
+
end
|
8
|
+
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,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,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,13 @@
|
|
1
|
+
<%%= form_for <%= item_path :instance_variable => true %> do |f| %>
|
2
|
+
<%%= f.error_messages %>
|
3
|
+
<%- for attribute in model_attributes -%>
|
4
|
+
<p>
|
5
|
+
<%%= f.label :<%= attribute.name %> %>
|
6
|
+
<% if attribute.type.to_s == 'string' %> <span class="limit_input"> ??/<%%= <%= class_name %>.columns_hash[ '<%= attribute.name %>' ].limit %> </span> <% end %><br />
|
7
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %><% if attribute.type.to_s == 'string' %>, :maxlength => <%= class_name %>.columns_hash[ '<%= attribute.name %>' ].limit.to_s <% end %> %>
|
8
|
+
</p>
|
9
|
+
<%- end -%>
|
10
|
+
<p><%%= f.submit %></p>
|
11
|
+
<%% end %>
|
12
|
+
|
13
|
+
<%%= javascript_include_tag 'edition_mod.js' %>
|
@@ -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", <%= item_path :instance_variable => true %> %> |
|
9
|
+
<%- end -%>
|
10
|
+
<%- if action? :index -%>
|
11
|
+
<%%= link_to "View All", <%= items_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 <%= instance_name %> in @<%= instances_name %> %>
|
10
|
+
<tr>
|
11
|
+
<%- for attribute in model_attributes -%>
|
12
|
+
<td><%%= <%= instance_name %>.<%= attribute.name %> %></td>
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :show -%>
|
15
|
+
<td><%%= link_to "Show", <%= item_path %> %></td>
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :edit -%>
|
18
|
+
<td><%%= link_to "Edit", <%= item_path :action => :edit %> %></td>
|
19
|
+
<%- end -%>
|
20
|
+
<%- if action? :destroy -%>
|
21
|
+
<td><%%= link_to "Destroy", <%= item_path %>, :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 %>", <%= item_path :action => :new %> %></p>
|
29
|
+
<%- 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
|
+
<%%= @<%= instance_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<%- if action? :edit -%>
|
12
|
+
<%%= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %> %> |
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :destroy -%>
|
15
|
+
<%%= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete %> |
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :index -%>
|
18
|
+
<%%= link_to "View All", <%= items_path %> %>
|
19
|
+
<%- end -%>
|
20
|
+
</p>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
= form_for <%= item_path :instance_variable => true %> 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", <%= item_path %>
|
9
|
+
|
|
10
|
+
<%- end -%>
|
11
|
+
<%- if action? :index -%>
|
12
|
+
= link_to "View All", <%= items_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 <%= instance_name %> in @<%= instances_name %>
|
9
|
+
%tr
|
10
|
+
<%- for attribute in model_attributes -%>
|
11
|
+
%td= <%= instance_name %>.<%= attribute.name %>
|
12
|
+
<%- end -%>
|
13
|
+
<%- if action? :show -%>
|
14
|
+
%td= link_to 'Show', <%= item_path %>
|
15
|
+
<%- end -%>
|
16
|
+
<%- if action? :edit -%>
|
17
|
+
%td= link_to 'Edit', <%= item_path :action => :edit %>
|
18
|
+
<%- end -%>
|
19
|
+
<%- if action? :destroy -%>
|
20
|
+
%td= link_to 'Destroy', <%= item_path %>, :confirm => 'Are you sure?', :method => :delete
|
21
|
+
<%- end -%>
|
22
|
+
|
23
|
+
<%- if actions? :new -%>
|
24
|
+
%p= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %>
|
25
|
+
<%- 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
|
+
= @<%= instance_name %>.<%= attribute.name %>
|
7
|
+
<%- end -%>
|
8
|
+
|
9
|
+
%p
|
10
|
+
<%- if action? :edit -%>
|
11
|
+
= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %>
|
12
|
+
|
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :destroy -%>
|
15
|
+
= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete
|
16
|
+
|
|
17
|
+
<%- end -%>
|
18
|
+
<%- if action? :index -%>
|
19
|
+
= link_to "View All", <%= items_path %>
|
20
|
+
<%- end -%>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Nifty
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::Base #:nodoc:
|
6
|
+
def self.source_root
|
7
|
+
@_nifty_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'nifty', generator_name, 'templates'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.banner
|
11
|
+
"rails generate nifty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def add_gem(name, options = {})
|
17
|
+
gemfile_content = File.read(destination_path("Gemfile"))
|
18
|
+
File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
|
19
|
+
gem name, options unless gemfile_content.include? name
|
20
|
+
end
|
21
|
+
|
22
|
+
def print_usage
|
23
|
+
self.class.help(Thor::Base.shell.new)
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a user model, users controller, and sessions controller. The
|
3
|
+
users controller handles the registration and the sessions controller
|
4
|
+
handles authentication. This is similar to restful_authentication, but
|
5
|
+
simpler.
|
6
|
+
|
7
|
+
IMPORTANT: This generator uses the "title" helper method which is generated
|
8
|
+
by the nifty_layout generator. You may want to run that generator first.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
If you do not pass any arguments, the model name will default to "user", and
|
12
|
+
the authentication controller will default to "session". You can override
|
13
|
+
each of these respectively by passing one or two arguments. Either name can
|
14
|
+
be CamelCased or under_scored.
|
15
|
+
|
16
|
+
Make sure to setup the authlogic gem if you are using that option.
|
17
|
+
|
18
|
+
config.gem "authlogic"
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
script/generate nifty_authentication
|
22
|
+
|
23
|
+
Creates user model, users_controller, and sessions_controller.
|
24
|
+
|
25
|
+
script/generate nifty_authentication account
|
26
|
+
|
27
|
+
Creates account model, accounts_controller, and sessions_controller.
|
28
|
+
|
29
|
+
script/generate nifty_authentication Account UserSession
|
30
|
+
|
31
|
+
Creates account model, accounts_controller, and user_sessions_controller.
|
32
|
+
|
33
|
+
Methods:
|
34
|
+
There are several methods generated which you can use in your application.
|
35
|
+
Here's a common example of what you might add to your layout.
|
36
|
+
|
37
|
+
<% if logged_in? %>
|
38
|
+
Welcome <%= current_user.username %>! Not you?
|
39
|
+
<%= link_to "Log out", logout_path %>
|
40
|
+
<% else %>
|
41
|
+
<%= link_to "Sign up", signup_path %> or
|
42
|
+
<%= link_to "log in", login_path %>.
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
You can also restrict unregistered users from accessing a controller using
|
46
|
+
a before filter. For example.
|
47
|
+
|
48
|
+
before_filter :login_required, :except => [:index, :show]
|
49
|
+
|
50
|
+
See the generated file lib/authentication.rb for details.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def route_resource(*resources)
|
3
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
4
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
5
|
+
|
6
|
+
logger.route "map.resource #{resource_list}"
|
7
|
+
unless options[:pretend]
|
8
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
9
|
+
"#{match}\n map.resource #{resource_list}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def route_name(name, path, route_options = {})
|
15
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
16
|
+
|
17
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
18
|
+
unless options[:pretend]
|
19
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
20
|
+
"#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_into(file, line)
|
26
|
+
logger.insert "#{line} into #{file}"
|
27
|
+
unless options[:pretend]
|
28
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
29
|
+
"#{match}\n #{line}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
36
|
+
def route_resource(*resources)
|
37
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
38
|
+
look_for = "\n map.resource #{resource_list}\n"
|
39
|
+
logger.route "map.resource #{resource_list}"
|
40
|
+
unless options[:pretend]
|
41
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def route_name(name, path, route_options = {})
|
46
|
+
look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
47
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
48
|
+
unless options[:pretend]
|
49
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def insert_into(file, line)
|
54
|
+
logger.remove "#{line} from #{file}"
|
55
|
+
unless options[:pretend]
|
56
|
+
gsub_file file, "\n #{line}", ''
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Rails::Generator::Commands::List.class_eval do
|
62
|
+
def route_resource(*resources)
|
63
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
64
|
+
logger.route "map.resource #{resource_list}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def route_name(name, path, options = {})
|
68
|
+
logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
|
69
|
+
end
|
70
|
+
|
71
|
+
def insert_into(file, line)
|
72
|
+
logger.insert "#{line} into #{file}"
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
class NiftyAuthenticationGenerator < Rails::Generator::Base
|
3
|
+
attr_accessor :user_name, :session_name
|
4
|
+
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
|
8
|
+
@user_name = @args[0] || 'user'
|
9
|
+
@session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : 'session')
|
10
|
+
end
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
record do |m|
|
14
|
+
m.directory "app/models"
|
15
|
+
m.directory "app/controllers"
|
16
|
+
m.directory "app/helpers"
|
17
|
+
m.directory "app/views"
|
18
|
+
m.directory "lib"
|
19
|
+
|
20
|
+
m.directory "app/views/#{user_plural_name}"
|
21
|
+
m.template "user.rb", "app/models/#{user_singular_name}.rb"
|
22
|
+
m.template "authlogic_session.rb", "app/models/#{session_singular_name}.rb" if options[:authlogic]
|
23
|
+
m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
|
24
|
+
m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
|
25
|
+
m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
|
26
|
+
|
27
|
+
m.directory "app/views/#{session_plural_name}"
|
28
|
+
m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
|
29
|
+
m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
|
30
|
+
m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
|
31
|
+
|
32
|
+
m.template "authentication.rb", "lib/authentication.rb"
|
33
|
+
m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
|
34
|
+
|
35
|
+
m.route_resources user_plural_name
|
36
|
+
m.route_resources session_plural_name
|
37
|
+
m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
|
38
|
+
m.route_name :logout, 'logout', :controller => session_plural_name, :action => 'destroy'
|
39
|
+
m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
|
40
|
+
|
41
|
+
m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
|
42
|
+
|
43
|
+
if test_framework == :rspec
|
44
|
+
m.directory "spec"
|
45
|
+
m.directory "spec/fixtures"
|
46
|
+
m.directory "spec/controllers"
|
47
|
+
m.directory "spec/models"
|
48
|
+
m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
|
49
|
+
m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
|
50
|
+
m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
|
51
|
+
m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{session_plural_name}_controller_spec.rb"
|
52
|
+
else
|
53
|
+
m.directory "test"
|
54
|
+
m.directory "test/fixtures"
|
55
|
+
m.directory "test/functional"
|
56
|
+
m.directory "test/unit"
|
57
|
+
m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
|
58
|
+
m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
|
59
|
+
m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
|
60
|
+
m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def user_singular_name
|
66
|
+
user_name.underscore
|
67
|
+
end
|
68
|
+
|
69
|
+
def user_plural_name
|
70
|
+
user_singular_name.pluralize
|
71
|
+
end
|
72
|
+
|
73
|
+
def user_class_name
|
74
|
+
user_name.camelize
|
75
|
+
end
|
76
|
+
|
77
|
+
def user_plural_class_name
|
78
|
+
user_plural_name.camelize
|
79
|
+
end
|
80
|
+
|
81
|
+
def session_singular_name
|
82
|
+
session_name.underscore
|
83
|
+
end
|
84
|
+
|
85
|
+
def session_plural_name
|
86
|
+
session_singular_name.pluralize
|
87
|
+
end
|
88
|
+
|
89
|
+
def session_class_name
|
90
|
+
session_name.camelize
|
91
|
+
end
|
92
|
+
|
93
|
+
def session_plural_class_name
|
94
|
+
session_plural_name.camelize
|
95
|
+
end
|
96
|
+
|
97
|
+
def application_controller_name
|
98
|
+
Rails.version >= '2.3.0' ? 'application_controller' : 'application'
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
def view_language
|
104
|
+
options[:haml] ? 'haml' : 'erb'
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_framework
|
108
|
+
options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_options!(opt)
|
112
|
+
opt.separator ''
|
113
|
+
opt.separator 'Options:'
|
114
|
+
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
|
115
|
+
opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
|
116
|
+
opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
|
117
|
+
opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
|
118
|
+
opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
|
119
|
+
end
|
120
|
+
|
121
|
+
def banner
|
122
|
+
<<-EOS
|
123
|
+
Creates user model and controllers to handle registration and authentication.
|
124
|
+
|
125
|
+
USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
|
126
|
+
EOS
|
127
|
+
end
|
128
|
+
end
|