Sha256: 0bd6b41f1bc994e9563032b79888ade6099d5a452e62b844002369ff66f83b89

Contents?: true

Size: 1.25 KB

Versions: 13

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Blogs
    module ContentBlocks
      class HighlightedPostsCell < Decidim::ContentBlocks::HighlightedElementsCell
        include Decidim::ComponentPathHelper
        include Decidim::CardHelper

        def show
          render unless posts_count.zero?
        end

        private

        def posts
          @posts ||= Decidim::Blogs::Post.published.where(component: published_components).created_at_desc
        end

        def decidim_blogs
          return unless single_component

          Decidim::EngineRouter.main_proxy(single_component)
        end

        def single_component
          @single_component ||= published_components.one? ? published_components.first : nil
        end

        def posts_to_render
          @posts_to_render ||= posts.includes([:author, :component]).limit(limit)
        end

        def posts_count
          @posts_count ||= posts.size
        end

        def cache_hash
          hash = []
          hash << "decidim/blogs/content_blocks/highlighted_posts"
          hash << posts.cache_key_with_version
          hash << I18n.locale.to_s
          hash.join(Decidim.cache_key_separator)
        end

        def limit
          3
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-blogs-0.29.1 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.4 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.29.0 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.3 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.29.0.rc4 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.29.0.rc3 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.29.0.rc2 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.29.0.rc1 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.2 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.1 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.0 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.0.rc5 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb
decidim-blogs-0.28.0.rc4 app/cells/decidim/blogs/content_blocks/highlighted_posts_cell.rb