active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
@@ -1,5 +1,5 @@
1
1
  class ActiveScaffold::Bridges::SemanticAttributes < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "semantic_attributes/column.rb")
3
+ require File.join(File.dirname(__FILE__), 'semantic_attributes/column.rb')
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ class ActiveScaffold::Bridges::SemanticAttributes
6
6
 
7
7
  def initialize_with_semantic_attributes(name, active_record_class)
8
8
  initialize_without_semantic_attributes(name, active_record_class)
9
- self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil?
9
+ self.required = !active_record_class.semantic_attributes[self.name].predicates.find { |p| p.allow_empty? == false }.nil?
10
10
  active_record_class.semantic_attributes[self.name].predicates.find do |p|
11
11
  sem_type = p.class.to_s.split('::')[1].underscore.to_sym
12
12
  next if [:required, :association].include?(sem_type)
@@ -12,54 +12,63 @@ module ActiveScaffold
12
12
  tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
13
13
  tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
14
14
  tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search)
15
- tags.join("&nbsp;").html_safe
15
+ tags.join('&nbsp;').html_safe
16
16
  end
17
-
17
+
18
18
  def active_scaffold_search_date_bridge_comparator_options(column)
19
- select_options = ActiveScaffold::Finder::DateComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
20
- select_options + ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
19
+ select_options = ActiveScaffold::Finder::DATE_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] }
20
+ select_options + ActiveScaffold::Finder::NUMERIC_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] }
21
21
  end
22
-
22
+
23
23
  def active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
24
- select_tag("#{options[:name]}[opt]", options_for_select(active_scaffold_search_date_bridge_comparator_options(column),current_search['opt']), :id => "#{options[:id]}_opt", :class => "as_search_range_option as_search_date_time_option")
24
+ select_tag("#{options[:name]}[opt]", options_for_select(active_scaffold_search_date_bridge_comparator_options(column), current_search['opt']), :id => "#{options[:id]}_opt", :class => 'as_search_range_option as_search_date_time_option')
25
25
  end
26
-
26
+
27
27
  def active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
28
- numeric_controls = "" <<
29
- active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') <<
30
- content_tag(:span, (" - " + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe,
31
- :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => current_search['opt'] == 'BETWEEN' ? nil : "display: none")
32
- content_tag("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :class => "search-date-numeric", :style => ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? nil : "display: none")
28
+ numeric_controls =
29
+ '' <<
30
+ active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') <<
31
+ content_tag(:span, (' - ' + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe,
32
+ :id => "#{options[:id]}_between", :class => 'as_search_range_between',
33
+ :style => current_search['opt'] == 'BETWEEN' ? nil : 'display: none')
34
+ content_tag('span', numeric_controls.html_safe,
35
+ :id => "#{options[:id]}_numeric", :class => 'search-date-numeric',
36
+ :style => ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(current_search['opt']) ? nil : 'display: none')
33
37
  end
34
-
38
+
35
39
  def active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
36
- active_scaffold_date_bridge_trend_tag(column, options,
37
- {:number_value => current_search['number'],
38
- :unit_value => current_search["unit"],
39
- :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE')})
40
+ active_scaffold_date_bridge_trend_tag(column, options,
41
+ :number_value => current_search['number'],
42
+ :unit_value => current_search['unit'],
43
+ :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE'))
40
44
  end
41
45
 
42
46
  def active_scaffold_date_bridge_trend_tag(column, options, trend_options)
43
- trend_controls = text_field_tag("#{options[:name]}[number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " <<
44
- select_tag("#{options[:name]}[unit]",
45
- options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]),
46
- :class => 'text-input')
47
- content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :class => "search-date-trend", :style => trend_options[:show] ? nil : "display: none")
47
+ trend_controls =
48
+ text_field_tag("#{options[:name]}[number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << ' ' <<
49
+ select_tag("#{options[:name]}[unit]",
50
+ options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]),
51
+ :class => 'text-input')
52
+ content_tag('span', trend_controls.html_safe,
53
+ :id => "#{options[:id]}_trend", :class => 'search-date-trend',
54
+ :style => trend_options[:show] ? nil : 'display: none')
48
55
  end
49
56
 
50
57
  def active_scaffold_search_date_bridge_trend_units(column)
51
- options = ActiveScaffold::Finder::DateUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]}
52
- options = ActiveScaffold::Finder::TimeUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]} + options if column_datetime?(column)
53
- options
58
+ options = ActiveScaffold::Finder::DATE_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] }
59
+ options = ActiveScaffold::Finder::TIME_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] } + options if column_datetime?(column)
60
+ options
54
61
  end
