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
@@ -7,21 +7,22 @@ module ActiveScaffold
7
7
 
8
8
  mattr_accessor :bridges
9
9
  mattr_accessor :bridges_run
10
+ mattr_accessor :bridges_prepared
10
11
  self.bridges = {}
11
12
 
12
13
  def self.register(file)
13
14
  match = file.match(/(active_scaffold\/bridges\/(.*))\.rb\Z/)
14
- self.bridges[match[2].to_sym] = match[1] if match
15
+ bridges[match[2].to_sym] = match[1] if match
15
16
  end
16
17
 
17
18
  def self.load(bridge_name)
18
- bridge = self.bridges[bridge_name.to_sym]
19
+ bridge = bridges[bridge_name.to_sym]
19
20
  if bridge.is_a? String
20
21
  if ActiveScaffold.exclude_bridges.exclude? bridge_name.to_sym
21
22
  bridge = bridge.camelize.constantize
22
- self.bridges[bridge_name.to_sym] = bridge
23
+ bridges[bridge_name.to_sym] = bridge
23
24
  else
24
- self.bridges.delete bridge_name
25
+ bridges.delete bridge_name
25
26
  bridge = nil
26
27
  end
27
28
  end
@@ -30,32 +31,41 @@ module ActiveScaffold
30
31
  class << self
31
32
  alias_method :[], :load
32
33
  end
33
-
34
+
34
35
  def self.run_all
35
- return false if self.bridges_run
36
- self.bridges.keys.each do |bridge_name|
36
+ return false if bridges_run
37
+ bridges.keys.each do |bridge_name|
37
38
  bridge = self[bridge_name]
38
39
  bridge.run if bridge
39
40
  end
40
41
  self.bridges_run = true
41
42
  end
42
43
 
44
+ def self.prepare_all
45
+ return false if bridges_prepared
46
+ bridges.keys.each do |bridge_name|
47
+ bridge = self[bridge_name]
48
+ bridge.prepare if bridge.install?
49
+ end
50
+ self.bridges_prepared = true
51
+ end
52
+
43
53
  def self.all_stylesheets
44
- self.bridges.keys.collect do |bridge_name|
54
+ bridges.keys.collect do |bridge_name|
45
55
  bridge = self[bridge_name]
46
- bridge.stylesheets if bridge and bridge.install?
56
+ bridge.stylesheets if bridge && bridge.install?
47
57
  end.compact.flatten
48
58
  end
49
59
 
50
60
  def self.all_javascripts
51
- self.bridges.keys.collect do |bridge_name|
61
+ bridges.keys.collect do |bridge_name|
52
62
  bridge = self[bridge_name]
53
- bridge.javascripts if bridge and bridge.install?
63
+ bridge.javascripts if bridge && bridge.install?
54
64
  end.compact.flatten
55
65
  end
56
66
  end
57
67
  end
58
68
 
59
- Dir[File.join(File.dirname(__FILE__), "bridges/*.rb")].each do |bridge|
69
+ Dir[File.join(File.dirname(__FILE__), 'bridges/*.rb')].each do |bridge|
60
70
  ActiveScaffold::Bridges.register bridge unless bridge == __FILE__
61
71
  end
@@ -1,5 +1,5 @@
1
1
  class ActiveScaffold::Bridges::Ancestry < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "ancestry/ancestry_bridge.rb")
3
+ require File.join(File.dirname(__FILE__), 'ancestry/ancestry_bridge.rb')
4
4
  end
5
5
  end
@@ -2,10 +2,10 @@ ActiveScaffold::Config::Core.class_eval do
2
2
  def initialize_with_ancestry(model_id)
3
3
  initialize_without_ancestry(model_id)
4
4
 
5
- return unless self.model.respond_to? :ancestry_column
6
-
7
- self.columns << :parent_id
8
- self.columns[:parent_id].form_ui = :ancestry
5
+ return unless model.respond_to? :ancestry_column
6
+
7
+ columns << :parent_id
8
+ columns[:parent_id].form_ui = :ancestry
9
9
  update.columns.exclude :ancestry
