Sha256: 9d278ccf5776d146dc9c76c745cd09fe5471d6d7bacd0e00d0a9b86a5a9e0712

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module ContentBlocks
    class ParticipatorySpaceHeroCell < Decidim::ContentBlocks::BaseCell
      include Decidim::TwitterSearchHelper

      delegate :title, :hashtag, :attached_uploader, to: :resource

      def cta_text
        return unless model

        @cta_text ||= translated_attribute(model.settings.button_text).presence
      end

      def cta_path
        return unless model

        @cta_path ||= translated_attribute(model.settings.button_url).presence
      end

      def title_text
        decidim_escape_translated(title)
      end

      def subtitle_text
        return unless resource.respond_to?(:subtitle)

        decidim_escape_translated(resource.subtitle)
      end

      # If it is called from the landing page content block, use the background image defined there
      # Else, use the banner image defined in the space (for assemblies)
      def image_path
        return model.images_container.attached_uploader(:background_image).url if model.respond_to?(:images_container)

        attached_uploader(:banner_image).url
      end

      def has_hashtag?
        @has_hashtag ||= hashtag.present?
      end

      def has_cta?
        [cta_text, cta_path].all?
      end

      def escaped_hashtag
        return unless has_hashtag?

        @escaped_hashtag ||= decidim_html_escape(hashtag)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/cells/decidim/content_blocks/participatory_space_hero_cell.rb
decidim-core-0.29.0 app/cells/decidim/content_blocks/participatory_space_hero_cell.rb
decidim-core-0.29.0.rc4 app/cells/decidim/content_blocks/participatory_space_hero_cell.rb