active_scaffold 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,362 @@
1
+ unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
2
+ raise "This version of ActiveScaffold requires Rails 3.1 or higher. Please use an earlier version."
3
+ end
4
+
5
+ begin
6
+ require 'render_component'
7
+ rescue LoadError
8
+ end
9
+
10
+ require 'active_scaffold/active_record_permissions'
11
+ require 'active_scaffold/paginator'
12
+ require 'active_scaffold/responds_to_parent'
13
+
14
+ require 'active_scaffold/version'
15
+ require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN
16
+
17
+ module ActiveScaffold
18
+ autoload :AttributeParams, 'active_scaffold/attribute_params'
19
+ autoload :Configurable, 'active_scaffold/configurable'
20
+ autoload :Constraints, 'active_scaffold/constraints'
21
+ autoload :Finder, 'active_scaffold/finder'
22
+ autoload :MarkedModel, 'active_scaffold/marked_model'
23
+ autoload :Bridges, 'active_scaffold/bridges'
24
+
25
+ mattr_accessor :stylesheets
26
+ self.stylesheets = []
27
+ mattr_accessor :javascripts
28
+ self.javascripts = []
29
+
30
+ def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
31
+ Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
32
+ basename = File.basename(file, ".rb")
33
+ mod.module_eval {
34
+ autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
35
+ }
36
+ }
37
+ end
38
+
39
+ module Actions
40
+ ActiveScaffold.autoload_subdir('actions', self)
41
+ end
42
+
43
+ module Config
44
+ ActiveScaffold.autoload_subdir('config', self)
45
+ end
46
+
47
+ module DataStructures
48
+ ActiveScaffold.autoload_subdir('data_structures', self)
49
+ end
50
+
51
+ module Helpers
52
+ ActiveScaffold.autoload_subdir('helpers', self)
53
+ end
54
+
55
+ class ControllerNotFound < RuntimeError; end
56
+ class DependencyFailure < RuntimeError; end
57
+ class MalformedConstraint < RuntimeError; end
58
+ class RecordNotAllowed < SecurityError; end
59
+ class ActionNotAllowed < SecurityError; end
60
+ class ReverseAssociationRequired < RuntimeError; end
61
+
62
+ def self.included(base)
63
+ base.extend(ClassMethods)
64
+ base.module_eval do
65
+ # TODO: these should be in actions/core
66
+ before_filter :handle_user_settings
67
+ before_filter :check_input_device
68
+ end
69
+
70
+ base.helper_method :touch_device?
71
+ base.helper_method :hover_via_click?
72
+ end
73
+
74
+ def self.set_defaults(&block)
75
+ ActiveScaffold::Config::Core.configure &block
76
+ end
77
+
78
+ def active_scaffold_config
79
+ self.class.active_scaffold_config
80
+ end
81
+
82
+ def active_scaffold_config_for(klass)
83
+ self.class.active_scaffold_config_for(klass)
84
+ end
85
+
86
+ def active_scaffold_session_storage(id = (params[:eid] || params[:controller]))
87
+ session_index = "as:#{id}"
88
+ session[session_index] ||= {}
89
+ session[session_index]
90
+ end
91
+
92
+ # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
93
+ def handle_user_settings
94
+ if self.class.uses_active_scaffold?
95
+ active_scaffold_config.actions.each do |action_name|
96
+ conf_instance = active_scaffold_config.send(action_name) rescue next
97
+ next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
98
+ active_scaffold_session_storage[action_name] ||= {}
99
+ conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
100
+ end
101
+ end
102
+ end
103
+
104
+ def check_input_device
105
+ if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
106
+ session[:input_device_type] = 'TOUCH'
107
+ session[:hover_supported] = false
108
+ else
109
+ session[:input_device_type] = 'MOUSE'
110
+ session[:hover_supported] = true
111
+ end if session[:input_device_type].nil?
112
+ end
113
+
114
+ def touch_device?
115
+ session[:input_device_type] == 'TOUCH'
116
+ end
117
+
118
+ def hover_via_click?
119
+ session[:hover_supported] == false
120
+ end
121
+
122
+ def self.js_framework=(framework)
123
+ @@js_framework = framework
124
+ end
125
+
126
+ def self.js_framework
127
+ @@js_framework ||= if defined? Jquery
128
+ :jquery
129
+ elsif defined? PrototypeRails
130
+ :prototype
131
+ end
132
+ end
133
+
134
+ # exclude bridges you do not need
135
+ # name of bridge subdir should be used to exclude it
136
+ # eg
137
+ # ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
138
+ # if you are using Activescaffold as a gem add to initializer
139
+ # if you are using Activescaffold as a plugin add to active_scaffold_env.rb
140
+ def self.exclude_bridges=(bridges)
141
+ @@exclude_bridges = bridges
142
+ end
143
+
144
+ def self.exclude_bridges
145
+ @@exclude_bridges ||= []
146
+ end
147
+
148
+ def self.root
149
+ File.dirname(__FILE__) + "/.."
150
+ end
151
+
152
+ module ClassMethods
153
+ def active_scaffold(model_id = nil, &block)
154
+ # initialize bridges here
155
+ ActiveScaffold::Bridges.run_all
156
+
157
+ # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
158
+ model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id
159
+
160
+ # run the configuration
161
+ @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
162
+ @active_scaffold_config_block = block
163
+ self.links_for_associations
164
+
165
+ @active_scaffold_frontends = []
166
+ if active_scaffold_config.frontend.to_sym != :default
167
+ active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views')
168
+ @active_scaffold_frontends << active_scaffold_custom_frontend_path
169
+ end
170
+ active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views')
171
+ @active_scaffold_frontends << active_scaffold_default_frontend_path
172
+ @active_scaffold_custom_paths = []
173
+
174
+ self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock}
175
+ self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
176
+ self.active_scaffold_config.configure &block if block_given?
177
+ self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil?
178
+ self.active_scaffold_config._load_action_columns
179
+
180
+ # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
181
+ klass = self.active_scaffold_config.model
182
+ klass.define_attribute_methods unless klass.attribute_methods_generated?
183
+ # include the rest of the code into the controller: the action core and the included actions
184
+ module_eval do
185
+ include ActiveScaffold::Finder
186
+ include ActiveScaffold::Constraints
187
+ include ActiveScaffold::AttributeParams
188
+ include ActiveScaffold::Actions::Core
189
+ active_scaffold_config.actions.each do |mod|
190
+ name = mod.to_s.camelize
191
+ include "ActiveScaffold::Actions::#{name}".constantize
192
+
193
+ # sneak the action links from the actions into the main set
194
+ if link = active_scaffold_config.send(mod).link rescue nil
195
+ if link.is_a? Array
196
+ link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)}
197
+ elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
198
+ active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
199
+ end
200
+ end
201
+ end
202
+ end
203
+ self.append_view_path active_scaffold_paths
204
+ self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
205
+ end
206
+
207
+ def parent_prefixes
208
+ @parent_prefixes ||= super << 'active_scaffold_overrides' << ''
209
+ end
210
+
211
+ # To be called after include action modules
212
+ def _add_sti_create_links
213
+ new_action_link = active_scaffold_config.action_links.collection['new']
214
+ unless new_action_link.nil? || active_scaffold_config.sti_children.empty?
215
+ active_scaffold_config.action_links.collection.delete('new')
216
+ active_scaffold_config.sti_children.each do |child|
217
+ new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
218
+ new_sti_link.label = child.to_s.camelize.constantize.model_name.human
219
+ new_sti_link.parameters = {:parent_sti => controller_path}
220
+ new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
221
+ active_scaffold_config.action_links.collection.create.add(new_sti_link)
222
+ end
223
+ end
224
+ end
225
+
226
+ # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
227
+ def links_for_associations
228
+ return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested
229
+ active_scaffold_config.columns.each do |column|
230
+ next unless column.link.nil? and column.autolink?
231
+ #lazy load of action_link, cause it was really slowing down app in dev mode
232
+ #and might lead to trouble cause of cyclic constantization of controllers
233
+ #and might be unnecessary cause it is done before columns are configured
234
+ column.set_link(Proc.new {|col| link_for_association(col)})
235
+ end
236
+ end
237
+
238
+ def active_scaffold_controller_for_column(column, options = {})
239
+ begin
240
+ if column.polymorphic_association?
241
+ :polymorph
242
+ elsif options.include?(:controller)
243
+ "#{options[:controller].to_s.camelize}Controller".constantize
244
+ else
245
+ active_scaffold_controller_for(column.association.klass)
246
+ end
247
+ rescue ActiveScaffold::ControllerNotFound
248
+ nil
249
+ end
250
+ end
251
+
252
+ def link_for_association(column, options = {})
253
+ controller = active_scaffold_controller_for_column(column, options)
254
+
255
+ unless controller.nil?
256
+ options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
257
+ options[:parameters] ||= {}
258
+ options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
259
+ if column.plural_association?
260
+ # note: we can't create nested scaffolds on :through associations because there's no reverse association.
261
+
262
+ ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
263
+ else
264
+ actions = [:create, :update, :show]
265
+ actions = controller.active_scaffold_config.actions unless controller == :polymorph
266
+ column.actions_for_association_links.delete :new unless actions.include? :create
267
+ column.actions_for_association_links.delete :edit unless actions.include? :update
268
+ column.actions_for_association_links.delete :show unless actions.include? :show
269
+ ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
270
+ end
271
+ end
272
+ end
273
+
274
+ def link_for_association_as_scope(scope, options = {})
275
+ options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
276
+ options[:parameters] ||= {}
277
+ options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
278
+ ActiveScaffold::DataStructures::ActionLink.new('index', options)
279
+ end
280
+
281
+ def add_active_scaffold_path(path)
282
+ @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
283
+ @active_scaffold_custom_paths << path
284
+ end
285
+
286
+ def active_scaffold_paths
287
+ return @active_scaffold_paths unless @active_scaffold_paths.nil?
288
+
289
+ @active_scaffold_paths = []
290
+ @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil?
291
+ @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil?
292
+ @active_scaffold_paths
293
+ end
294
+
295
+ def active_scaffold_config
296
+ if @active_scaffold_config.nil?
297
+ self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config
298
+ else
299
+ @active_scaffold_config
300
+ end
301
+ end
302
+
303
+ def active_scaffold_config_block
304
+ @active_scaffold_config_block
305
+ end
306
+
307
+ def active_scaffold_superclasses_blocks
308
+ blocks = []
309
+ klass = self.superclass
310
+ while klass.respond_to? :active_scaffold_superclasses_blocks
311
+ blocks << klass.active_scaffold_config_block
312
+ klass = klass.superclass
313
+ end
314
+ blocks.compact.reverse
315
+ end
316
+
317
+ def active_scaffold_config_for(klass)
318
+ begin
319
+ controller = active_scaffold_controller_for(klass)
320
+ rescue ActiveScaffold::ControllerNotFound
321
+ config = ActiveScaffold::Config::Core.new(klass)
322
+ config._load_action_columns
323
+ config
324
+ else
325
+ controller.active_scaffold_config
326
+ end
327
+ end
328
+
329
+ # Tries to find a controller for the given ActiveRecord model.
330
+ # Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax.
331
+ # You may override this method to customize the search routine.
332
+ def active_scaffold_controller_for(klass)
333
+ controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::'
334
+ error_message = []
335
+ [controller_namespace, ''].each do |namespace|
336
+ ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name|
337
+ begin
338
+ controller = "#{namespace}#{controller_name.camelize}Controller".constantize
339
+ rescue NameError => error
340
+ # Only rescue NameError associated with the controller constant not existing - not other compile errors
341
+ if error.message["uninitialized constant #{controller}"]
342
+ error_message << "#{namespace}#{controller_name.camelize}Controller"
343
+ next
344
+ else
345
+ raise
346
+ end
347
+ end
348
+ raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold?
349
+ raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model.to_s == klass.to_s
350
+ return controller
351
+ end
352
+ end
353
+ raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller
354
+ end
355
+
356
+ def uses_active_scaffold?
357
+ !active_scaffold_config.nil?
358
+ end
359
+ end
360
+ end
361
+
362
+ require 'active_scaffold_env'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 4
10
- version: 3.1.4
9
+ - 5
10
+ version: 3.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Many, see README
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-06 00:00:00 Z
18
+ date: 2011-10-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ files:
138
138
  - frontends/default/views/_list_pagination_links.html.erb
