Sha256: c76df4bdeabef54b06699aa5d505d739f18a21a6fbc8e45a3e910920d4766860
Contents?: true
Size: 1.41 KB
Versions: 8
Compression:
Stored size: 1.41 KB
Contents
module Ecoportal module API class V2 class Page class Sections < Common::Content::CollectionModel class_resolver :section_class, "Ecoportal::API::V2::Page::Section" self.klass = :section_class def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED) sec_doc = Ecoportal::API::V2::Page::Section.new_doc(split: split) upsert!(sec_doc, pos: pos, before: before, after: after) do |section| section.heading = name if prev = previous_section(section) section.weight = prev.weight end yield(section) if block_given? #fix_weights! # a server bug prevents to set the weight of existing sections end end def ordered each_with_index.sort_by do |section, index| (section.weight >= 9999) ? [index, index] : [section.weight, index] end.map(&:first) end private def fix_weights! ordered.each_with_index do |section, index| section.weight = index end end def previous_section(value) secs = ordered pos = secs.index(value) - 1 return if pos < 0 secs[pos] end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems