app/controllers/umlaut_configurable.rb in umlaut-4.0.3 vs app/controllers/umlaut_configurable.rb in umlaut-4.1.0.pre.alpha.1
- old
+ new
@@ -232,28 +232,59 @@
# We add a custom method into the resolve_sections array,
# ensure_order!.
resolve_sections [].extend Module.new do
- # Convenience method for re-ordering sections
- # Swaps elements if necessary to ensure they are in the specified order.
- # For example, make sure holding comes before document_delivery:
- # resolve_sections.ensure_order!("holding", "document_delivery")
- # Maybe in the future we'll expand this to take variable arguments.
+
+ # 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
@@ -275,27 +306,13 @@
add_resolve_sections! do
div_id "fulltext"
html_area :main
partial :fulltext
show_partial_only true
- end
-
- add_resolve_sections! do
- div_id "search_inside"
- html_area :main
- partial "search_inside"
- show_partial_only true
- end
+ end
add_resolve_sections! do
- div_id "excerpts"
- html_area :main
- list_visible_limit 5
- visibility :responses_exist
- end
-
- add_resolve_sections! do
div_id "audio"
html_area :main
visibility :responses_exist
end
@@ -348,9 +365,23 @@
add_resolve_sections! do
div_id "export_citation"
html_area :sidebar
visibility :in_progress
+ end
+
+ add_resolve_sections! do
+ div_id "search_inside"
+ html_area :sidebar
+ partial "search_inside"
+ show_partial_only true
+ end
+
+ add_resolve_sections! do
+ div_id "excerpts"
+ html_area :sidebar
+ list_visible_limit 5
+ visibility :responses_exist
end
add_resolve_sections! do
div_id "related_items"
html_area :sidebar