139
139
  - frontends/default/views/_list_record.html.erb
140
140
  - frontends/default/views/_action_group.html.erb
141
- - frontends/default/views/_render_field.js.erb
141
+ - frontends/default/views/_list_messages.html.erb
142
142
  - frontends/default/views/_row.html.erb
143
143
  - frontends/default/views/_messages.html.erb
144
144
  - frontends/default/views/_search.html.erb
@@ -155,11 +155,11 @@ files:
155
155
  - frontends/default/views/add_existing_form.html.erb
156
156
  - frontends/default/views/create.html.erb
157
157
  - frontends/default/views/_human_conditions.html.erb
158
- - frontends/default/views/_list_messages.html.erb
158
+ - frontends/default/views/_horizontal_subform_footer.html.erb
159
159
  - frontends/default/views/field_search.html.erb
160
- - frontends/default/views/add_existing.js.erb
160
+ - frontends/default/views/_render_field.js.erb
161
161
  - frontends/default/views/search.html.erb
162
- - frontends/default/views/destroy.js.erb
162
+ - frontends/default/views/add_existing.js.erb
163
163
  - frontends/default/views/update.html.erb
164
164
  - frontends/default/views/_list_pagination.html.erb
165
165
  - frontends/default/views/_list_record_columns.html.erb
