diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index 8c8ee497e64cf450b45288651c85c6cf3f96503d..f061e4b368ac0e437a787fde3d6feea27a063cf4 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -1,5 +1,7 @@ class Communication::Block::Template::Base - class_attribute :components_descriptions, :layouts + class_attribute :components_descriptions, + :layouts, + :element_class attr_reader :block @@ -29,6 +31,10 @@ class Communication::Block::Template::Base self.layouts = list end + def self.has_elements(element_class) + self.element_class = element_class + end + def self.has_component(property, kind) self.components_descriptions ||= [] self.components_descriptions << { name: property, type: kind } @@ -92,7 +98,8 @@ class Communication::Block::Template::Base end def default_element - nil + return if self.class.element_class.nil? + self.class.element_class.new block end def elements diff --git a/app/models/communication/block/template/gallery.rb b/app/models/communication/block/template/gallery.rb index 38f353f754e49c083a58dcf6767be84591f34c31..8df44751774d9fbab69a6669f3f65dd43bc64dc7 100644 --- a/app/models/communication/block/template/gallery.rb +++ b/app/models/communication/block/template/gallery.rb @@ -1,10 +1,7 @@ class Communication::Block::Template::Gallery < Communication::Block::Template::Base has_layouts [:grid, :carousel] - - def default_element - Communication::Block::Template::Gallery::Image.new block - end + has_elements Communication::Block::Template::Gallery::Image def build_git_dependencies add_dependency active_storage_blobs diff --git a/app/models/communication/block/template/page.rb b/app/models/communication/block/template/page.rb index 023ccda4668ea9041449b2bcbd1e7cb5612e544f..521f841f93780579a8b35f9ba0d9ebe9df958926 100644 --- a/app/models/communication/block/template/page.rb +++ b/app/models/communication/block/template/page.rb @@ -20,10 +20,6 @@ class Communication::Block::Template::Page < Communication::Block::Template::Bas @main_page ||= page(data['page_id']) end - def layout - data['layout'] || 'grid' - end - def show_main_description data['show_main_description'] || false end