10
10
  create.columns.exclude :ancestry, :parent_id
11
11
  list.columns.exclude :ancestry, :parent_id
@@ -19,8 +19,8 @@ module ActiveScaffold::Bridges
19
19
  module FormColumnHelpers
20
20
  def active_scaffold_input_ancestry(column, options)
21
21
  record = options[:object]
22
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in html_options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
23
- record ||= @record # TODO Remove when relying on @record is removed
22
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in html_options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
23
+ record ||= @record # TODO: Remove when relying on @record is removed
24
24
 
25
25
  select_options = []
26
26
  select_control_options = {:selected => record.parent_id}
@@ -1,6 +1,6 @@
1
1
  class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "bitfields/bitfields_bridge")
3
+ require File.join(File.dirname(__FILE__), 'bitfields/bitfields_bridge')
4
4
  ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Bitfields::BitfieldsBridge
5
5
  end
6
6
  end
@@ -4,31 +4,30 @@ module ActiveScaffold
4
4
  module BitfieldsBridge
5
5
  def initialize_with_bitfields(model_id)
6
6
  initialize_without_bitfields(model_id)
7
- return unless self.model.respond_to?(:bitfields) and self.model.bitfields.present?
7
+ return unless model.respond_to?(:bitfields) && model.bitfields.present?
8
8
 
9
- self.model.bitfields.each do |column_name, options|
10
- self.columns << options.keys
9
+ model.bitfields.each do |_, options|
10
+ columns << options.keys
11
11
  options.each do |column, value|
12
- self.columns[column].form_ui = :checkbox
13
- self.columns[column].weight = 1000 + value.to_s(2).size
12
+ columns[column].form_ui = :checkbox
13
+ columns[column].weight = 1000 + value.to_s(2).size
14
14
  end
15
15
  end
16
16
  end
17
-
17
+
18
18
  def _load_action_columns_with_bitfields
19
- self.model.bitfields.each do |column_name, options|
19
+ model.bitfields.each do |column_name, options|
20
20
  columns = options.keys.sort_by { |column| self.columns[column].weight }
21
21
  [:create, :update, :show, :subform].each do |action|
22
- if self.actions.include? action
23
- self.send(action).columns.exclude column_name
24
- self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns }
22
+ if actions.include? action
23
+ send(action).columns.exclude column_name
24
+ send(action).columns.add_subgroup(column_name) { |group| group.add *columns }
25
25
  end
26
26
  end
27
- end if self.model.respond_to?(:bitfields) and self.model.bitfields.present?
28
-
27
+ end if model.respond_to?(:bitfields) && model.bitfields.present?
28
+
29
29
  _load_action_columns_without_bitfields
30
30
  end
31
-
32
31
 
33
32
  def self.included(base)
34
33
  base.alias_method_chain :initialize, :bitfields
@@ -2,14 +2,14 @@ class ActiveScaffold::Bridges::CalendarDateSelect < ActiveScaffold::DataStructur
2
2
  def self.install
3
3
  # check to see if the old bridge was installed. If so, warn them
4
4
  # we can detect this by checking to see if the bridge was installed before calling this code
5
-
5
+
6
6
  if ActiveScaffold::Config::Core.method_defined?(:initialize_with_calendar_date_select)
7
- raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts"
7
+ raise "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts"
8
8
  end
9
-
10
- require File.join(File.dirname(__FILE__), "calendar_date_select/as_cds_bridge.rb")
9
+
10
+ require File.join(File.dirname(__FILE__), 'calendar_date_select/as_cds_bridge.rb')
11
11
  end
12
-
12
+
13
13
  def self.install?
14
14
  super && ActiveScaffold.js_framework == :prototype
15
15
  end
@@ -1,25 +1,20 @@
1
1
  module ActiveScaffold::Config
2
2
  class Core < Base
3
-
4
3
  def initialize_with_calendar_date_select(model_id)
5
4
  initialize_without_calendar_date_select(model_id)