55
-
62
+
56
63
  def active_scaffold_search_date_bridge_range_tag(column, options, current_search)
57
- range_controls = select_tag("#{options[:name]}[range]",
58
- options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]),
59
- :class => 'text-input', :id => nil)
60
- content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :class => "search-date-range", :style => (current_search['opt'] == 'RANGE') ? nil : "display: none")
64
+ range_controls = select_tag("#{options[:name]}[range]",
65
+ options_for_select(ActiveScaffold::Finder::DATE_RANGES.collect { |range| [as_(range.downcase.to_sym), range] }, current_search['range']),
66
+ :class => 'text-input', :id => nil)
67
+ content_tag('span', range_controls.html_safe,
68
+ :id => "#{options[:id]}_range", :class => 'search-date-range',
69
+ :style => (current_search['opt'] == 'RANGE') ? nil : 'display: none')
61
70
  end
62
-
71
+
63
72
  def column_datetime?(column)
64
73
  (!column.column.nil? && [:datetime, :time].include?(column.column.type))
65
74
  end
@@ -100,24 +109,24 @@ module ActiveScaffold
100
109
  end
101
110
  end
102
111
  end
103
-
112
+
104
113
  module Finder
105
114
  module ClassMethods
106
115
  def condition_for_date_bridge_type(column, value, like_pattern)
107
- operator = ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) && value[:opt] != 'BETWEEN' ? value[:opt] : nil
116
+ operator = ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(value[:opt]) && value[:opt] != 'BETWEEN' ? value[:opt] : nil
108
117
  from_value, to_value = date_bridge_from_to(column, value)
109
-
118
+
110
119
  if column.search_sql.is_a? Proc
111
120
  column.search_sql.call(from_value, to_value, operator)
112
121
  else
113
- unless operator.nil?
114
- ["%{search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil?
122
+ if operator.nil?
123
+ ['%{search_sql} BETWEEN ? AND ?', from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? || to_value.nil?
115
124
  else
116
- ["%{search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? || to_value.nil?
125
+ ["%{search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil?
117
126
  end
118
127
  end
119
128
  end
120
-
129
+
121
130
  def date_bridge_from_to(column, value)
122
131
  conversion = datetime_conversion_for_condition(column)
123
132
  case value[:opt]
@@ -126,17 +135,17 @@ module ActiveScaffold
126
135
  when 'PAST', 'FUTURE'
127
136
  date_bridge_from_to_for_trend(column, value).collect(&conversion)
128
137
  else
129
- ['from', 'to'].collect { |field| condition_value_for_datetime(column, value[field], conversion)}
138
+ %w(from to).collect { |field| condition_value_for_datetime(column, value[field], conversion) }
130
139
  end
131
140
  end
132
141
 
133
142
  def date_bridge_now
134
143
  Time.zone.now
135
144
  end
136
-
145
+
137
146
  def date_bridge_from_to_for_trend(column, value)
138
147
  case value['opt']
139
- when "PAST"
148
+ when 'PAST'
140
149
  trend_number = [value['number'].to_i, 1].max
141
150
  now = date_bridge_now
142
151
  if date_bridge_column_date?(column)
@@ -147,7 +156,7 @@ module ActiveScaffold
147
156
  to = now
148
157
  end
149
158
  return from, to
150
- when "FUTURE"
159
+ when 'FUTURE'
151
160
  trend_number = [value['number'].to_i, 1].max
152
161
  now = date_bridge_now
153
162
  if date_bridge_column_date?(column)
@@ -160,7 +169,7 @@ module ActiveScaffold
160
169
  return from, to
161
170
  end
162
171
  end
163
-
172
+
164
173
  def date_bridge_from_to_for_range(column, value)
165
174
  case value[:range]
166
175
  when 'TODAY'
@@ -171,7 +180,7 @@ module ActiveScaffold
171
180
  return date_bridge_now.in(1.day).beginning_of_day, date_bridge_now.in(1.day).end_of_day
172
181
  else
173
182
  range_type, range = value[:range].downcase.split('_')
174
- raise ArgumentError unless ['week', 'month', 'year'].include?(range)
183
+ raise ArgumentError unless %w(week month year).include?(range)
175
184
  case range_type
176
185
  when 'this'
177
186
  return date_bridge_now.send("beginning_of_#{range}".to_sym), date_bridge_now.send("end_of_#{range}")
@@ -180,7 +189,7 @@ module ActiveScaffold
180
189
  when 'next'
181
190
  return date_bridge_now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), date_bridge_now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym)
182
191
  else
183
- return nil, nil
192
+ return nil, nil
184
193
  end
185
194
  end
186
195
  end
@@ -199,10 +208,7 @@ module ActiveScaffold
199
208
  end
200
209
  end
201
210
 
202
- ActiveScaffold::Finder.const_set('DateComparators', ["PAST", "FUTURE", "RANGE"])
203
- ActiveScaffold::Finder.const_set('DateUnits', ["DAYS", "WEEKS", "MONTHS", "YEARS"])
204
- ActiveScaffold::Finder.const_set('TimeUnits', ["SECONDS", "MINUTES", "HOURS"])
205
- ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW",
206
- "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK",
207
- "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH",
208
- "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"])
211
+ ActiveScaffold::Finder.const_set('DATE_COMPARATORS', %w(PAST FUTURE RANGE))
212
+ ActiveScaffold::Finder.const_set('DATE_UNITS', %w(DAYS WEEKS MONTHS YEARS))
213
+ ActiveScaffold::Finder.const_set('TIME_UNITS', %w(SECONDS MINUTES HOURS))
214
+ ActiveScaffold::Finder.const_set('DATE_RANGES', %w(TODAY YESTERDAY TOMORROW THIS_WEEK PREV_WEEK NEXT_WEEK THIS_MONTH PREV_MONTH NEXT_MONTH THIS_YEAR PREV_YEAR NEXT_YEAR))
@@ -5,9 +5,9 @@ class ActiveScaffold::Bridges::TinyMce < ActiveScaffold::DataStructures::Bridge
5
5
  end
