scaffold_logic 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Capfile +4 -0
- data/README.rdoc +29 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/config/deploy.rb +41 -0
- data/lib/generators/scaffold_logic/layout/USAGE +7 -0
- data/lib/generators/scaffold_logic/layout/layout_generator.rb +38 -0
- data/lib/generators/scaffold_logic/layout/templates/_nav_tabs.html.erb +3 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/add.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/collapsed.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/delete.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/drag.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/edit.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/expanded.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/help_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/link_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/move.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/move_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/note.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/note_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/notification_icon_sprite.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/spinner.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/view.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_2.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_box.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_icon.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/icons/warning_white.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_asc.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/arrow_desc.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/back.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/black_bar.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/breadcrumb_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/button_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/content_left_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/content_right_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/credit_cards.gif +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/footer_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h1_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/h2_bg_for_table.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_grey.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/header_bg_purple.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/legend_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/menu_box_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_2.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_3.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/shadow_border_4.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/tab.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/tab_active.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/table_header.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_bg.jpg +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/text_field_error_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/layout/th_bg_selected.png +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/black_bar.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/branding.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/legend_bg.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/images/src/menu_icons.psd +0 -0
- data/lib/generators/scaffold_logic/layout/templates/layout.html.erb +49 -0
- data/lib/generators/scaffold_logic/layout/templates/layout_helper.rb +16 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/application.css +881 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/core.css +1146 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/core_ie.css +52 -0
- data/lib/generators/scaffold_logic/layout/templates/stylesheets/csshover3.htc +14 -0
- data/lib/generators/scaffold_logic/scaffold/USAGE +48 -0
- data/lib/generators/scaffold_logic/scaffold/scaffold_generator.rb +230 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/create.rb +9 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/destroy.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/scaffold_logic/scaffold/templates/actions/update.rb +9 -0
- data/lib/generators/scaffold_logic/scaffold/templates/controller.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/helper.rb +2 -0
- data/lib/generators/scaffold_logic/scaffold/templates/migration.rb +16 -0
- data/lib/generators/scaffold_logic/scaffold/templates/model.rb +18 -0
- data/lib/generators/scaffold_logic/scaffold/templates/mongoid_model.rb +30 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/create.rb +10 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/destroy.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/index.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/controller.rb +12 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/rspec/model.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/_form.html.erb +39 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/edit.html.erb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/index.html.erb +32 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/new.html.erb +5 -0
- data/lib/generators/scaffold_logic/scaffold/templates/views/erb/show.html.erb +22 -0
- data/lib/scaffold_logic.rb +198 -0
- data/lib/scaffold_logic/data_import.rb +80 -0
- data/lib/scaffold_logic/form_helper.rb +148 -0
- data/lib/scaffold_logic/helper.rb +174 -0
- data/lib/scaffold_logic/menu_helper.rb +27 -0
- data/lib/scaffold_logic/tab_interface_helper.rb +125 -0
- data/scaffold_logic.gemspec +154 -0
- 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,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,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,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,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,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,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
|