6
-
7
- calendar_date_select_fields = self.model.columns.collect{|c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact
5
+
6
+ calendar_date_select_fields = model.columns.collect { |c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact
8
7
  # check to see if file column was used on the model
9
8
  return if calendar_date_select_fields.empty?
10
-
9
+
11
10
  # automatically set the forum_ui to a file column
12
- calendar_date_select_fields.each{|field|
13
- self.columns[field].form_ui = :calendar_date_select
14
- }
11
+ calendar_date_select_fields.each { |field| columns[field].form_ui = :calendar_date_select }
15
12
  end
16
-
13
+
17
14
  alias_method_chain :initialize, :calendar_date_select
18
-
19
15
  end
20
16
  end
21
17
 
22
-
23
18
  module ActiveScaffold
24
19
  module Bridges
25
20
  class CalendarDateSelect
@@ -27,10 +22,10 @@ module ActiveScaffold
27
22
  module FormColumnHelpers
28
23
  def active_scaffold_input_calendar_date_select(column, options)
29
24
  options[:class] = "#{options[:class]} text-input".strip
30
- calendar_date_select("record", column.name, options.merge(column.options))
31
- end
25
+ calendar_date_select('record', column.name, options.merge(column.options))
26
+ end
32
27
  end
33
-
28
+
34
29
  module SearchColumnHelpers
35
30
  def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name)
36
31
  if current_search.is_a? Hash
@@ -38,13 +33,15 @@ module ActiveScaffold
38
33
  else
39
34
  value = current_search
40
35
  end
41
- calendar_date_select("record", column.name,
42
- {:name => "#{options[:name]}[#{name}]",
43
- :value => (value ? l(value) : nil),
44
- :class => 'text-input',
45
- :id => "#{options[:id]}_#{name}",
46
- :time => column_datetime?(column) ? true : false,
47
- :style => (options[:show].nil? || options[:show]) ? nil : "display: none"})
36
+ calendar_date_select(
37
+ 'record', column.name,
38
+ :name => "#{options[:name]}[#{name}]",
39
+ :value => (value ? l(value) : nil),
40
+ :class => 'text-input',
41
+ :id => "#{options[:id]}_#{name}",
42
+ :time => column_datetime?(column) ? true : false,
43
+ :style => (options[:show].nil? || options[:show]) ? nil : 'display: none'
44
+ )
48
45
  end
49
46
  end
50
47
  end
@@ -1,6 +1,6 @@
1
1
  class ActiveScaffold::Bridges::Cancan < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "cancan", "cancan_bridge.rb")
3
+ require File.join(File.dirname(__FILE__), 'cancan', 'cancan_bridge.rb')
4
4
 
5
5
  ActiveScaffold::Core::ClassMethods.send :include, ActiveScaffold::Bridges::Cancan::ClassMethods
6
6
  ActiveScaffold::Actions::Core.send :include, ActiveScaffold::Bridges::Cancan::Actions::Core
@@ -1,6 +1,6 @@
1
1
  # Allow users to easily define aliases for AS actions.
2
2
  # Ability#as_action_aliases should be called by the user in his ability class
3
- #
3
+ #
4
4
  # class Ability < CanCan::Ability
5
5
  # def initialize(user)
6
6
  # as_action_aliases
@@ -19,7 +19,6 @@ end
19
19
 
20
20
  module ActiveScaffold::Bridges
21
21
  class Cancan
22
-
23
22
  # controller level authorization
24
23
  # As already has callbacks to ensure authorization at controller method via "authorization_method"
25
24
  # but let's include this too, just in case, no sure how performance is affected tough :TODO benchmark
@@ -70,7 +69,7 @@ module ActiveScaffold::Bridges
70
69
  # because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the
71
70
  # current_ability_method on this ApplicationController.
72
71
  def assign_current_ability_to_models
73
- ::ActiveRecord::Base.current_ability_proc = proc {send(:current_ability)}
72
+ ::ActiveRecord::Base.current_ability_proc = proc { send(:current_ability) }
74
73
  end
75
74
  end
76
75
 
@@ -82,6 +81,7 @@ module ActiveScaffold::Bridges
82
81
  def current_ability_proc
83
82
  Thread.current[:current_ability_proc]