6
6
 
7
7
  def self.install?
8
- Object.const_defined? "TinyMCE"
8
+ Object.const_defined? 'TinyMCE'
9
9
  end
10
-
10
+
11
11
  def self.javascripts
12
12
  case ActiveScaffold.js_framework
13
13
  when :jquery
@@ -14,10 +14,10 @@ class ActiveScaffold::Bridges::TinyMce
14
14
 
15
15
  def active_scaffold_input_text_editor(column, options)
16
16
  options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
17
-
18
- settings = { :theme => 'simple' }.merge(column.options[:tinymce] || {})
17
+
18
+ settings = {:theme => 'simple'}.merge(column.options[:tinymce] || {})
19
19
  settings = settings.to_json
20
- settings = "tinyMCE.settings = #{settings};"
20
+ settings = "tinyMCE.settings = #{settings};"
21
21
 
22
22
  html = []
23
23
  html << send(override_input(:textarea), column, options)
@@ -16,7 +16,7 @@ module ActiveScaffold::Config
16
16
  class << subclass
17
17
  # the crud type of the action. possible values are :create, :read, :update, :delete, and nil.
18
18
  # this is not a setting for the developer. it's self-description for the actions.
19
- def crud_type; @crud_type; end
19
+ attr_reader :crud_type
20
20
 
21
21
  protected
22
22
 
@@ -28,13 +28,15 @@ module ActiveScaffold::Config
28
28
  end
29
29
 
30
30
  # delegate
31
- def crud_type; self.class.crud_type end
31
+ def crud_type
32
+ self.class.crud_type
33
+ end
32
34
 
33
35
  def label(model = nil)
34
36
  model ||= @core.label(:count => 1)
35
37
  @label.nil? ? model : as_(@label, :model => model)
36
38
  end
37
-
39
+
38
40
  # the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class.
39
41
  attr_accessor :user
40
42
 
@@ -70,17 +72,14 @@ module ActiveScaffold::Config
70
72
  end
71
73
  end
72
74
  end
73
-
75
+
74
76
  def formats
75
77
  @formats ||= []
76
78
  end
77
-
78
- def formats=(val)
79
- @formats=val
80
- end
81
-
79
+ attr_writer :formats
80
+
82
81
  private
83
-
82
+
84
83
  def columns=(val)
85
84
  @columns.set_values(*val) if @columns
86
85
  @columns ||= ActiveScaffold::DataStructures::ActionColumns.new(*val).tap do |columns|
@@ -94,9 +94,9 @@ module ActiveScaffold::Config
94
94
  # provides read/write access to the local Columns DataStructure
95
95
  attr_reader :columns
