Module: RubyCms::ContentBlocksGrouping

Defined in:
lib/generators/ruby_cms/templates/lib/ruby_cms/content_blocks_grouping.rb

Defined Under Namespace

Classes: Row

Class Method Summary collapse

Class Method Details

.build_row(key, blocks) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/ruby_cms/templates/lib/ruby_cms/content_blocks_grouping.rb', line 23

def build_row(key, blocks)
  first = blocks.first
  Row.new(
    key: key,
    id: first.id,
    locale: blocks.map(&:locale).sort.join(", "),
    title: first.title,
    content_type: first.content_type,
    published: blocks.all?(&:published?),
    content_block: first
  )
end

.group_by_key(collection) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/generators/ruby_cms/templates/lib/ruby_cms/content_blocks_grouping.rb', line 14

def group_by_key(collection)
  return [] if collection.nil? || collection.empty?

  collection
    .group_by(&:key)
    .map { |key, blocks| build_row(key, blocks) }
    .sort_by(&:key)
end