84
83
  end
84
+
85
85
  def current_ability_proc=(value)
86
86
  Thread.current[:current_ability_proc] = value
87
87
  end
@@ -93,11 +93,12 @@ module ActiveScaffold::Bridges
93
93
  end
94
94
 
95
95
  # Instance-level access to the current ability
96
- def current_ability; self.class.current_ability end
96
+ def current_ability
97
+ self.class.current_ability
98
+ end
97
99
  end
98
100
  end
99
101
 
100
-
101
102
  # plug into AS#authorized_for calls
102
103
  module ActiveRecord
103
104
  extend ActiveSupport::Concern
@@ -119,7 +120,7 @@ module ActiveScaffold::Bridges
119
120
  # to allow access cancan must allow both :crud_type and :action
120
121
  # if cancan says "no", it delegates to default AS behavior
121
122
  def authorized_for_with_cancan?(options = {})
122
- raise InvalidArgument if options[:crud_type].blank? and options[:action].blank?
123
+ raise InvalidArgument if options[:crud_type].blank? && options[:action].blank?
123
124
  if current_ability.present?
124
125
  crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
125
126
  action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
@@ -127,11 +128,9 @@ module ActiveScaffold::Bridges
127
128
  crud_type_result, action_result = false, false
128
129
  end
129
130
  default_result = authorized_for_without_cancan?(options)
130
- result = (crud_type_result && action_result) || default_result
131
- return result
131
+ (crud_type_result && action_result) || default_result
132
132
  end
133
133
  end
134
134
  end
135
-
136
135
  end
137
136
  end
@@ -1,9 +1,9 @@
1
1
  class ActiveScaffold::Bridges::Carrierwave < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "carrierwave/form_ui")
4
- require File.join(File.dirname(__FILE__), "carrierwave/list_ui")
5
- require File.join(File.dirname(__FILE__), "carrierwave/carrierwave_bridge_helpers")
6
- require File.join(File.dirname(__FILE__), "carrierwave/carrierwave_bridge")
3
+ require File.join(File.dirname(__FILE__), 'carrierwave/form_ui')
4
+ require File.join(File.dirname(__FILE__), 'carrierwave/list_ui')
5
+ require File.join(File.dirname(__FILE__), 'carrierwave/carrierwave_bridge_helpers')
6
+ require File.join(File.dirname(__FILE__), 'carrierwave/carrierwave_bridge')
7
7
  ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridge
8
8
  end
9
9
  def self.install?
@@ -4,12 +4,12 @@ module ActiveScaffold
4
4
  module CarrierwaveBridge
5
5
  def initialize_with_carrierwave(model_id)
6
6
  initialize_without_carrierwave(model_id)
7
- return unless self.model.respond_to?(:uploaders) && self.model.uploaders.present?
7
+ return unless model.respond_to?(:uploaders) && model.uploaders.present?
8
8
 
9
- self.update.multipart = true
10
- self.create.multipart = true
9
+ update.multipart = true
10
+ create.multipart = true
11
11
 
12
- self.model.uploaders.keys.each do |field|
12
+ model.uploaders.keys.each do |field|
13
13
  configure_carrierwave_field(field.to_sym)
14
14
  end
15
15
  end
@@ -19,11 +19,12 @@ module ActiveScaffold
19
19
  end
20
20
 
21
21
  private
22
+
22
23
  def configure_carrierwave_field(field)
23
- self.columns << field
24
- self.columns[field].form_ui ||= :carrierwave # :TODO thumbnail
25
- self.columns[field].params.add "#{field}_cache"
26
- self.columns[field].params.add "remove_#{field}"
24
+ columns << field
25
+ columns[field].form_ui ||= :carrierwave # :TODO thumbnail
26
+ columns[field].params.add "#{field}_cache"
27
+ columns[field].params.add "remove_#{field}"
27
28
  end
28
29
  end
29
30
  end
@@ -3,8 +3,8 @@ module ActiveScaffold
3
3
  module FormColumnHelpers
4
4
  def active_scaffold_input_carrierwave(column, options)
5
5
  record = options[:object]