96
96
  def columns=(val)
97
- @columns._inheritable = val.collect {|c| c.to_sym}
97
+ @columns._inheritable = val.collect(&:to_sym)
98
98
  # Add virtual columns
99
- @columns << val.collect {|c| c.to_sym unless @columns[c.to_sym]}.compact
99
+ @columns << val.collect { |c| c.to_sym unless @columns[c.to_sym] }.compact
100
100
  end
101
101
 
102
102
  # lets you override the global ActiveScaffold frontend for a specific controller
@@ -120,7 +120,7 @@ module ActiveScaffold::Config
120
120
  # lets you specify whether add a create link for each sti child for a specific controller
121
121
  attr_accessor :sti_create_links
122
122
  def add_sti_create_links?
123
- self.sti_create_links and not self.sti_children.nil?
123
+ sti_create_links && !sti_children.nil?
124
124
  end
125
125
 
126
126
  # action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold.
@@ -128,7 +128,7 @@ module ActiveScaffold::Config
128
128
 
129
129
  # a generally-applicable name for this ActiveScaffold ... will be used for generating page/section headers
130
130
  attr_writer :label
131
- def label(options={})
131
+ def label(options = {})
132
132
  as_(@label, options) || model.model_name.human(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize}))
133
133
  end
134
134
 
@@ -153,15 +153,15 @@ module ActiveScaffold::Config
153
153
  @actions = self.class.actions.clone
154
154
 
155
155
  # create a new default columns datastructure, since it doesn't make sense before now
156
- attribute_names = self.model.columns.collect{ |c| c.name.to_sym }.sort_by { |c| c.to_s }
157
- association_column_names = self.model.reflect_on_all_associations.collect{ |a| a.name.to_sym }.sort_by { |c| c.to_s }
158
- @columns = ActiveScaffold::DataStructures::Columns.new(self.model, attribute_names + association_column_names)
156
+ attribute_names = model.columns.collect { |c| c.name.to_sym }.sort_by(&:to_s)
157
+ association_column_names = model.reflect_on_all_associations.collect { |a| a.name.to_sym }.sort_by(&:to_s)
158
+ @columns = ActiveScaffold::DataStructures::Columns.new(model, attribute_names + association_column_names)
159
159
 
160
160
  # and then, let's remove some columns from the inheritable set.
161
- content_columns = Set.new(self.model.content_columns.map(&:name))
161
+ content_columns = Set.new(model.content_columns.map(&:name))
162
162
  @columns.exclude(*self.class.ignore_columns)
163
- @columns.exclude(*@columns.find_all { |c| c.column and content_columns.exclude?(c.column.name) }.collect {|c| c.name})
164
- @columns.exclude(*self.model.reflect_on_all_associations.collect{|a| :"#{a.name}_type" if a.options[:polymorphic]}.compact)
163
+ @columns.exclude(*@columns.find_all { |c| c.column && content_columns.exclude?(c.column.name) }.collect(&:name))
164
+ @columns.exclude(*model.reflect_on_all_associations.collect { |a| :"#{a.name}_type" if a.options[:polymorphic] }.compact)
165
165
 
166
166
  # inherit the global frontend
167
167
  @frontend = self.class.frontend
@@ -181,21 +181,21 @@ module ActiveScaffold::Config
181
181
  # To be called after your finished configuration
182
182
  def _load_action_columns
183
183
  # then, register the column objects
184
- self.actions.each do |action_name|
185
- action = self.send(action_name)
186
- action.columns.set_columns(self.columns) if action.respond_to?(:columns)
184
+ actions.each do |action_name|
185
+ action = send(action_name)
186
+ action.columns.set_columns(columns) if action.respond_to?(:columns)
187
187
  end
188
188
  end
189
189
 
190
190
  # To be called after your finished configuration
191
191
  def _configure_sti
192
- column = self.model.inheritance_column
192
+ column = model.inheritance_column
193
193
  if sti_create_links
194
- self.columns[column].form_ui ||= :hidden
194
+ columns[column].form_ui ||= :hidden
195
195
  else
196
- self.columns[column].form_ui ||= :select
197
- self.columns[column].options ||= {}
198
- self.columns[column].options[:options] = self.sti_children.collect do |model_name|
196
+ columns[column].form_ui ||= :select
197
+ columns[column].options ||= {}
198
+ columns[column].options[:options] = sti_children.collect do |model_name|
199
199
  [model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize]
200
200
  end
201
201
  end
