scaffold_logic 1.6.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 (121) hide show
  1. data/.document +5 -0
  2. data/Capfile +4 -0
  3. data/README.rdoc +29 -0
  4. data/Rakefile +51 -0
  5. data/VERSION +1 -0
  6. data/config/deploy.rb +41 -0
  7. data/lib/generators/scaffold_logic/layout/USAGE +7 -0
  8. data/lib/generators/scaffold_logic/layout/layout_generator.rb +38 -0
  9. data/lib/generators/scaffold_logic/layout/templates/_nav_tabs.html.erb +3 -0
  10. data/lib/generators/scaffold_logic/layout/templates/images/icons/add.png +0 -0
  11. data/lib/generators/scaffold_logic/layout/templates/images/icons/collapsed.gif +0 -0
  12. data/lib/generators/scaffold_logic/layout/templates/images/icons/delete.png +0 -0
  13. data/lib/generators/scaffold_logic/layout/templates/images/icons/drag.png +0 -0
  14. data/lib/generators/scaffold_logic/layout/templates/images/icons/edit.png +0 -0
  15. data/lib/generators/scaffold_logic/layout/templates/images/icons/expanded.gif +0 -0
  16. data/lib/generators/scaffold_logic/layout/templates/images/icons/help_icon.png +0 -0
  17. data/lib/generators/scaffold_logic/layout/templates/images/icons/link_icon.png +0 -0
  18. data/lib/generators/scaffold_logic/layout/templates/images/icons/move.png +0 -0
  19. data/lib/generators/scaffold_logic/layout/templates/images/icons/move_white.png +0 -0
  20. data/lib/generators/scaffold_logic/layout/templates/images/icons/note.png +0 -0
  21. data/lib/generators/scaffold_logic/layout/templates/images/icons/note_white.png +0 -0
  22. data/lib/generators/scaffold_logic/layout/templates/images/icons/notification_icon_sprite.png +0 -0
  23. data/lib/generators/scaffold_logic/layout/templates/images/icons/spinner.gif +0 -0
  24. data/lib/generators/scaffold_logic/layout/templates/images/icons/view.png +0 -0
  25. data/lib/generators/scaffold_logic/layout/templates/images/icons/warning.png +0 -0
  26. data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_2.png +0 -0
  27. data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_box.png +0 -0
  28. data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_icon.png +0 -0
  29. data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_white.png +0 -0
  30. data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_asc.png +0 -0
  31. data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_desc.png +0 -0
  32. data/lib/generators/scaffold_logic/layout/templates/images/layout/back.png +0 -0
  33. data/lib/generators/scaffold_logic/layout/templates/images/layout/black_bar.png +0 -0
  34. data/lib/generators/scaffold_logic/layout/templates/images/layout/breadcrumb_bg.png +0 -0
  35. data/lib/generators/scaffold_logic/layout/templates/images/layout/button_bg.png +0 -0
  36. data/lib/generators/scaffold_logic/layout/templates/images/layout/content_left_bg.png +0 -0
  37. data/lib/generators/scaffold_logic/layout/templates/images/layout/content_right_bg.png +0 -0
  38. data/lib/generators/scaffold_logic/layout/templates/images/layout/credit_cards.gif +0 -0
  39. data/lib/generators/scaffold_logic/layout/templates/images/layout/footer_bg.png +0 -0
  40. data/lib/generators/scaffold_logic/layout/templates/images/layout/h1_bg.png +0 -0
  41. data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg.png +0 -0
  42. data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg_for_table.png +0 -0
  43. data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_grey.png +0 -0
  44. data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_purple.png +0 -0
  45. data/lib/generators/scaffold_logic/layout/templates/images/layout/legend_bg.png +0 -0
  46. data/lib/generators/scaffold_logic/layout/templates/images/layout/menu_box_bg.png +0 -0
  47. data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border.png +0 -0
  48. data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_2.png +0 -0
  49. data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_3.png +0 -0
  50. data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_4.png +0 -0
  51. data/lib/generators/scaffold_logic/layout/templates/images/layout/tab.png +0 -0
  52. data/lib/generators/scaffold_logic/layout/templates/images/layout/tab_active.png +0 -0
  53. data/lib/generators/scaffold_logic/layout/templates/images/layout/table_header.png +0 -0
  54. data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_bg.jpg +0 -0
  55. data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_error_bg.png +0 -0
  56. data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg.png +0 -0
  57. data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg_selected.png +0 -0
  58. data/lib/generators/scaffold_logic/layout/templates/images/src/black_bar.psd +0 -0
  59. data/lib/generators/scaffold_logic/layout/templates/images/src/branding.psd +0 -0
  60. data/lib/generators/scaffold_logic/layout/templates/images/src/legend_bg.psd +0 -0
  61. data/lib/generators/scaffold_logic/layout/templates/images/src/menu_icons.psd +0 -0
  62. data/lib/generators/scaffold_logic/layout/templates/layout.html.erb +49 -0
  63. data/lib/generators/scaffold_logic/layout/templates/layout_helper.rb +16 -0
  64. data/lib/generators/scaffold_logic/layout/templates/stylesheets/application.css +881 -0
  65. data/lib/generators/scaffold_logic/layout/templates/stylesheets/core.css +1146 -0
  66. data/lib/generators/scaffold_logic/layout/templates/stylesheets/core_ie.css +52 -0
  67. data/lib/generators/scaffold_logic/layout/templates/stylesheets/csshover3.htc +14 -0
  68. data/lib/generators/scaffold_logic/scaffold/USAGE +48 -0
  69. data/lib/generators/scaffold_logic/scaffold/scaffold_generator.rb +230 -0
  70. data/lib/generators/scaffold_logic/scaffold/templates/actions/create.rb +9 -0
  71. data/lib/generators/scaffold_logic/scaffold/templates/actions/destroy.rb +6 -0
  72. data/lib/generators/scaffold_logic/scaffold/templates/actions/edit.rb +3 -0
  73. data/lib/generators/scaffold_logic/scaffold/templates/actions/index.rb +3 -0
  74. data/lib/generators/scaffold_logic/scaffold/templates/actions/new.rb +3 -0
  75. data/lib/generators/scaffold_logic/scaffold/templates/actions/show.rb +3 -0
  76. data/lib/generators/scaffold_logic/scaffold/templates/actions/update.rb +9 -0
  77. data/lib/generators/scaffold_logic/scaffold/templates/controller.rb +7 -0
  78. data/lib/generators/scaffold_logic/scaffold/templates/helper.rb +2 -0
  79. data/lib/generators/scaffold_logic/scaffold/templates/migration.rb +16 -0
  80. data/lib/generators/scaffold_logic/scaffold/templates/model.rb +18 -0
  81. data/lib/generators/scaffold_logic/scaffold/templates/mongoid_model.rb +30 -0
  82. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/create.rb +10 -0
  83. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/destroy.rb +5 -0
  84. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  85. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/index.rb +5 -0
  86. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  87. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  88. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  89. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/controller.rb +12 -0
  90. data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/model.rb +5 -0
  91. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  92. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  93. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  94. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  95. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  96. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  97. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  98. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/controller.rb +5 -0
  99. data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/model.rb +7 -0
  100. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  101. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  102. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  103. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  104. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  105. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  106. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  107. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/controller.rb +5 -0
  108. data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/model.rb +7 -0
  109. data/lib/generators/scaffold_logic/scaffold/templates/views/erb/_form.html.erb +39 -0
  110. data/lib/generators/scaffold_logic/scaffold/templates/views/erb/edit.html.erb +5 -0
  111. data/lib/generators/scaffold_logic/scaffold/templates/views/erb/index.html.erb +32 -0
  112. data/lib/generators/scaffold_logic/scaffold/templates/views/erb/new.html.erb +5 -0
  113. data/lib/generators/scaffold_logic/scaffold/templates/views/erb/show.html.erb +22 -0
  114. data/lib/scaffold_logic.rb +198 -0
  115. data/lib/scaffold_logic/data_import.rb +80 -0
  116. data/lib/scaffold_logic/form_helper.rb +148 -0
  117. data/lib/scaffold_logic/helper.rb +174 -0
  118. data/lib/scaffold_logic/menu_helper.rb +27 -0
  119. data/lib/scaffold_logic/tab_interface_helper.rb +125 -0
  120. data/scaffold_logic.gemspec +154 -0
  121. metadata +184 -0
