lib/scrivito/basic_obj.rb in scrivito_sdk-1.0.0 vs lib/scrivito/basic_obj.rb in scrivito_sdk-1.1.0.rc1
- old
+ new
@@ -598,15 +598,26 @@
toclist = children
toclist = toclist.reject { |toc| toc.binary? } unless args.include?(:all)
toclist
end
- # @param objs_to_be_sorted [Array<Scrivito::BasicObj>] unsorted list of CMS objects
- # @param list [Array<Scrivito::BasicObj>] list of objects that defines the order
- # @return [Array<Scrivito::BasicObj>] a sorted list of objects. Objects present in
- # +objs_to_be_sorted+ but not in +list+ are appended to the end, sorted by +Obj#id+
- def self.sort_by_list(objs_to_be_sorted, list)
- (list & objs_to_be_sorted) + (objs_to_be_sorted - list).sort_by(&:id)
+ # @api public
+ #
+ # Returns a list of children that are sorted according to the order specifed in the
+ # +child_order+ attribute. The same sort order is used when rendering navigations using
+ # the {ScrivitoHelper#scrivito_tag_list scrivito_tag_list} helper.
+ #
+ # @return [Array<Obj>]
+ def sorted_toclist
+ if sortable_toclist?
+ (child_order & toclist) + (toclist - child_order).sort_by(&:id)
+ else
+ toclist
+ end
+ end
+
+ def sortable_toclist?
+ has_attribute?(:child_order)
end
# This should be a Set, because it's faster in this particular case.
SYSTEM_KEYS = Set.new(%w[
body