fetty-generators 1.7.1

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 (75) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +69 -0
  4. data/Rakefile +3 -0
  5. data/lib/generators/fetty/layout/USAGE +26 -0
  6. data/lib/generators/fetty/layout/layout_generator.rb +44 -0
  7. data/lib/generators/fetty/layout/templates/application.js +55 -0
  8. data/lib/generators/fetty/layout/templates/error_messages_helper.rb +23 -0
  9. data/lib/generators/fetty/layout/templates/layout.html.erb +32 -0
  10. data/lib/generators/fetty/layout/templates/layout.html.haml +34 -0
  11. data/lib/generators/fetty/layout/templates/layout_helper.rb +22 -0
  12. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +23 -0
  13. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +23 -0
  14. data/lib/generators/fetty/layout/templates/stylesheet.css +166 -0
  15. data/lib/generators/fetty/layout/templates/stylesheet.sass +163 -0
  16. data/lib/generators/fetty/scaffold/USAGE +53 -0
  17. data/lib/generators/fetty/scaffold/scaffold_generator.rb +370 -0
  18. data/lib/generators/fetty/scaffold/templates/actions/create.rb +8 -0
  19. data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +5 -0
  20. data/lib/generators/fetty/scaffold/templates/actions/edit.rb +3 -0
  21. data/lib/generators/fetty/scaffold/templates/actions/index.rb +10 -0
  22. data/lib/generators/fetty/scaffold/templates/actions/new.rb +3 -0
  23. data/lib/generators/fetty/scaffold/templates/actions/show.rb +3 -0
  24. data/lib/generators/fetty/scaffold/templates/actions/update.rb +8 -0
  25. data/lib/generators/fetty/scaffold/templates/controller.rb +7 -0
  26. data/lib/generators/fetty/scaffold/templates/fixtures.yml +9 -0
  27. data/lib/generators/fetty/scaffold/templates/helper.rb +2 -0
  28. data/lib/generators/fetty/scaffold/templates/migration.rb +16 -0
  29. data/lib/generators/fetty/scaffold/templates/model.rb +7 -0
  30. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  31. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  32. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  33. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  34. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  35. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  36. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  37. data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +8 -0
  38. data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +7 -0
  39. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  40. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  41. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  42. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  43. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  44. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  45. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  46. data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +5 -0
  47. data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +7 -0
  48. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  49. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  50. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  51. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  52. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  53. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  54. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  55. data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +5 -0
  56. data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +7 -0
  57. data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +22 -0
  58. data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +50 -0
  59. data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +12 -0
  60. data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +13 -0
  61. data/lib/generators/fetty/scaffold/templates/views/erb/index.js.erb +1 -0
  62. data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +9 -0
  63. data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +26 -0
  64. data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +8 -0
  65. data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +33 -0
  66. data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +14 -0
  67. data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +12 -0
  68. data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +1 -0
  69. data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +8 -0
  70. data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +23 -0
  71. data/lib/generators/fetty/setup/USAGE +22 -0
  72. data/lib/generators/fetty/setup/setup_generator.rb +80 -0
  73. data/lib/generators/fetty/setup/templates/ability.rb +29 -0
  74. data/lib/generators/fetty.rb +38 -0
  75. metadata +137 -0
