caseadilla 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +33 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.eot +0 -0
  8. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.svg +229 -0
  9. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.ttf +0 -0
  10. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.woff +0 -0
  11. data/app/assets/images/caseadilla/caseadilla.png +0 -0
  12. data/app/assets/javascripts/caseadilla/bootstrap.js +2114 -0
  13. data/app/assets/javascripts/caseadilla/bootstrap3-wysihtml5.js +521 -0
  14. data/app/assets/javascripts/caseadilla/caseadilla.js +51 -0
  15. data/app/assets/javascripts/caseadilla/html5shiv.js +8 -0
  16. data/app/assets/javascripts/caseadilla/wysihtml5-0.3.0.min.js +261 -0
  17. data/app/assets/stylesheets/caseadilla/bootstrap-glyphicons.css.scss +2 -0
  18. data/app/assets/stylesheets/caseadilla/bootstrap-theme.css +442 -0
  19. data/app/assets/stylesheets/caseadilla/bootstrap-wysihtml5.css +102 -0
  20. data/app/assets/stylesheets/caseadilla/bootstrap.css +6203 -0
  21. data/app/assets/stylesheets/caseadilla/caseadilla-bootstrap-overrides.css.scss +80 -0
  22. data/app/assets/stylesheets/caseadilla/caseadilla.scss +270 -0
  23. data/app/assets/stylesheets/caseadilla/login.css.scss +81 -0
  24. data/app/controllers/caseadilla/caseadilla_controller.rb +57 -0
  25. data/app/controllers/caseadilla/caseadilla_user_sessions_controller.rb +36 -0
  26. data/app/controllers/caseadilla/password_resets_controller.rb +64 -0
  27. data/app/controllers/caseadilla/roles_controller.rb +65 -0
  28. data/app/controllers/caseadilla/users_controller.rb +118 -0
  29. data/app/helpers/caseadilla/caseadilla_helper.rb +262 -0
  30. data/app/mailers/caseadilla/caseadilla_notification.rb +39 -0
  31. data/app/views/caseadilla/caseadilla/blank.html.erb +12 -0
  32. data/app/views/caseadilla/caseadilla_notification/generate_new_password.erb +12 -0
  33. data/app/views/caseadilla/caseadilla_notification/new_user_information.erb +12 -0
  34. data/app/views/caseadilla/caseadilla_notification/password_reset_instructions.erb +11 -0
  35. data/app/views/caseadilla/caseadilla_user_sessions/new.html.erb +39 -0
  36. data/app/views/caseadilla/roles/_form.html.erb +11 -0
  37. data/app/views/caseadilla/roles/_table.html.erb +28 -0
  38. data/app/views/caseadilla/roles/index.html.erb +15 -0
  39. data/app/views/caseadilla/roles/new.html.erb +18 -0
  40. data/app/views/caseadilla/roles/show.html.erb +18 -0
  41. data/app/views/caseadilla/users/index.html.erb +37 -0
  42. data/app/views/caseadilla/users/new.html.erb +50 -0
  43. data/app/views/caseadilla/users/show.html.erb +39 -0
  44. data/app/views/layouts/caseadilla_auth.html.erb +36 -0
  45. data/app/views/layouts/caseadilla_main.html.erb +119 -0
  46. data/caseadilla.gemspec +49 -0
  47. data/config/initializers/will_paginate.rb +40 -0
  48. data/config/routes.rb +23 -0
  49. data/lib/caseadilla.rb +14 -0
  50. data/lib/caseadilla/engine.rb +35 -0
  51. data/lib/caseadilla/version.rb +3 -0
  52. data/lib/generators/caseadilla/install/install_generator.rb +154 -0
  53. data/lib/generators/caseadilla/install/templates/app/assets/javascripts/caseadilla/custom.js +2 -0
  54. data/lib/generators/caseadilla/install/templates/app/assets/stylesheets/caseadilla/custom.css.scss +2 -0
  55. data/lib/generators/caseadilla/install/templates/app/helpers/caseadilla/config_helper.rb +45 -0
  56. data/lib/generators/caseadilla/install/templates/app/models/user.rb +24 -0
  57. data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_tab_navigation.html.erb +2 -0
  58. data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_top_navigation.html.erb +4 -0
  59. data/lib/generators/caseadilla/install/templates/public/robots.txt +5 -0
  60. data/lib/generators/caseadilla/install/templates/steak/config/initializers/caseadilla.rb +8 -0
  61. data/lib/generators/caseadilla/install/templates/steak/db/migrate/add_name_to_users.rb +9 -0
  62. data/lib/generators/caseadilla/install/templates/veggie/config/initializers/caseadilla.rb +8 -0
  63. data/lib/generators/caseadilla/scaffold/scaffold_generator.rb +111 -0
  64. data/lib/generators/caseadilla/scaffold/templates/controller.rb +72 -0
  65. data/lib/generators/caseadilla/scaffold/templates/migration.rb +13 -0
  66. data/lib/generators/caseadilla/scaffold/templates/model.rb +3 -0
  67. data/lib/generators/caseadilla/scaffold/templates/views/_form.html.erb +12 -0
  68. data/lib/generators/caseadilla/scaffold/templates/views/_table.html.erb +19 -0
  69. data/lib/generators/caseadilla/scaffold/templates/views/index.html.erb +15 -0
  70. data/lib/generators/caseadilla/scaffold/templates/views/new.html.erb +18 -0
  71. data/lib/generators/caseadilla/scaffold/templates/views/show.html.erb +18 -0
  72. data/lib/railties/tasks.rake +32 -0
  73. metadata +231 -0