@@ -221,17 +221,13 @@ module ActiveScaffold::Config
221
221
 
222
222
  def self.method_missing(name, *args)
223
223
  klass = "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize rescue nil
224
- if @@actions.include? name.to_s.underscore and klass
225
- return eval("ActiveScaffold::Config::#{name.to_s.camelcase}")
226
- end
224
+ return klass if @@actions.include?(name.to_s.underscore) && klass
227
225
  super
228
226
  end
229
227
  # some utility methods
230
228
  # --------------------
231
229
 
232
- def model_id
233
- @model_id
234
- end
230
+ attr_reader :model_id
235
231
 
236
232
  def model
237
233
  @model ||= @model_id.to_s.camelize.constantize
@@ -239,7 +235,7 @@ module ActiveScaffold::Config
239
235
 
240
236
  # warning - this won't work as a per-request dynamic attribute in rails 2.0. You'll need to interact with Controller#generic_view_paths
241
237
  def inherited_view_paths
242
- @inherited_view_paths||=[]
238
+ @inherited_view_paths ||= []
243
239
  end
244
240
 
245
241
  # must be a class method so the layout doesn't depend on a controller that uses active_scaffold
@@ -251,14 +247,13 @@ module ActiveScaffold::Config
251
247
  # must be a class method so the layout doesn't depend on a controller that uses active_scaffold
252
248
  # note that this is unaffected by per-controller frontend configuration.
253
249
  def self.javascripts(frontend = self.frontend)
254
- javascript_dir = File.join(Rails.public_path, "javascripts", asset_path('', frontend))
255
- Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) or (!self.dhtml_history? and e.match('dhtml_history')) }
250
+ javascript_dir = File.join(Rails.public_path, 'javascripts', asset_path('', frontend))
251
+ Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) || (!self.dhtml_history? && e.match('dhtml_history')) }
256
252
  end
257
253
 
258
254
  def self.available_frontends
259
- frontends_dir = File.join(Rails.root, "vendor", "plugins", ActiveScaffold::Config::Core.plugin_directory, "frontends")
255
+ frontends_dir = File.join(Rails.root, 'vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends')
260
256
  Dir.entries(frontends_dir).reject { |e| e.match(/^\./) } # Get rid of files that start with .
261
257
  end
262
258
  end
263
259
  end
264
-
@@ -27,6 +27,5 @@ module ActiveScaffold::Config
27
27
 
28
28
  # whether the form stays open after a create or not
29
29
  attr_accessor :action_after_create
30
-
31
30
  end
32
31
  end
@@ -8,7 +8,6 @@ module ActiveScaffold::Config
8
8
  @human_conditions = self.class.human_conditions
9
9
  end
10
10
 
11
-
12
11
  # global level configuration
13
12
  # --------------------------
14
13
  # the ActionLink for this action
@@ -28,7 +27,7 @@ module ActiveScaffold::Config
28
27
  # instead of just filtered you may show the user a humanized search condition statment
29
28
  cattr_accessor :human_conditions
30
29
  @@human_conditions = false
31
-
30
+
32
31
  # instance-level configuration
33
32
  # ----------------------------
34
33
 
@@ -37,7 +36,7 @@ module ActiveScaffold::Config
37
36
  # we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable?
38
37
  unless @columns
39
38
  self.columns = @core.columns._inheritable
40
- self.columns.exclude @core.columns.active_record_class.locking_column.to_sym
39
+ columns.exclude @core.columns.active_record_class.locking_column.to_sym
41
40
  end
42
41
  @columns
43
42
  end
@@ -51,26 +50,25 @@ module ActiveScaffold::Config
51
50
  # * false: LIKE ?
52
51
  # Default is :full
53
52
  attr_accessor :text_search
54
-
53
+
55
54
  # the ActionLink for this action
56
55
  attr_accessor :link
57
-
56
+
58
57
  # rarely searched columns may be placed in a hidden subgroup
59
58
  def optional_columns=(optionals)
60
59
  @optional_columns = Array(optionals)
61
60
  end
62
-
61
+
63
62
  def optional_columns
64
63
  @optional_columns ||= []
65
64
  end
66
-
65
+
67
66
  # default search params
68
- # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}}
67
+ # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}}
69
68
  attr_accessor :default_params
70
-
69
+
71
70
  # human conditions
72
71
  # instead of just filtered you may show the user a humanized search condition statment
73
72
  attr_accessor :human_conditions
74
-
75
73
  end
76
74
  end