class Decidim::ContentBlockManifest
This class acts as a manifest for content blocks.
A content block is a view section in a given page. Those sections can be registered by Decidim
modules, and are configurable and sortable. They are a useful way to customize a given page, without having to rely on overwriting the views files. Also, this system is more powerful than basic view hooks (see the `ViewHooks` class for reference), as view hooks don't have a way to explicitly control the order of the hooked views.
Content blocks are intended to be used in the home page, for example.
A content block has a set of settings and an associated `cell` that will handle the layout logic. They can also have attached images that can be used as background images, for example. You must explicitly specify the number of images the block will have (this means the number of attached images cannot be configurable). Each content block is identified by a name, which has to be unique per scope.
Public Instance Methods
Public: Registers whether this content block should be shown by default when creating an organization. Use `#default` to retrieve it.
# File lib/decidim/content_block_manifest.rb, line 39 def default! self.default = true end
# File lib/decidim/content_block_manifest.rb, line 43 def has_settings? settings.attributes.any? end
# File lib/decidim/content_block_manifest.rb, line 47 def settings(&block) @settings ||= SettingsManifest.new yield(@settings) if block @settings end
Private Instance Methods
# File lib/decidim/content_block_manifest.rb, line 55 def image_names_are_unique image_names = images.pluck(:name) errors.add(:images, "names must be unique per manifest") if image_names.count != image_names.uniq.count end
# File lib/decidim/content_block_manifest.rb, line 60 def images_have_an_uploader uploaders = images.map { |image| image[:uploader].presence } errors.add(:images, "must have an uploader") if uploaders.compact.count != images.count end