@@ -0,0 +1,30 @@
1
+ class <%= class_name %>
2
+ include Mongoid::Document
3
+ <%- unless options[:skip_timestamps] -%>
4
+ include Mongoid::Timestamps
5
+ <%- end -%>
6
+
7
+ # Attributes =====================================================================================
8
+ <%- for attribute in model_attributes -%>
9
+ field :<%= attribute.name %><%= attribute.type.to_s.downcase == "string" ? "" : ", :type => #{attribute.type.to_s.capitalize}" -%>
10
+
11
+ <%- end -%>
12
+
13
+ # Indices ========================================================================================
14
+
15
+ # Constants ======================================================================================
16
+
17
+ # Scopes =========================================================================================
18
+
19
+ # Relationships ==================================================================================
20
+
21
+ # Behavior =======================================================================================
22
+
23
+ # Callbacks ======================================================================================
24
+
25
+ # Validations ====================================================================================
26
+
27
+ # Class methods ==================================================================================
28
+
29
+ # Instance methods ===============================================================================
30
+ end
@@ -0,0 +1,10 @@
1
+ it 'posts create action and renders new template when model is invalid' do
2
+ <%= class_name %>.any_instance.stubs(:save).returns(false)
3
+ post :create
4
+ response.should render_template(:new)
5
+ end
6
+
7
+ it 'posts create action and redirects' do
8
+ post :create
9
+ response.should be_redirect
10
+ end
@@ -0,0 +1,5 @@
1
+ it 'deletes destroy action and redirects' do
2
+ @<%= singular_name %>.expects(:destroy)
3
+ delete :destroy, :id => 1
4
+ response.should be_redirect
5
+ end
@@ -0,0 +1,4 @@
1
+ it 'gets edit action' do
2
+ get :edit, :id => 1
3
+ response.should render_template(:edit)
4
+ end
@@ -0,0 +1,5 @@
1
+ it 'gets index action' do
2
+ <%= class_name %>.stubs(:find).returns([@<%= singular_name %>])
3
+ get :index
4
+ response.should render_template(:index)
5
+ end
@@ -0,0 +1,4 @@
1
+ it 'gets new action' do
2
+ get :new
3
+ response.should render_template(:new)
4
+ end
@@ -0,0 +1,4 @@
1
+ it 'gets show action' do
2
+ get :show, :id => 1
3
+ response.should render_template(:show)
4
+ end
@@ -0,0 +1,11 @@
1
+ it 'puts update action and renders edit template when model is invalid' do
2
+ <%= class_name %>.any_instance.stubs(:save).returns(false)
3
+ put :update, :id => 1
4
+ response.should render_template(:edit)
5
+ end
6
+
7
+ it 'puts update action and redirects' do
8
+ <%= class_name %>.any_instance.stubs(:save).returns(true)
9
+ put :update, :id => 1
10
+ response.should be_redirect
11
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+ before :each do
5
+ @<%= singular_name %> = <%= class_name %>.new
6
+ <%= class_name %>.stubs(:find).returns(@<%= singular_name %>)
7
+ <%= class_name %>.any_instance.stubs(:save).returns(true)
8
+ <%= class_name %>.any_instance.stubs(:to_param).returns('1')
9
+ end
10
+
11
+ <%= controller_methods 'tests/rspec/actions' %>
12
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ it 'should have specs'
5
+ 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,39 @@
1
+ <%% if @<%= singular_name %>.errors.any? %>
2
+ <div id="error_explanation">
3
+ <h2>Please correct the following errors:</h2>
4
+ <%% @<%= singular_name %>.errors.to_a.in_groups(2, false).each do |group| %>
5
+ <ul>
6
+ <%% group.each do |msg| %>
7
+ <li><%%= msg %></li>
8
+ <%% end %>
9
+ </ul>
10
+ <%% end %>
11
+ <br style="clear: both;" />
12
+ </div>
13
+ <br style="clear: both;" />
14
+ <%% end %>
15
+
16
+ <fieldset class="form_container">
17
+ <%%= legend_tag 'About This <%= singular_name.titleize -%>' -%>
18
+
19
+ <%- model_attributes.in_groups(2).each do |group| -%>
20
+ <div class="form_column">
21
+ <%- group.each do |attribute| -%>
22
+ <%- if attribute -%>
23
+ <%- if attribute.field_type == :check_box -%>
24
+ <%%= f.<%= attribute.field_type -%> :<%= attribute.name -%>, :inline_label => 'Yes' -%>
25
+ <%- else -%>
26
+ <%%= f.<%= attribute.field_type -%> :<%= attribute.name -%> -%>
27
+ <%- end -%>
28
+ <%- end -%>
29
+ <%- end -%>
30
+ </div>
31
+ <%- end -%>
32
+ <br style="clear: both;" />
33
+ <div class="link_block">
34
+ <%%= f.submit 'Save', :class => 'link_button' -%>
35
+ <%%= link_to 'Cancel', <%= plural_name -%>_path, :class => 'link_button' -%>
36
+ </div>
37
+ </fieldset>
38
+
39
+ <br style="clear: both;" />
@@ -0,0 +1,5 @@
1
+ <%% set_title 'Edit a <%= singular_name.titleize %>' %>
2
+
3
+ <%%= form_for @<%= singular_name %>, :url => <%= singular_name -%>_url(@<%= singular_name-%>) do |f| %>
4
+ <%%= render :partial => 'form', :locals => {:f => f } %>
5
+ <%%- end -%>
@@ -0,0 +1,32 @@
1
+ <%%- set_title '<%= plural_name.titleize -%>' -%>
2
+
3
+ <table class="standard">
4
+ <%%- if @<%= plural_name -%>.blank? -%>
5
+ <tr>
6
+ <th colspan="<%= model_attributes.size + 1 -%>"><em>No <%= plural_name.titleize.downcase -%> have been created yet.</em></th>
7
+ </tr>
8
+ <%%- else -%>
9
+ <tr>
10
+ <%- model_attributes.each do |attribute| -%>
11
+ <th><%%= sort_link('<%= plural_name -%>', '<%= attribute.name -%>', params) -%></th>
12
+ <%- end -%>
13
+ <th> </th>
14
+ </tr>
15
+
16
+ <%%- @<%= plural_name %>.each do |<%= singular_name -%>| -%>
17
+ <tr class="<%%= cycle('odd', 'even') -%>">
18
+ <%- model_attributes.each_with_index do |attribute, i| -%>
19
+ <%- if i == 0 -%>
20
+ <td><%%= link_to <%= singular_name -%>.<%= attribute.name -%>, <%= singular_name -%>_path(<%= singular_name -%>) -%></td>
21
+ <%- else -%>
22
+ <td><%%= <%= singular_name -%>.<%= attribute.name -%> -%></td>
23
+ <%- end -%>
24
+ <%- end -%>
25
+ <td class="crud_links"><%%= crud_links(<%= singular_name -%>, [:show, :edit, :destroy]) -%></td>
26
+ </tr>
27
+ <%%- end -%>
28
+ <%%- end -%>
29
+ </table>
30
+ <div class="link_block attached table">
31
+ <%%= link_to "New <%= singular_name.titleize -%>", new_<%= singular_name -%>_path, :class => 'link_button' -%>
32
+ </div>
@@ -0,0 +1,5 @@
1
+ <%% set_title 'Create a New <%= singular_name.titleize %>' %>
2
+
3
+ <%%= form_for @<%= singular_name %>, :url => <%= plural_name -%>_url do |f| %>
4
+ <%%= render :partial => 'form', :locals => {:f => f } %>
5
+ <%%- end -%>
@@ -0,0 +1,22 @@
1
+ <%%- set_title '<%= singular_name.titleize -%> Details' -%>
2
+
3
+ <fieldset class="form_container">
4
+ <%%= legend_tag 'About This <%= singular_name.titleize -%>' -%>
5
+
6
+ <%- model_attributes.in_groups(2).each do |group| -%>
7
+ <div class="form_column">
8
+ <%- group.each do |attribute| -%>
9
+ <%- if attribute -%>
10
+ <%%= faux_field '<%= attribute.human_name.titleize %>', @<%= singular_name -%>.<%= attribute.name -%> %>
11
+ <%- end -%>
12
+ <%- end -%>
13
+ </div>
14
+ <%- end -%>
15
+ <br style="clear: both;" />
16
+ </fieldset>
17
+
18
+ <div class="link_block attached">
19
+ <%%= link_to 'Edit', edit_<%= singular_name -%>_path(@<%= singular_name -%>), :class => 'link_button' -%>
20
+ <%%= link_to 'Back', <%= plural_name -%>_path, :class => 'link_button' -%>
21
+ </div>
22
+
@@ -0,0 +1,198 @@
1
+ require 'scaffold_logic/data_import'
2
+ require 'scaffold_logic/form_helper'
3
+ require 'scaffold_logic/helper'
4
+ require 'scaffold_logic/menu_helper'
5
+ require 'scaffold_logic/tab_interface_helper'
6
+
7
+ include ScaffoldLogic::FormHelper
8
+
9
+ # == Configuration
10
+ #
11
+ # === Configure your application to default to the custom form builder
12
+ #
13
+ # In app/controllers/application_controller.rb:
14
+ #
15
+ # class ApplicationController < ActionController::Base
16
+ # ActionView::Base.default_form_builder = ScaffoldLogic::FormBuilder
17
+ #
18
+ # == Usage
19
+ #
20
+ # === Default form field with label:
21
+ #
22
+ # <%= f.text_field :last_name -%>
23
+ #
24
+ # Returns:
25
+ #
26
+ # <fieldset>
27
+ # <label for="user_last_name">Last Name</label>
28
+ # <input id="user_last_name" name="user[last_name]" size="30" type="text" />
29
+ # </fieldset>
30
+ #
31
+ # === Form field with custom label:
32
+ #
33
+ # <%= f.text_field :first_name, :label => 'Custom' -%>
34
+ #
35
+ # Returns:
36
+ #
37
+ # <fieldset>
38
+ # <label for="user_first_name">Custom</label>
39
+ # <input id="user_first_name" name="user[first_name]" size="30" type="text" />
40
+ # </fieldset>
41
+ #
42
+ # === Form field with no label
43
+ #
44
+ # <%= f.text_field :search, :label => false -%>
45
+ #
46
+ # Returns:
47
+ #
48
+ # <input id="search" name="search" size="30" type="text" />
49
+ #
50
+ # === Form field with inline help (? icon which reveals help content when clicked):
51
+ #
52
+ # <%= f.password_field :password %>
53
+ #
54
+ # Returns:
55
+ #
56
+ # <fieldset>
57
+ # <label for="password">Password: <img src="/images/icons/help_icon.png"
58
+ # onclick="$('password_help').toggle();" class='inline_icon' /></label>
59
+ # <div class="inline_help" id="password_help" style="display: none;">
60
+ # <p>Here are some detailed instructions on valid passwords.</p>
61
+ # </div>
62
+ # <input id="user_password" name="user[password]" size="30" type="password" />
63
+ # </fieldset>
64
+ #
65
+ # === Form field with instructions (show immediately below the label):
66
+ #
67
+ # <%= f.password_field :password_confirmation %>
68
+ #
69
+ # Returns:
70
+ #
71
+ # <fieldset>
72
+ # <label for="password_confirmation">
73
+ # Confirm Password:
74
+ # <span class="instructions">Enter your password again to confirm.</span>
75
+ # </label>
76
+ # <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
77
+ # </fieldset>
78
+ #
79
+ # === Check box with label in addition to checkbox value text
80
+ # (E.g. 'Foo' appears above the checkbox, and 'Something' next to it):
81
+ #
82
+ # <%= f.check_box :foo, :inline_label => 'Something' -%>
83
+ #
84
+ # Returns:
85
+ #
86
+ # <fieldset>
87
+ # <label for="user_foo">Foo</label>
88
+ # <input name="user[foo]" type="hidden" value="0" />
89
+ # <input id="user_foo" name="user[foo]" type="checkbox" value="1" />
90
+ # <label class="inline" for="user_foo">Something</label>
91
+ # </fieldset>
92
+ #
93
+ # === Don't wrap fields in a fieldset
94
+ #
95
+ # <%= f.text_field :query, :label => 'Search terms:', :fieldset => false -%>
96
+ #
97
+ # Returns
98
+ #
99
+ # <label for="search_terms_query">
100
+ # <input id="search_terms_query" name="search_terms_query" size="30" />
101
+ #
102
+ # == Troubleshooting
103
+ #
104
+ # If you're seeing double form labels, it's because you still have
105
+ # <%= label -%> elements in your forms.
106
+ #
107
+ module ScaffoldLogic
108
+ class FormBuilder < ActionView::Helpers::FormBuilder
109
+ helpers = field_helpers +
110
+ %w{date_select datetime_select time_select} +
111
+ %w{collection_select select country_select time_zone_select} -
112
+ %w{hidden_field label fields_for}
113
+
114
+ helpers.each do |name|
115
+ define_method(name) do |field, *args|
116
+
117
+ # capture first array as select choices
118
+ choices = args.detect{ |a| a.is_a?(Array) } || []
119
+ args.delete(choices)
120
+
121
+ # capture first hash as options
122
+ options = args.detect{ |a| a.is_a?(Hash) } || {}
123
+ args.delete(options)
124
+
125
+ # capture second hash as HTML options
126
+ html_options = args.detect{ |a| a.is_a?(Hash) } || {}
127
+ args.delete(html_options)
128
+
129
+ include_label = true
130
+
131
+ if options[:label].nil? # Not specified. Default to humanized version of field id.
132
+ _label_text = field.to_s.humanize.titleize
133
+ elsif options[:label]
134
+ _label_text = options.delete :label
135
+ # options[:label] is false!
136
+ else
137
+ include_label = options.delete(:label)
138
+ end
139
+
140
+ # Create label, if label text was provided or created.
141
+ if _label_text || options[:instructions]
142
+ if options[:instructions]
143
+ _label = tag_for_label_with_instructions(_label_text, field, options.delete(:instructions))
144
+ elsif options[:help]
145
+ _label = tag_for_label_with_inline_help(_label_text, field, options.delete(:help))
146
+ elsif include_label
147
+ _label = label(field, _label_text)
148
+ end
149
+ end
150
+
151
+ if options[:inline_label] # Handle inline labels, e.g. for checkboxes
152
+ _inline_label = label(field, options.delete(:inline_label), :class => 'inline')
153
+ end
154
+
155
+ _field = nil
156
+
157
+ if name == 'select'
158
+ _field = super(field, choices, options, html_options)
159
+ elsif name.include? 'select'
160
+ _field = super(field, options, html_options)
161
+ else
162
+ if name == 'radio_button'
163
+ # invert arguments
164
+ _field = super(field, args, options)
165
+ else
166
+ _field = args.compact.blank? ? super(field, options) : super(field, options, args)
167
+ end
168
+ end
169
+
170
+ if options[:fieldset] == false
171
+ "#{_label}#{_field}#{_inline_label.to_s}".html_safe
172
+ else
173
+ @template.content_tag(:fieldset, "#{_label}#{_field}#{_inline_label.to_s}".html_safe)
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ def self.mongoid_sorter_from( field, direction )
180
+ field ||= 'id'
181
+ direction ||= 'asc'
182
+ eval ":#{field}.#{direction}"
183
+ end
184
+ end
185
+
186
+ module ActionControllerMixin
187
+ def handle_date_time(params, model, attr)
188
+ if params && params[model] && params[model]["#{attr}(1i)"]
189
+ year = params[model]["#{attr}(1i)"]
190
+ month = params[model]["#{attr}(2i)"]
191
+ day = params[model]["#{attr}(3i)"]
192
+ params[model][attr] = Date.parse("#{month}/#{day}/#{year}")
193
+ params[model].delete("#{attr}(1i)")
194
+ params[model].delete("#{attr}(2i)")
195
+ params[model].delete("#{attr}(3i)")
196
+ end
197
+ end
198
+ end