app/controllers/umlaut_configurable.rb in umlaut-4.1.0.pre3 vs app/controllers/umlaut_configurable.rb in umlaut-4.1.0
- old
+ new
@@ -13,14 +13,75 @@
included do
class_attribute :umlaut_config
helper_method :umlaut_config
self.umlaut_config = Confstruct::Configuration.new
end
-
+ # Used for `resolve_sections` config, like an Array but
+ # we add a some custom methods into the resolve_sections array,
+ # insert_section, remove_section. With a sub-class.
+ class ResolveSectionsArray < Array
+ # Deprecated. This was a silly confusing way to do this.
+ # See #remove and #insert below instead.
+ def ensure_order!(first, second)
+ $stderr.puts "resolve_sections.ensure_order! is deprecated, please see resolve_sections.remove and resolve_sections.insert"
+ list = self
+ index1 = list.index {|s| s[:div_id].to_s == first.to_s}
+ index2 = list.index {|s| s[:div_id].to_s == second.to_s}
+
+ (list[index1], list[index2] = list[index2], list[index1]) if index1 && index2 && (index1 > index2)
+
+ list
+ end
+
+ # Insert a section_config hash before or after an existing
+ # section, by the existing section's div_id
+ #
+ # resolve_sections.insert_section({:div_id => "new"}, :after => "fulltext")
+ # resolve_sections.insert_section( resolve_sections.remove_section("document_deliver"), :before => "fulltext")
+ def insert_section(section_config, options = {})
+ list = self
+
+ if options[:before]
+ i = (list.find_index {|s| s[:div_id].to_s == options[:before].to_s}) || 0
+ list.insert(i, section_config)
+ elsif options[:after]
+ i = (list.find_index {|s| s[:div_id].to_s == options[:after].to_s}) || (list.length - 1)
+ list.insert(i + 1, section_config)
+ else
+ # just add at end of list
+ list << section_config
+ end
+ end
+
+ # Remove a configuration block with a certain div_id from the configuration entirely,
+ # returning the removed configuration block (or nil if none exists).
+ # You can re-insert it with #insert if you like.
+ def remove_section(div_id)
+ list = self
+ i = list.find_index {|s| s[:div_id].to_s == div_id.to_s}
+ return list.delete_at(i) if i
+ end
+
+ # Make deep_dup work
+ def deep_dup
+ self.class.new.concat super
+ end
+
+ # Make map work returning same class, to avoid breaking Hashie::Mash.
+ # Bah, this is a mess, yep.
+ def map(*args, &block)
+ self.class.new.concat super
+ end
+ alias_method :collect, :map
+
+ end
+
+
+
# Call as UmlautConfigurable.set_default_configuration!(confstruct_obj)
# to initialize
def self.set_default_configuration!(configuration)
configuration.configure do
app_name 'Find It'
@@ -109,16 +170,16 @@
# 'true' or shortname of a service type.
skip_resolve_menu false
# How many seconds between updates of the background updater for background
# services?
- poll_wait_seconds 2.2
+ poll_wait_seconds 2.0
# The FIRST AJAX callback for bg tasks should be much quicker. So we
# get any bg tasks that executed nearly instantaneously, and on page
# refresh when bg is really all loaded on back-end, but still needs JS to
# fetch it.
- initial_poll_wait_seconds 0.300
+ initial_poll_wait_seconds 0.250
# if a background service hasn't returned in this many seconds, consider
# it failed. (May actually be slow, more likely raised an exception and
# our exception handling failed to note it as failed.)
background_service_timeout 30
@@ -227,64 +288,16 @@
# Here are the defaults. You can add new elements to the resolve_sections
# array in config and modify or delete existing resolve_sections elements.
#
# Look in comments at top of SectionRenderer class for what the keys
# in each entry mean.
-
-
- # We add a custom method into the resolve_sections array,
- # ensure_order!.
- resolve_sections [].extend Module.new do
+
+ # ResolveSectionsArray is like an Array, but with
+ # some additional methods making it easier to do common
+ # configuration tasks.
+ resolve_sections ResolveSectionsArray.new
- # Deprecated. This was a silly confusing way to do this.
- # See #remove and #insert below instead.
- def self.ensure_order!(first, second)
- $stderr.puts "resolve_sections.ensure_order! is deprecated, please see resolve_sections.remove and resolve_sections.insert"
-
- list = self
-
- index1 = list.index {|s| s[:div_id].to_s == first.to_s}
- index2 = list.index {|s| s[:div_id].to_s == second.to_s}
-
- (list[index1], list[index2] = list[index2], list[index1]) if index1 && index2 && (index1 > index2)
-
- list
- end
-
- # Insert a section_config hash before or after an existing
- # section, by the existing section's div_id
- #
- # resolve_sections.insert_section({:div_id => "new"}, :after => "fulltext")
- # resolve_sections.insert_section( resolve_sections.remove_section("document_deliver"), :before => "fulltext")
- def self.insert_section(section_config, options = {})
- list = self
-
- if options[:before]
- i = (list.find_index {|s| s[:div_id].to_s == options[:before].to_s}) || 0
- list.insert(i, section_config)
- elsif options[:after]
- i = (list.find_index {|s| s[:div_id].to_s == options[:after].to_s}) || (list.length - 1)
- list.insert(i + 1, section_config)
- else
- # just add at end of list
- list << section_config
- end
- end
-
- # Remove a configuration block with a certain div_id from the configuration entirely,
- # returning the removed configuration block (or nil if none exists).
- # You can re-insert it with #insert if you like.
- def self.remove_section(div_id)
- list = self
- i = list.find_index {|s| s[:div_id].to_s == div_id.to_s}
- return list.delete_at(i) if i
- end
-
- end
-
-
-
##########
#
# Names of these sections can be given in Rails i18n, under key
# umlaut.display_sections.#{section_div_id}.title
# If not given there, will be automatically calculated from
@@ -410,9 +423,10 @@
html_area :service_errors
service_type_values []
end
end
+
end
end