@@ -167,6 +167,7 @@ files:
167
167
  - frontends/default/views/_list_with_header.html.erb
168
168
  - frontends/default/views/_search_attribute.html.erb
169
169
  - frontends/default/views/action_confirmation.html.erb
170
+ - frontends/default/views/destroy.js.erb
170
171
  - frontends/default/views/edit_associated.js.erb
171
172
  - frontends/default/views/form_messages.js.erb
172
173
  - frontends/default/views/mark.js.rjs
@@ -176,9 +177,8 @@ files:
176
177
  - frontends/default/views/on_update.js.erb
177
178
  - frontends/default/views/render_field.js.erb
178
179
  - frontends/default/views/update_column.js.erb
179
- - frontends/default/views/_base_form.html.erb~
180
- - frontends/default/views/_horizontal_subform_footer.html.erb
181
180
  - frontends/default/views/update_row.js.erb
181
+ - frontends/default/views/_base_form.html.erb~
182
182
  - frontends/default/views/_form.html.erb~
183
183
  - frontends/default/views/_row.html.erb~
184
184
  - frontends/default/views/render_field.js.erb~
@@ -232,6 +232,7 @@ files:
232
232
  - lib/active_scaffold/config/update.rb
233
233
  - lib/active_scaffold/config/mark.rb