6
- ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in html_options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
7
- record ||= @record # TODO Remove when relying on @record is removed
6
+ ActiveSupport::Deprecation.warn 'Relying on @record is deprecated, include :object in html_options with record.', caller if record.nil? # TODO: Remove when relying on @record is removed
7
+ record ||= @record # TODO: Remove when relying on @record is removed
8
8
  options = active_scaffold_input_text_options(options.merge(column.options))
9
9
 
10
10
  carrierwave = record.send("#{column.name}")
@@ -23,22 +23,23 @@ module ActiveScaffold
23
23
 
24
24
  case ActiveScaffold.js_framework
25
25
  when :jquery
26
- js_remove_file_code = "jQuery(this).prev('input#remove_#{options[:id]}').val('true'); jQuery(this).parent().hide().next().show(); return false;";
27
- js_dont_remove_file_code = "jQuery(this).parents('div.carrierwave_controls').find('input#remove_#{options[:id]}').val('false'); return false;";
26
+ js_remove_file_code = "jQuery(this).prev('input#remove_#{options[:id]}').val('true'); jQuery(this).parent().hide().next().show(); return false;"
27
+ js_dont_remove_file_code = "jQuery(this).parents('div.carrierwave_controls').find('input#remove_#{options[:id]}').val('false'); return false;"
28
28
  when :prototype
29
- js_remove_file_code = "$(this).previous('input#remove_#{options[:id]}').value='true'; $(this).up().hide().next().show(); return false;";
30
- js_dont_remove_file_code = "$(this).up('div.carrierwave_controls').down('input#remove_#{options[:id]}').value='false'; return false;";
29
+ js_remove_file_code = "$(this).previous('input#remove_#{options[:id]}').value='true'; $(this).up().hide().next().show(); return false;"
30
+ js_dont_remove_file_code = "$(this).up('div.carrierwave_controls').down('input#remove_#{options[:id]}').value='false'; return false;"
31
31
  end
32
32
 
33
33
  input = file_field(:record, column.name, options.merge(:onchange => js_dont_remove_file_code))
34
- content_tag( :div,
34
+ content_tag(
35
+ :div,
35
36
  content_tag(:div, (
36
- get_column_value(record, column) + " | " +
37
+ get_column_value(record, column) + ' | ' +
37
38
  hidden_field(:record, "#{column.name}_cache", cache_field_options) +
38
39
  hidden_field(:record, "remove_#{column.name}", remove_field_options) +
39
- content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code})
40
+ content_tag(:a, as_(:remove_file), :href => '#', :onclick => js_remove_file_code)
40
41
  ).html_safe
41
- ) + content_tag(:div, input, :style => "display: none"),
42
+ ) + content_tag(:div, input, :style => 'display: none'),
42
43
  :class => 'carrierwave_controls'
43
44
  )
44
45
  else
@@ -3,13 +3,14 @@ module ActiveScaffold
3
3
  module ListColumnHelpers
4
4
  def active_scaffold_column_carrierwave(record, column)
5
5
  carrierwave = record.send("#{column.name}")
6
- return nil unless !carrierwave.file.blank?
6
+ return nil if carrierwave.file.blank?
7
7
  thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style
8
- content = if carrierwave.versions.keys.include?(thumbnail_style)
9
- image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe
10
- else
11
- record.send(record.send(:_mounter, column.name).send(:serialization_column))
12
- end
8
+ content =
9
+ if carrierwave.versions.keys.include?(thumbnail_style)
10
+ image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe
11
+ else
12
+ record.send(record.send(:_mounter, column.name).send(:serialization_column))
13
+ end
13
14
  link_to(content, carrierwave.url, :target => '_blank')
14
15
  end
15
16
  end
@@ -1,6 +1,6 @@
1
1
  class ActiveScaffold::Bridges::Chosen < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), "chosen/helpers.rb")
3
+ require File.join(File.dirname(__FILE__), 'chosen/helpers.rb')
4
4
  end
5
5
  def self.install?
6
6
  super && [:jquery, :prototype].include?(ActiveScaffold.js_framework)