casein 5.3.2.0 → 5.4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +6 -6
- data/Rakefile +5 -4
- data/app/controllers/casein/admin_user_sessions_controller.rb +12 -14
- data/app/controllers/casein/admin_users_controller.rb +49 -50
- data/app/controllers/casein/casein_controller.rb +26 -24
- data/app/controllers/casein/password_resets_controller.rb +18 -21
- data/app/helpers/casein/casein_helper.rb +146 -155
- data/app/mailers/casein/casein_notification.rb +26 -27
- data/app/models/casein.rb +2 -0
- data/app/models/casein/admin_user.rb +50 -21
- data/app/models/casein/admin_user_session.rb +5 -3
- data/config/initializers/will_paginate.rb +12 -8
- data/config/routes.rb +10 -11
- data/lib/casein.rb +10 -8
- data/lib/casein/engine.rb +13 -14
- data/lib/casein/version.rb +4 -2
- data/lib/casein/version.rb.orig +10 -0
- data/lib/generators/casein/install/install_generator.rb +36 -35
- data/lib/generators/casein/install/templates/app/helpers/casein/config_helper.rb +8 -8
- data/lib/generators/casein/install/templates/db/migrate/casein_create_admin_users.rb +4 -4
- data/lib/generators/casein/scaffold/scaffold_generator.rb +31 -30
- data/lib/railties/tasks.rake +10 -12
- metadata +40 -39
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Casein
|
2
4
|
module CaseinHelper
|
3
|
-
|
4
|
-
def casein_get_footer_string include_version = false
|
5
|
+
def casein_get_footer_string(include_version = false)
|
5
6
|
if include_version
|
6
7
|
"Running on #{link_to 'Casein', 'http://www.caseincms.com'} #{casein_get_full_version_string}, an open-source project.".html_safe
|
7
8
|
else
|
@@ -9,315 +10,305 @@ module Casein
|
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
def casein_get_version_info
|
13
14
|
Casein::VERSION_HASH
|
14
|
-
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
+
def casein_get_full_version_string
|
17
18
|
"v#{Casein::VERSION}"
|
18
|
-
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
def casein_get_short_version_string
|
21
22
|
version_info = casein_get_version_info
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def casein_generate_page_title
|
23
|
+
"v#{version_info[:major]}"
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def casein_generate_page_title
|
27
|
+
return casein_config_website_name if @casein_page_title.nil?
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
casein_config_website_name + ' > ' + @casein_page_title
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
def casein_get_access_level_text(level)
|
33
|
+
case level
|
36
34
|
when $CASEIN_USER_ACCESS_LEVEL_ADMIN
|
37
|
-
|
35
|
+
'Administrator'
|
38
36
|
when $CASEIN_USER_ACCESS_LEVEL_USER
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
'User'
|
38
|
+
else
|
39
|
+
'Unknown'
|
40
|
+
end
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
def casein_get_access_level_array
|
44
|
+
[['Administrator', $CASEIN_USER_ACCESS_LEVEL_ADMIN], ['User', $CASEIN_USER_ACCESS_LEVEL_USER]]
|
45
|
+
end
|
48
46
|
|
49
|
-
def casein_pagination_details
|
47
|
+
def casein_pagination_details(objs)
|
50
48
|
" <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
|
51
49
|
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
51
|
+
def casein_table_cell_link(contents, link, options = {})
|
52
|
+
if options.key? :casein_truncate
|
53
|
+
contents = truncate(contents, length: options[:casein_truncate], omission: '...')
|
54
|
+
end
|
58
55
|
|
59
|
-
|
56
|
+
link_to contents.to_s.html_safe, link, options
|
60
57
|
end
|
61
58
|
|
62
|
-
def casein_table_cell_no_link
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
59
|
+
def casein_table_cell_no_link(contents, options = {})
|
60
|
+
if options.key? :casein_truncate
|
61
|
+
contents = truncate(contents, length: options[:casein_truncate], omission: '...')
|
62
|
+
end
|
67
63
|
|
68
|
-
|
64
|
+
"<div class='no-link'>#{contents}</div>".html_safe
|
69
65
|
end
|
70
66
|
|
71
|
-
def casein_span_icon
|
67
|
+
def casein_span_icon(icon_name)
|
72
68
|
"<span class='glyphicon glyphicon-#{icon_name}' title='#{icon_name.titleize}'></span>"
|
73
69
|
end
|
74
70
|
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
def casein_show_icon(icon_name)
|
72
|
+
"<div class='icon'>#{casein_span_icon icon_name}</div>".html_safe
|
73
|
+
end
|
78
74
|
|
79
|
-
|
75
|
+
def casein_show_row_icon(icon_name)
|
80
76
|
"<div class='iconRow'>#{casein_span_icon icon_name}</div>".html_safe
|
81
|
-
|
77
|
+
end
|
82
78
|
|
83
|
-
def casein_format_date
|
79
|
+
def casein_format_date(date, format = '%b %d, %Y')
|
84
80
|
date.strftime(format)
|
85
81
|
end
|
86
82
|
|
87
|
-
def casein_format_time
|
83
|
+
def casein_format_time(time, format = '%H:%M')
|
88
84
|
time.strftime(format)
|
89
85
|
end
|
90
86
|
|
91
|
-
def casein_format_datetime
|
87
|
+
def casein_format_datetime(datetime, format = '%b %d, %Y %H:%M')
|
92
88
|
datetime.strftime(format)
|
93
89
|
end
|
94
90
|
|
95
|
-
def casein_sort_link
|
96
|
-
condition = options[:unless] if options.
|
91
|
+
def casein_sort_link(title, column, options = {})
|
92
|
+
condition = options[:unless] if options.key?(:unless)
|
97
93
|
icon_to_show_html = "<div class='table-header-icon'> </div>".html_safe
|
98
94
|
if params[:c].to_s == column.to_s
|
99
95
|
icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
|
100
96
|
icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
|
101
97
|
end
|
102
98
|
sort_dir = params[:d] == 'down' ? 'up' : 'down'
|
103
|
-
link_to_unless(condition, title, request.parameters.merge(
|
99
|
+
link_to_unless(condition, title, request.parameters.merge(c: column, d: sort_dir)) + icon_to_show_html
|
104
100
|
end
|
105
101
|
|
106
|
-
def casein_yes_no_label
|
102
|
+
def casein_yes_no_label(value)
|
107
103
|
if value
|
108
|
-
|
104
|
+
"<span class='label label-success'>Yes</span>".html_safe
|
109
105
|
else
|
110
|
-
|
106
|
+
"<span class='label label-danger'>No</span>".html_safe
|
111
107
|
end
|
112
108
|
end
|
113
109
|
|
114
|
-
def casein_no_yes_label
|
110
|
+
def casein_no_yes_label(value)
|
115
111
|
if value
|
116
|
-
|
112
|
+
"<span class='label label-danger'>Yes</span>".html_safe
|
117
113
|
else
|
118
|
-
|
114
|
+
"<span class='label label-success'>No</span>".html_safe
|
119
115
|
end
|
120
116
|
end
|
121
117
|
|
122
|
-
|
118
|
+
# Styled form tag helpers
|
123
119
|
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
def casein_text_field(form, obj, attribute, options = {})
|
121
|
+
casein_form_tag_wrapper(form.text_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
122
|
+
end
|
127
123
|
|
128
|
-
|
129
|
-
|
130
|
-
|
124
|
+
def casein_password_field(form, obj, attribute, options = {})
|
125
|
+
casein_form_tag_wrapper(form.password_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
126
|
+
end
|
131
127
|
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
def casein_text_area(form, obj, attribute, options = {})
|
129
|
+
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
130
|
+
end
|
135
131
|
|
136
|
-
|
137
|
-
|
138
|
-
|
132
|
+
def casein_text_area_big(form, obj, attribute, options = {})
|
133
|
+
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
134
|
+
end
|
139
135
|
|
140
|
-
|
141
|
-
|
136
|
+
def casein_check_box(form, obj, attribute, options = {})
|
137
|
+
form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_casein_options(options))}</div>".html_safe
|
142
138
|
casein_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
|
143
|
-
|
139
|
+
end
|
144
140
|
|
145
|
-
|
146
|
-
form_tags =
|
141
|
+
def casein_check_box_group(form, obj, check_boxes = {})
|
142
|
+
form_tags = ''
|
147
143
|
|
148
|
-
|
144
|
+
check_boxes.each do |check_box|
|
149
145
|
form_tags += casein_check_box form, obj, check_box[0], check_box[1]
|
150
146
|
end
|
151
147
|
|
152
148
|
casein_form_tag_wrapper(form_tag, form, obj, attribute, options)
|
153
149
|
end
|
154
150
|
|
155
|
-
|
156
|
-
|
151
|
+
def casein_radio_button(form, obj, attribute, tag_value, options = {})
|
152
|
+
form_tag = form.radio_button(obj, attribute, tag_value, strip_casein_options(options))
|
157
153
|
|
158
|
-
|
159
|
-
|
160
|
-
|
154
|
+
if options.key? :casein_button_label
|
155
|
+
form_tag = '<div>' + form_tag + "<span class=\"rcText\">#{options[:casein_button_label]}</span></div>".html_safe
|
156
|
+
end
|
161
157
|
|
162
|
-
|
163
|
-
|
158
|
+
casein_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
|
159
|
+
end
|
164
160
|
|
165
|
-
|
166
|
-
form_tags =
|
161
|
+
def casein_radio_button_group(form, obj, radio_buttons = {})
|
162
|
+
form_tags = ''
|
167
163
|
|
168
|
-
|
164
|
+
radio_buttons.each do |_radio_button|
|
169
165
|
form_tags += casein_radio_button form, obj, check_box[0], check_box[1], check_box[2]
|
170
166
|
end
|
171
167
|
|
172
168
|
casein_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
|
173
169
|
end
|
174
170
|
|
175
|
-
|
176
|
-
|
177
|
-
html_options_to_use = merged_class_hash(options, 'form-control') #legacy support
|
171
|
+
def casein_select(form, obj, attribute, option_tags, options = {}, html_options = {})
|
172
|
+
html_options_to_use = merged_class_hash(options, 'form-control') # legacy support
|
178
173
|
html_options_to_use = options_hash_with_merged_classes(html_options, html_options_to_use[:class])
|
179
|
-
|
180
|
-
casein_form_tag_wrapper(form.select(attribute, option_tags, strip_casein_options(options), html_options_to_use), form, obj, attribute, options).html_safe
|
181
|
-
end
|
182
174
|
|
183
|
-
|
184
|
-
|
185
|
-
end
|
175
|
+
casein_form_tag_wrapper(form.select(attribute, option_tags, strip_casein_options(options), html_options_to_use), form, obj, attribute, options).html_safe
|
176
|
+
end
|
186
177
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
178
|
+
def casein_time_zone_select(form, obj, attribute, option_tags, options = {})
|
179
|
+
casein_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_casein_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
|
180
|
+
end
|
191
181
|
|
192
|
-
|
193
|
-
|
194
|
-
|
182
|
+
# e.g. casein_collection_select f, f.object, :article, :author_id, Author.all, :id, :name, { prompt: 'Select author' }
|
183
|
+
def casein_collection_select(form, obj, object_name, attribute, collection, value_method, text_method, options = {})
|
184
|
+
casein_form_tag_wrapper(collection_select(object_name, attribute, collection, value_method, text_method, strip_casein_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
|
185
|
+
end
|
186
|
+
|
187
|
+
def casein_date_select(form, obj, attribute, options = {})
|
188
|
+
casein_form_tag_wrapper("<div class='casein-date-select'>".html_safe + form.date_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + '</div>'.html_safe, form, obj, attribute, options).html_safe
|
189
|
+
end
|
195
190
|
|
196
|
-
|
197
|
-
|
198
|
-
|
191
|
+
def casein_time_select(form, obj, attribute, options = {})
|
192
|
+
casein_form_tag_wrapper("<div class='casein-time-select'>".html_safe + form.time_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + '</div>'.html_safe, form, obj, attribute, options).html_safe
|
193
|
+
end
|
199
194
|
|
200
|
-
|
201
|
-
|
202
|
-
|
195
|
+
def casein_datetime_select(form, obj, attribute, options = {})
|
196
|
+
casein_form_tag_wrapper("<div class='casein-datetime-select'>".html_safe + form.datetime_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + '</div>'.html_safe, form, obj, attribute, options).html_safe
|
197
|
+
end
|
203
198
|
|
204
|
-
|
205
|
-
|
206
|
-
|
199
|
+
def casein_file_field(form, obj, _object_name, attribute, options = {})
|
200
|
+
class_hash = merged_class_hash(options, 'form-control')
|
201
|
+
contents = "<div class='#{class_hash[:class]}'>" + form.file_field(attribute, strip_casein_options(options)) + '</div>'
|
207
202
|
|
208
203
|
if options.key? :casein_contents_preview
|
209
204
|
contents = options[:casein_contents_preview].html_safe + contents.html_safe
|
210
205
|
end
|
211
206
|
|
212
|
-
|
213
|
-
|
207
|
+
casein_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
|
208
|
+
end
|
214
209
|
|
215
|
-
|
216
|
-
|
217
|
-
|
210
|
+
def casein_hidden_field(form, _obj, attribute, options = {})
|
211
|
+
form.hidden_field(attribute, strip_casein_options(options)).html_safe
|
212
|
+
end
|
218
213
|
|
219
|
-
def casein_color_field
|
220
|
-
|
214
|
+
def casein_color_field(form, obj, attribute, options = {})
|
215
|
+
casein_form_tag_wrapper(form.color_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
221
216
|
end
|
222
217
|
|
223
|
-
def casein_search_field
|
218
|
+
def casein_search_field(form, obj, attribute, options = {})
|
224
219
|
casein_form_tag_wrapper(form.search_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
225
220
|
end
|
226
221
|
|
227
|
-
def casein_telephone_field
|
222
|
+
def casein_telephone_field(form, obj, attribute, options = {})
|
228
223
|
casein_form_tag_wrapper(form.telephone_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
229
224
|
end
|
230
225
|
|
231
|
-
def casein_url_field
|
226
|
+
def casein_url_field(form, obj, attribute, options = {})
|
232
227
|
casein_form_tag_wrapper(form.url_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
233
228
|
end
|
234
229
|
|
235
|
-
def casein_email_field
|
230
|
+
def casein_email_field(form, obj, attribute, options = {})
|
236
231
|
casein_form_tag_wrapper(form.email_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
237
232
|
end
|
238
233
|
|
239
|
-
def casein_date_field
|
234
|
+
def casein_date_field(form, obj, attribute, options = {})
|
240
235
|
casein_form_tag_wrapper(form.date_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
241
236
|
end
|
242
237
|
|
243
|
-
def casein_datetime_field
|
238
|
+
def casein_datetime_field(form, obj, attribute, options = {})
|
244
239
|
casein_form_tag_wrapper(form.datetime_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
245
240
|
end
|
246
241
|
|
247
|
-
def casein_datetime_local_field
|
242
|
+
def casein_datetime_local_field(form, obj, attribute, options = {})
|
248
243
|
casein_form_tag_wrapper(form.datetime_local_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
249
244
|
end
|
250
245
|
|
251
|
-
def casein_month_field
|
246
|
+
def casein_month_field(form, obj, attribute, options = {})
|
252
247
|
casein_form_tag_wrapper(form.month_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
253
248
|
end
|
254
249
|
|
255
|
-
def casein_week_field
|
250
|
+
def casein_week_field(form, obj, attribute, options = {})
|
256
251
|
casein_form_tag_wrapper(form.week_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
257
252
|
end
|
258
253
|
|
259
|
-
def casein_time_field
|
254
|
+
def casein_time_field(form, obj, attribute, options = {})
|
260
255
|
casein_form_tag_wrapper(form.time_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
261
256
|
end
|
262
257
|
|
263
|
-
def casein_number_field
|
258
|
+
def casein_number_field(form, obj, attribute, options = {})
|
264
259
|
casein_form_tag_wrapper(form.number_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
265
260
|
end
|
266
261
|
|
267
|
-
def casein_range_field
|
262
|
+
def casein_range_field(form, obj, attribute, options = {})
|
268
263
|
casein_form_tag_wrapper(form.range_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
269
264
|
end
|
270
265
|
|
271
|
-
def casein_custom_field
|
266
|
+
def casein_custom_field(form, obj, attribute, custom_contents, options = {})
|
272
267
|
casein_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
|
273
268
|
end
|
274
269
|
|
275
270
|
protected
|
276
271
|
|
277
|
-
def strip_casein_options
|
278
|
-
options.reject { |key,
|
272
|
+
def strip_casein_options(options)
|
273
|
+
options.reject { |key, _value| key.to_s.include? 'casein_' }
|
279
274
|
end
|
280
275
|
|
281
|
-
def merged_class_hash
|
282
|
-
if options.key? :class
|
283
|
-
new_class += " #{options[:class]}"
|
284
|
-
end
|
276
|
+
def merged_class_hash(options, new_class)
|
277
|
+
new_class += " #{options[:class]}" if options.key? :class
|
285
278
|
|
286
279
|
{ class: new_class }
|
287
280
|
end
|
288
281
|
|
289
|
-
def options_hash_with_merged_classes
|
290
|
-
if options.key? :class
|
291
|
-
new_class += " #{options[:class]}"
|
292
|
-
end
|
282
|
+
def options_hash_with_merged_classes(options, new_class)
|
283
|
+
new_class += " #{options[:class]}" if options.key? :class
|
293
284
|
options[:class] = new_class
|
294
285
|
options
|
295
286
|
end
|
296
287
|
|
297
|
-
def casein_form_tag_wrapper
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
288
|
+
def casein_form_tag_wrapper(form_tag, form, obj, attribute, options = {})
|
289
|
+
human_attribute_name = if options.key? :casein_label
|
290
|
+
options[:casein_label]
|
291
|
+
else
|
292
|
+
attribute.to_s.humanize.titleize
|
293
|
+
end
|
303
294
|
|
304
|
-
sublabel =
|
295
|
+
sublabel = ''
|
305
296
|
|
306
297
|
if options.key? :casein_sublabel
|
307
298
|
sublabel = " <small>#{options[:casein_sublabel]}</small>".html_safe
|
308
299
|
end
|
309
300
|
|
310
|
-
|
301
|
+
html = ''
|
311
302
|
|
312
303
|
if obj && obj.errors[attribute].any?
|
313
304
|
html += "<div class='form-group has-error'>"
|
314
|
-
|
315
|
-
|
305
|
+
html += form.label(attribute, "#{human_attribute_name} #{obj.errors[attribute].first}".html_safe, class: 'control-label')
|
306
|
+
else
|
316
307
|
html += "<div class='form-group'>"
|
317
|
-
|
318
|
-
|
308
|
+
html += form.label(attribute, "#{human_attribute_name}#{sublabel}".html_safe, class: 'control-label')
|
309
|
+
end
|
319
310
|
|
320
|
-
|
311
|
+
html += "<div class='well'>#{form_tag}</div></div>"
|
321
312
|
end
|
322
313
|
end
|
323
314
|
end
|