@@ -0,0 +1,36 @@
1
+ module Caseadilla
2
+ class CaseadillaUserSessionsController < Caseadilla::CaseadillaController
3
+
4
+ skip_before_action :require_sign_in, :only => [:new, :create]
5
+ before_filter :requires_no_session_user, :except => [:destroy]
6
+
7
+ layout 'caseadilla_auth'
8
+
9
+ def new
10
+ @user_session = nil
11
+ end
12
+
13
+ def create
14
+ @user_session = nil
15
+ if @user_session.save
16
+ redirect_back_or_default :controller => :caseadilla, :action => :index
17
+ else
18
+ render :action => :new
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ current_user_session.destroy
24
+ redirect_back_or_default new_caseadilla_user_session_url
25
+ end
26
+
27
+ private
28
+
29
+ def requires_no_session_user
30
+ if current_user
31
+ redirect_to :controller => :caseadilla, :action => :index
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ module Caseadilla
2
+ class PasswordResetsController < Caseadilla::CaseadillaController
3
+
4
+ skip_before_filter :authorise
5
+ before_filter :load_user_using_perishable_token, :only => [:edit, :update]
6
+
7
+ layout 'caseadilla_auth'
8
+
9
+ def create
10
+ users = Caseadilla::User.where(:email => params[:recover_email]).all
11
+
12
+ if users.length > 0
13
+ users.each do |user|
14
+ user.send_password_reset_instructions
15
+ end
16
+
17
+ if users.length > 1
18
+ flash[:notice] = "Multiple accounts were found. Emails have been sent to " + params[:recover_email] + " with instructions on how to reset your passwords"
19
+ else
20
+ flash[:notice] = "An email has been sent to " + params[:recover_email] + " with instructions on how to reset your password"
21
+ end
22
+ else
23
+ flash[:warning] = "There is no user with that email"
24
+ end
25
+
26
+ redirect_to new_caseadilla_user_session_url
27
+ end
28
+
29
+ def edit
30
+ render
31
+ end
32
+
33
+ def update
34
+
35
+ if params[:caseadilla_user][:password].empty? || params[:caseadilla_user][:password_confirmation].empty?
36
+ flash.now[:warning] = "A field has been left empty"
37
+ else
38
+
39
+ @reset_user.password = params[:caseadilla_user][:password]
40
+ @reset_user.password_confirmation = params[:caseadilla_user][:password_confirmation]
41
+
42
+ if @reset_user.save
43
+ flash[:notice] = "Password successfully updated"
44
+ redirect_to new_caseadilla_user_session_url
45
+ return
46
+ end
47
+ end
48
+
49
+ render :action => :edit
50
+ end
51
+
52
+ private
53
+
54
+ def load_user_using_perishable_token
55
+
56
+ @reset_user = Caseadilla::User.find_using_perishable_token params[:token]
57
+
58
+ unless @reset_user
59
+ flash[:warning] = "Your account could not be located. Try to copy and paste the URL directly from the email."
60
+ redirect_to new_caseadilla_user_session_url
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,65 @@
1
+ module Caseadilla
2
+ class RolesController < Caseadilla::CaseadillaController
3
+ filter_resource_access
4
+
5
+ ## optional filters for defining usage according to Caseadilla::AdminUser access_levels
6
+ # before_filter :needs_admin, :except => [:action1, :action2]
7
+ # before_filter :needs_admin_or_current_user, :only => [:action1, :action2]
8
+
9
+ def index
10
+ @caseadilla_page_title = 'Roles'
11
+ @roles = Role.order(sort_order(:title)).paginate :page => params[:page]
12
+ end
13
+
14
+ def show
15
+ @caseadilla_page_title = 'View role'
16
+ @role = Role.find params[:id]
17
+ end
18
+
19
+ def new
20
+ @caseadilla_page_title = 'Add a new role'
21
+ @role = Role.new
22
+ end
23
+
24
+ def create
25
+ @role = Role.new role_params
26
+
27
+ if @role.save
28
+ flash[:notice] = 'Role created'
29
+ redirect_to caseadilla_roles_path
30
+ else
31
+ flash.now[:warning] = 'There were problems when trying to create a new role'
32
+ render :action => :new
33
+ end
34
+ end
35
+
36
+ def update
37
+ @caseadilla_page_title = 'Update role'
38
+
39
+ @role = Role.find params[:id]
40
+
41
+ if @role.update_attributes role_params
42
+ flash[:notice] = 'Role has been updated'
43
+ redirect_to caseadilla_roles_path
44
+ else
45
+ flash.now[:warning] = 'There were problems when trying to update this role'
46
+ render :action => :show
47
+ end
48
+ end
49
+
50
+ def destroy
51
+ @role = Role.find params[:id]
52
+
53
+ @role.destroy
54
+ flash[:notice] = 'Role has been deleted'
55
+ redirect_to caseadilla_roles_path
56
+ end
57
+
58
+ private
59
+
60
+ def role_params
61
+ params.require(:role).permit(:title)
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,118 @@
1
+ require 'securerandom'
2
+
3
+ module Caseadilla
4
+ class UsersController < Caseadilla::CaseadillaController
5
+ filter_resource_access
6
+
7
+ # before_filter :needs_admin, :except => [:show, :destroy, :update, :update_password]
8
+ # before_filter :needs_or_current_user, :only => [:show, :destroy, :update, :update_password]
9
+
10
+ def index
11
+ @caseadilla_page_title = "Users"
12
+ @users = User.order(sort_order(:id)).paginate :page => params[:page]
13
+ end
14
+
15
+ def new
16
+ @caseadilla_page_title = "Add a new user"
17
+ @caseadilla_user = User.new
18
+ @caseadilla_user.time_zone = Rails.configuration.time_zone
19
+ end
20
+
21
+ def create
22
+
23
+ generate_random_password if params[:generate_random_password]
24
+
25
+ @caseadilla_user = User.new caseadilla_user_params
26
+
27
+ if @caseadilla_user.save
28
+ flash[:notice] = "An email has been sent to " + @caseadilla_user.first_name + " with the new account details"
29
+ redirect_to caseadilla_users_path
30
+ else
31
+ flash.now[:warning] = "There were problems when trying to create a new user"
32
+ render :action => :new
33
+ end
34
+ end
35
+
36
+ def show
37
+ @caseadilla_user = User.find params[:id]
38
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > View user"
39
+ end
40
+
41
+ def update
42
+ @caseadilla_user = User.find params[:id]
43
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update user"
44
+
45
+ if @caseadilla_user.update_attributes caseadilla_user_params
46
+ flash[:notice] = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been updated"
47
+ redirect_to action: :index
48
+ else
49
+ flash.now[:warning] = "There were problems when trying to update this user"
50
+ render :action => :show
51
+ return
52
+ end
53
+ end
54
+
55
+ def update_password
56
+ @caseadilla_user = User.find params[:id]
57
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update password"
58
+
59
+ if @caseadilla_user.valid_password? params[:form_current_password]
60
+ if params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
61
+ flash[:warning] = "New password cannot be blank"
62
+ elsif @caseadilla_user.update_attributes caseadilla_user_params
63
+ flash[:notice] = "Your password has been changed"
64
+ else
65
+ flash[:warning] = "There were problems when trying to change your password"
66
+ end
67
+ else
68
+ flash[:warning] = "The current password is incorrect"
69
+ end
70
+
71
+ redirect_to :action => :show
72
+ end
73
+
74
+ def reset_password
75
+ @caseadilla_user = User.find params[:id]
76
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Reset password"
77
+
78
+ if params[:generate_random_password].blank? && params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
79
+ flash[:warning] = "New password cannot be blank"
80
+ else
81
+ generate_random_password if params[:generate_random_password]
82
+ @caseadilla_user.notify_of_new_password = true unless (@caseadilla_user.id == @session_user.id && params[:generate_random_password].blank?)
83
+
84
+ if @caseadilla_user.update_attributes caseadilla_user_params
85
+ unless @caseadilla_user.notify_of_new_password
86
+ flash[:notice] = "Your password has been reset"
87
+ else
88
+ flash[:notice] = "Password has been reset and #{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been notified by email"
89
+ end
90
+ else
91
+ flash[:warning] = "There were problems when trying to reset this user's password"
92
+ end
93
+ end
94
+
95
+ redirect_to :action => :show
96
+ end
97
+
98
+ def destroy
99
+ user = User.find params[:id]
100
+ user.destroy
101
+ flash[:notice] = "#{user.first_name} #{user.last_name} has been deleted"
102
+ redirect_to caseadilla_users_path
103
+ end
104
+
105
+ private
106
+
107
+ def generate_random_password
108
+ random_password = random_string = SecureRandom.hex
109
+ params[:user] = Hash.new if params[:user].blank?
110
+ params[:user].merge! ({:password => random_password, :password_confirmation => random_password})
111
+ end
112
+
113
+ def caseadilla_user_params
114
+ params.require(:user).permit(:email, :first_name, :last_name, :time_zone, :role, :role_id, :password, :password_confirmation)
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,262 @@
1
+ module Caseadilla
2
+ module CaseadillaHelper
3
+
4
+ def caseadilla_get_footer_string include_version = false
5
+ if include_version
6
+ "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'} #{caseadilla_get_full_version_string}, an open-source project.".html_safe
7
+ else
8
+ "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'}, an open-source project.".html_safe
9
+ end
10
+ end
11
+
12
+ def caseadilla_get_full_version_string
13
+ Caseadilla::VERSION
14
+ end
15
+
16
+ def caseadilla_get_short_version_string
17
+ Caseadilla::VERSION.slice(0..(str.index('.')))
18
+ end
19
+
20
+ def caseadilla_generate_page_title
21
+
22
+ if @caseadilla_page_title.nil?
23
+ return caseadilla_config_website_name
24
+ end
25
+
26
+ caseadilla_config_website_name + " > " + @caseadilla_page_title
27
+ end
28
+
29
+ def caseadilla_get_access_level_text level
30
+ case level
31
+ when $CASEIN_USER_ACCESS_LEVEL_ADMIN
32
+ return "Administrator"
33
+ when $CASEIN_USER_ACCESS_LEVEL_USER
34
+ return "User"
35
+ else
36
+ return "Unknown"
37
+ end
38
+ end
39
+
40
+ def caseadilla_get_access_level_array
41
+ [["Administrator", $CASEIN_USER_ACCESS_LEVEL_ADMIN], ["User", $CASEIN_USER_ACCESS_LEVEL_USER]]
42
+ end
43
+
44
+ def caseadilla_pagination_details objs
45
+ " <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
46
+ end
47
+
48
+ def caseadilla_table_cell_link contents, link, options = {}
49
+
50
+ if options.key? :caseadilla_truncate
51
+ contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
52
+ end
53
+
54
+ link_to "#{contents}".html_safe, link, options
55
+ end
56
+
57
+ def caseadilla_table_cell_no_link contents, options = {}
58
+
59
+ if options.key? :caseadilla_truncate
60
+ contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
61
+ end
62
+
63
+ "<div class='no-link'>#{contents}</div>".html_safe
64
+ end
65
+
66
+ def caseadilla_show_icon icon_name
67
+ "<div class='icon'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
68
+ end
69
+
70
+ def caseadilla_show_row_icon icon_name
71
+ "<div class='iconRow'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
72
+ end
73
+
74
+ def caseadilla_format_date date, format = "%b %d, %Y"
75
+ date.strftime(format)
76
+ end
77
+
78
+ def caseadilla_format_time time, format = "%H:%M"
79
+ time.strftime(format)
80
+ end
81
+
82
+ def caseadilla_format_datetime datetime, format = "%b %d, %Y %H:%M"
83
+ datetime.strftime(format)
84
+ end
85
+
86
+ def caseadilla_sort_link title, column, options = {}
87
+ condition = options[:unless] if options.has_key?(:unless)
88
+ icon_to_show_html = "<div class='table-header-icon'>&nbsp;</div>".html_safe
89
+ if params[:c].to_s == column.to_s
90
+ icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
91
+ icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
92
+ end
93
+ sort_dir = params[:d] == 'down' ? 'up' : 'down'
94
+ link_to_unless(condition, title, request.parameters.merge({:c => column, :d => sort_dir})) + icon_to_show_html
95
+ end
96
+
97
+ def caseadilla_yes_no_label value
98
+ if value
99
+ return "<span class='label label-success'>Yes</span>".html_safe
100
+ else
101
+ return "<span class='label label-danger'>No</span>".html_safe
102
+ end
103
+ end
104
+
105
+ def caseadilla_no_yes_label value
106
+ if value
107
+ return "<span class='label label-danger'>Yes</span>".html_safe
108
+ else
109
+ return "<span class='label label-success'>No</span>".html_safe
110
+ end
111
+ end
112
+
113
+ # Styled form tag helpers
114
+
115
+ def caseadilla_text_field form, obj, attribute, options = {}
116
+ caseadilla_form_tag_wrapper(form.text_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
117
+ end
118
+
119
+ def caseadilla_password_field form, obj, attribute, options = {}
120
+ caseadilla_form_tag_wrapper(form.password_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
121
+ end
122
+
123
+ def caseadilla_text_area form, obj, attribute, options = {}
124
+ caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
125
+ end
126
+
127
+ def caseadilla_text_area_wysiwyg form, obj, attribute, options = {}
128
+ options.reverse_merge!({style: "height: 250px;"})
129
+ caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control wysihtml5'))), form, obj, attribute, options).html_safe
130
+ end
131
+
132
+ def caseadilla_check_box form, obj, attribute, options = {}
133
+ form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_caseadilla_options(options))}</div>".html_safe
134
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
135
+ end
136
+
137
+ def caseadilla_check_box_group form, obj, check_boxes = {}
138
+ form_tags = ""
139
+
140
+ for check_box in check_boxes
141
+ form_tags += caseadilla_check_box form, obj, check_box[0], check_box[1]
142
+ end
143
+
144
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options)
145
+ end
146
+
147
+ def caseadilla_radio_button form, obj, attribute, tag_value, options = {}
148
+ form_tag = form.radio_button(obj, attribute, tag_value, strip_caseadilla_options(options))
149
+
150
+ if options.key? :caseadilla_button_label
151
+ form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{options[:caseadilla_button_label]}</span></div>".html_safe
152
+ end
153
+
154
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
155
+ end
156
+
157
+ def caseadilla_radio_button_group form, obj, radio_buttons = {}
158
+ form_tags = ""
159
+
160
+ for radio_button in radio_buttons
161
+ form_tags += caseadilla_radio_button form, obj, check_box[0], check_box[1], check_box[2]
162
+ end
163
+
164
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
165
+ end
166
+
167
+ def caseadilla_select form, obj, attribute, option_tags, options = {}
168
+ caseadilla_form_tag_wrapper(form.select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
169
+ end
170
+
171
+ def caseadilla_time_zone_select form, obj, attribute, option_tags, options = {}
172
+ caseadilla_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
173
+ end
174
+
175
+ def caseadilla_collection_select form, obj, attribute, collection, value_method, text_method, options = {}
176
+ caseadilla_form_tag_wrapper(collection_select(obj.class.name.downcase.to_sym, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
177
+ end
178
+
179
+ def caseadilla_collection_check_boxes form, obj, attribute, collection, value_method, text_method, options = {}
180
+ caseadilla_form_tag_wrapper(collection_check_boxes(obj, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
181
+ end
182
+
183
+ def caseadilla_date_select form, obj, attribute, options = {}
184
+ caseadilla_form_tag_wrapper("<div class='caseadilla-date-select'>".html_safe + form.date_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
185
+ end
186
+
187
+ def caseadilla_time_select form, obj, attribute, options = {}
188
+ caseadilla_form_tag_wrapper("<div class='caseadilla-time-select'>".html_safe + form.time_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
189
+ end
190
+
191
+ def caseadilla_datetime_select form, obj, attribute, options = {}
192
+ caseadilla_form_tag_wrapper("<div class='caseadilla-datetime-select'>".html_safe + form.datetime_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
193
+ end
194
+
195
+ def caseadilla_file_field form, obj, object_name, attribute, options = {}
196
+ class_hash = merged_class_hash(options, 'form-control')
197
+ contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_caseadilla_options(options)) + '</div>'
198
+
199
+ if options.key? :caseadilla_contents_preview
200
+ contents = options[:caseadilla_contents_preview].html_safe + contents.html_safe
201
+ end
202
+
203
+ caseadilla_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
204
+ end
205
+
206
+ def caseadilla_hidden_field form, obj, attribute, options = {}
207
+ form.hidden_field(attribute, strip_caseadilla_options(options)).html_safe
208
+ end
209
+
210
+ def caseadilla_custom_field form, obj, attribute, custom_contents, options = {}
211
+ caseadilla_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
212
+ end
213
+
214
+ protected
215
+
216
+ def strip_caseadilla_options options
217
+ options.reject {|key, value| key.to_s.include? "caseadilla_" }
218
+ end
219
+
220
+ def merged_class_hash options, new_class
221
+ if options.key? :class
222
+ new_class += " #{options[:class]}"
223
+ end
224
+
225
+ {:class => new_class}
226
+ end
227
+
228
+ def options_hash_with_merged_classes options, new_class
229
+ if options.key? :class
230
+ new_class += " #{options[:class]}"
231
+ end
232
+ options[:class] = new_class
233
+ options
234
+ end
235
+
236
+ def caseadilla_form_tag_wrapper form_tag, form, obj, attribute, options = {}
237
+ unless options.key? :caseadilla_label
238
+ human_attribute_name = attribute.to_s.humanize
239
+ else
240
+ human_attribute_name = options[:caseadilla_label]
241
+ end
242
+
243
+ sublabel = ""
244
+
245
+ if options.key? :caseadilla_sublabel
246
+ sublabel = " <small>#{options[:caseadilla_sublabel]}</small>".html_safe
247
+ end
248
+
249
+ html = ""
250
+
251
+ if obj && obj.errors[attribute].any?
252
+ html += "<div class='form-group has-error'>"
253
+ html += form.label(attribute, "#{human_attribute_name} #{obj.errors[attribute].first}".html_safe, :class => "control-label")
254
+ else
255
+ html += "<div class='form-group'>"
256
+ html += form.label(attribute, "#{human_attribute_name}#{sublabel}".html_safe, :class => "control-label")
257
+ end
258
+
259
+ html += "<div class='well'>#{form_tag}</div></div>"
260
+ end
261
+ end
262
+ end