234
234
  - lib/active_scaffold/config/search.rb~
235
+ - lib/active_scaffold/config/nested.rb~
235
236
  - lib/active_scaffold/configurable.rb
236
237
  - lib/active_scaffold/constraints.rb
237
238
  - lib/active_scaffold/data_structures/action_columns.rb
@@ -246,6 +247,8 @@ files:
246
247
  - lib/active_scaffold/data_structures/nested_info.rb
247
248
  - lib/active_scaffold/data_structures/bridge.rb
248
249
  - lib/active_scaffold/data_structures/action_columns.rb~
250
+ - lib/active_scaffold/data_structures/action_link.rb~
251
+ - lib/active_scaffold/data_structures/nested_info.rb~
249
252
  - lib/active_scaffold/finder.rb
250
253
  - lib/active_scaffold/helpers/association_helpers.rb
251
254
  - lib/active_scaffold/helpers/controller_helpers.rb
@@ -305,6 +308,7 @@ files:
305
308
  - lib/active_scaffold/bridges/semantic_attributes.rb
306
309
  - lib/active_scaffold/bridges/semantic_attributes/column.rb
307
310
  - lib/active_scaffold/bridges/shared/date_bridge.rb
311
+ - lib/active_scaffold/bridges/shared/date_bridge.rb~
308
312
  - lib/active_scaffold/bridges/tiny_mce.rb
309
313
  - lib/active_scaffold/bridges/tiny_mce/helpers.rb
310
314
  - lib/active_scaffold/version.rb
@@ -330,17 +334,20 @@ files:
330
334
  - lib/active_scaffold/extensions/cache_association.rb~
331
335
  - lib/active_scaffold/extensions/reverse_associations.rb~
332
336
  - lib/active_scaffold/extensions/routing_mapper.rb~
337
+ - lib/active_scaffold/extensions/unsaved_associated.rb~
333
338
  - lib/active_scaffold/paginator.rb
334
339
  - lib/active_scaffold/responds_to_parent.rb
335
340
  - lib/active_scaffold/engine.rb
336
341
  - lib/active_scaffold/attribute_params.rb~
337
342
  - lib/active_scaffold/finder.rb~
343
+ - lib/active_scaffold/constraints.rb~
338
344
  - lib/generators/active_scaffold/USAGE
339
345
  - lib/generators/active_scaffold/active_scaffold_generator.rb
340
346
  - lib/generators/active_scaffold_controller/USAGE
341
347
  - lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb
342
348
  - lib/generators/active_scaffold_controller/templates/controller.rb
343
349
  - lib/generators/active_scaffold_controller/templates/helper.rb
350
+ - lib/active_scaffold.rb~
344
351
  - public/blank.html
345
352
  - shoulda_macros/macros.rb
346
353
  - vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png