@@ -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
+ <%= instance_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= instance_name %>
4
+ response.should redirect_to(<%= items_url %>)
5
+ <%= class_name %>.exists?(<%= instance_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
+ render_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
+ <%= 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,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
+ <%= instance_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= instance_name %>
4
+ assert_redirected_to <%= items_url %>
5
+ assert !<%= class_name %>.exists?(<%= instance_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,22 @@
1
+ <%- unless @tinymce_name.empty? -%>
2
+ <%% content_for(:head) do %>
3
+ <%%= include_tiny_mce_if_needed %>
4
+ <%% end %>
5
+ <%- end -%>
6
+ <%%= simple_form_for @<%= instance_name %><%= ", :html => { :multipart => true }" unless @paperclip_name.empty? -%> do |f| %>
7
+ <%%= f.error_messages %>
8
+
9
+ <div class="inputs">
10
+ <%- for attribute in model_attributes -%>
11
+ <%- unless @tinymce_name.include?(attribute.name) -%>
12
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
13
+ <%- else -%>
14
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>, :input_html => { :class => 'mceEditor' } %>
15
+ <%- end -%>
16
+ <%- end -%>
17
+ </div>
18
+
19
+ <div class="actions">
20
+ <%%= f.button :submit %>
21
+ </div>
22
+ <%% end %>
@@ -0,0 +1,50 @@
1
+ <table class="pretty">
2
+ <tr>
3
+ <%- for attribute in model_attributes -%>
4
+ <%- unless @paperclip_name.include?(attribute.name) -%>
5
+ <th><%%= sort_link @search, :<%= attribute.name %> %></th>
6
+ <%- else -%>
7
+ <th><%= attribute.name %></th>
8
+ <%- end -%>
9
+ <%- end -%>
10
+ <%- if action? :show -%>
11
+ <th></th>
12
+ <%- end -%>
13
+ <%- if action? :edit -%>
14
+ <th></th>
15
+ <%- end -%>
16
+ <%- if action? :destroy -%>
17
+ <th></th>
18
+ <%- end -%>
19
+ </tr>
20
+ <%% for <%= instance_name %> in @<%= instances_name %> %>
21
+ <tr>
22
+ <%- for attribute in model_attributes -%>
23
+ <%- if @paperclip_name.include?(attribute.name) -%>
24
+ <td><%%= image_tag <%= instance_name %>.<%= attribute.name %>.url %></td>
25
+ <%- elsif @tinymce_name.include?(attribute.name) -%>
26
+ <td><%%= raw <%= instance_name %>.<%= attribute.name %> %></td>
27
+ <%- else -%>
28
+ <td><%%= <%= instance_name %>.<%= attribute.name %> %></td>
29
+ <%- end -%>
30
+ <%- end -%>
31
+ <%- if action? :show -%>
32
+ <td>
33
+ <%= generate_action_links(:read, instance_name, "Show", instance_name) %>
34
+ </td>
35
+ <%- end -%>
36
+ <%- if action? :edit -%>
37
+ <td>
38
+ <%= generate_action_links(:update, instance_name, "Edit", "edit_#{singular_table_name}_path(#{instance_name})") %>
39
+ </td>
40
+ <%- end -%>
41
+ <%- if action? :destroy -%>
42
+ <td>
43
+ <%= generate_action_links(:destroy, instance_name, "Destroy", instance_name) %>
44
+ </td>
45
+ <%- end -%>
46
+ </tr>
47
+ <%% end %>
48
+ </table>
49
+
50
+ <p><%%= will_paginate @<%= instances_name %> %></p>
@@ -0,0 +1,12 @@
1
+ <%% title "Edit <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <p>
6
+ <%- if action? :show -%>
7
+ <%= generate_action_links(:read, "@#{instance_name}", "Show", "@#{instance_name}") %> |
8
+ <%- end -%>
9
+ <%- if action? :index -%>
10
+ <%= generate_action_links(:index, class_name, "View All", items_path) %>
11
+ <%- end -%>
12
+ </p>
@@ -0,0 +1,13 @@
1
+ <%% title "<%= plural_name.titleize %>" %>
2
+
3
+ <%%= form_for @search, :url => <%= items_path %>, :html => {:id => "index_search", :method => :get} do |f| %>
4
+ <%%= f.text_field :<%= model_attributes[0].name %>_contains, :title => "Search by <%= model_attributes[0].name %>" %>
5
+ <%% end %>
6
+
7
+ <div id="index_table"><%= render_table %></div>
8
+
9
+ <%- if action? :new -%>
10
+ <p>
11
+ <%= generate_action_links(:create, class_name, "New #{singular_table_name.titleize}", "new_#{singular_table_name}_path") %>
12
+ </p>
13
+ <%- end -%>
@@ -0,0 +1 @@
1
+ $("#index_table").html("<%%= escape_javascript(render("table")) %>");
@@ -0,0 +1,9 @@
1
+ <%% title "New <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ <p>
7
+ <%= generate_action_links(:index, class_name, "Back to List", items_path) %>
8
+ </p>
9
+ <%- end -%>
@@ -0,0 +1,26 @@
1
+ <%% title "<%= singular_name.titleize %>" %>
2
+
3
+ <%- for attribute in model_attributes -%>
4
+ <p>
5
+ <strong><%= attribute.human_name.titleize %>:</strong>
6
+ <%- if @paperclip_name.include?(attribute.name) -%>
7
+ <%%= image_tag @<%= instance_name %>.<%= attribute.name %>.url %>
8
+ <%- elsif @tinymce_name.include?(attribute.name) -%>
9
+ <%%= raw @<%= instance_name %>.<%= attribute.name %> %>
10
+ <%- else -%>
11
+ <%%= @<%= instance_name %>.<%= attribute.name %> %>
12
+ <%- end -%>
13
+ </p>
14
+ <%- end -%>
15
+
16
+ <p>
17
+ <%- if action? :edit -%>
18
+ <%= generate_action_links(:update, "@#{instance_name}", "Edit", "edit_#{singular_table_name}_path(@#{instance_name})") %> |
19
+ <%- end -%>
20
+ <%- if action? :destroy -%>
21
+ <%= generate_action_links(:destroy, "@#{instance_name}", "Destroy", "@#{instance_name}") %> |
22
+ <%- end -%>
23
+ <%- if action? :index -%>
24
+ <%= generate_action_links(:index, class_name, "View All", items_path) %>
25
+ <%- end -%>
26
+ </p>
@@ -0,0 +1,8 @@
1
+ = simple_form_for(<%= item_path :instance_variable => true %>) do |f|
2
+ = f.error_messages
3
+ .inputs
4
+ <%- for attribute in model_attributes -%>
5
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ .actions
8
+ = f.submit
@@ -0,0 +1,33 @@
1
+ %table{:class => "pretty"}
2
+ %tr
3
+ <%- for attribute in model_attributes -%>
4
+ %th= sort_link @search, :<%= attribute.name %>
5
+ <%- end -%>
6
+ <%- if action? :show -%>
7
+ %th
8
+ <%- end -%>
9
+ <%- if action? :edit -%>
10
+ %th
11
+ <%- end -%>
12
+ <%- if action? :destroy -%>
13
+ %th
14
+ <%- end -%>
15
+ - for <%= instance_name %> in @<%= instances_name %>
16
+ %tr
17
+ <%- for attribute in model_attributes -%>
18
+ %td= <%= instance_name %>.<%= attribute.name %>
19
+ <%- end -%>
20
+ <%- if action? :show -%>
21
+ - if can? :read, <%= instance_name %>
22
+ %td= link_to 'Show', <%= instance_name %>
23
+ <%- end -%>
24
+ <%- if action? :edit -%>
25
+ - if can? :update, <%= instance_name %>
26
+ %td= link_to 'Edit', <%= item_path :action => :edit %>
27
+ <%- end -%>
28
+ <%- if action? :destroy -%>
29
+ - if can? :destroy, <%= instance_name %>
30
+ %td= link_to 'Destroy', <%= item_path %>, :confirm => 'Are you sure?', :method => :delete
31
+ <%- end -%>
32
+
33
+ %p= will_paginate @<%= plural_name %>
@@ -0,0 +1,14 @@
1
+ - title "Edit <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ %p
6
+ <%- if action? :show -%>
7
+ - if can? :read, @<%= singular_name %>
8
+ = link_to "Show", @<%= singular_name %>
9
+ |
10
+ <%- end -%>
11
+ <%- if action? :index -%>
12
+ - if can? :index, <%= singular_name.titleize %>
13
+ = link_to "View All", <%= items_path %>
14
+ <%- end -%>
@@ -0,0 +1,12 @@
1
+ - title "<%= plural_name.titleize %>"
2
+
3
+ = form_for @search, :url => <%= items_path %>, :html => {:id => "index_search", :method => :get} do |f|
4
+ = f.text_field :<%= model_attributes[0].name %>_contains, :title => "Search by <%= model_attributes[0].name %>"
5
+
6
+ #index_table
7
+ <%= render_table %>
8
+
9
+ <%- if actions? :new -%>
10
+ - if can? :create, <%= singular_name.titleize %>
11
+ %p= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path
12
+ <%- end -%>
@@ -0,0 +1 @@
1
+ != "$('#index_table').html('#{escape_javascript(render :partial => 'table')}');"
@@ -0,0 +1,8 @@
1
+ - title "New <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ - if can? :index, <%= singular_name.titleize %>
7
+ %p= link_to "Back to List", <%= items_path %>
8
+ <%- end -%>
@@ -0,0 +1,23 @@
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
+ - if can? :update, @<%= singular_name %>
12
+ = link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %>
13
+ |
14
+ <%- end -%>
15
+ <%- if action? :destroy -%>
16
+ - if can? :destroy, @<%= singular_name %>
17
+ = link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete
18
+ |
19
+ <%- end -%>
20
+ <%- if action? :index -%>
21
+ - if can? :index, <%= singular_name.titleize %>
22
+ = link_to "View All", <%= items_path %>
23
+ <%- end -%>
@@ -0,0 +1,22 @@
1
+ Description:
2
+ The fetty:setup generator creates a bunch of task to update your gemfile
3
+ with necessary gem need for you to build your rails app.
4
+ the basic installation required you to have :
5
+ - meta_search
6
+ - simple_form
7
+ - will_paginate
8
+ - jquery-rails
9
+ and the optional gems for Authentication & Autorization using :
10
+ - Devise
11
+ - CanCan
12
+
13
+ Examples:
14
+ rails generate fetty:setup
15
+
16
+ this default command will add gems to your Gemfile and install
17
+ some necessary files. both required and optional gems.
18
+ if you like to install minimum for layout and scaffolding using
19
+ fetty-generators, or you already have diffrent gems for authentication
20
+ or authorization you could skip the optional setup :
21
+
22
+ rails generate fetty:setup --skip-optional
@@ -0,0 +1,80 @@
1
+ require 'generators/fetty'
2
+
3
+ module Fetty
4
+ module Generators
5
+ class SetupGenerator < Base
6
+
7
+ class_option :required, :desc => 'Only install required gems [meta_where, meta_search, will_paginate, simple_form, jquery-rails]', :type => :boolean, :default => true
8
+ class_option :optional, :desc => 'Only install optional gems such as [devise, cancan, paperclip, tiny_mce]', :type => :boolean, :default => true
9
+
10
+ def add_install_gems
11
+
12
+ #required
13
+ if options.required?
14
+ add_gem("meta_where")
15
+ add_gem("meta_search")
16
+ add_gem("will_paginate")
17
+
18
+ add_gem("simple_form")
19
+ generate("simple_form:install")
20
+
21
+ add_gem("jquery-rails")
22
+ generate("jquery:install")
23
+ end
24
+
25
+ # optional
26
+ if options.optional?
27
+ install_devise
28
+ install_cancan
29
+ install_paperclip
30
+ install_tiny_mce
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def install_devise
37
+ opt = ask("Would you like to install Devise for authentication? [yes]")
38
+ if opt == "yes" || opt.blank?
39
+ add_gem("devise")
40
+ generate("devise:install")
41
+ model_name = ask("Would you like the user model to be called? [user]")
42
+ model_name = "user" if model_name.blank?
43
+ generate("devise", model_name)
44
+ opt = ask("Would you like to set global authentications in application_controller.rb? [yes]")
45
+ if opt == "yes" || opt.blank?
46
+ inject_into_file 'app/controllers/application_controller.rb', :after => "class ApplicationController < ActionController::Base" do
47
+ "\n before_filter :authenticate_user!"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def install_cancan
54
+ opt = ask("Would you like to install CanCan for authorization? [yes]")
55
+ if opt == "yes" || opt.blank?
56
+ add_gem("cancan","~> 1.5.0")
57
+ copy_file 'ability.rb', 'app/models/ability.rb'
58
+ inject_into_file 'app/controllers/application_controller.rb', :after => "class ApplicationController < ActionController::Base" do
59
+ "\n rescue_from CanCan::AccessDenied do |exception| flash[:alert] = exception.message; redirect_to root_url end;"
60
+ end
61
+ end
62
+ end
63
+
64
+ def install_paperclip
65
+ opt = ask("Would you like to install Paperclip for handling your attachment? [yes]")
66
+ if opt == "yes" || opt.blank?
67
+ add_gem("paperclip")
68
+ end
69
+ end
70
+
71
+ def install_tiny_mce
72
+ opt = ask("Would you like to install Tiny-MCE Editor? [yes]")
73
+ if opt == "yes" || opt.blank?
74
+ add_gem("tiny_mce")
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ # Define abilities for the passed in user here. For example:
6
+ #
7
+ # user ||= User.new # guest user (not logged in)
8
+ # if user.admin?
9
+ # can :manage, :all
10
+ # else
11
+ # can :read, :all
12
+ # end
13
+ #
14
+ # The first argument to `can` is the action you are giving the user permission to do.
15
+ # If you pass :manage it will apply to every action. Other common actions here are
16
+ # :read, :create, :update and :destroy.
17
+ #
18
+ # The second argument is the resource the user can perform the action on. If you pass
19
+ # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
20
+ #
21
+ # The third argument is an optional hash of conditions to further filter the objects.
22
+ # For example, here the user can only update published articles.
23
+ #
24
+ # can :update, Article, :published => true
25
+ #
26
+ # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
27
+ can :manage, :all
28
+ end
29
+ end