Sha256: d1ced3f51a9c5427ccffaefb497e6d10c4dd03edcdf5ec1b3377bf4eaa98b38a

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    #
    # Decorator for meetings
    #
    class MeetingPresenter < SimpleDelegator
      include Decidim::TranslationsHelper
      include Decidim::ResourceHelper
      include Decidim::SanitizeHelper

      def meeting
        __getobj__
      end

      def title(links: false, all_locales: false)
        return unless meeting

        handle_locales(meeting.title, all_locales) do |content|
          content = decidim_html_escape(content)
          renderer = Decidim::ContentRenderers::HashtagRenderer.new(content)
          renderer.render(links: links).html_safe
        end
      end

      def description(links: false, all_locales: false)
        return unless meeting

        handle_locales(meeting.description, all_locales) do |content|
          renderer = Decidim::ContentRenderers::HashtagRenderer.new(content)
          renderer.render(links: links).html_safe
        end
      end

      # Next methods are used for present a Meeting As Proposal Author
      def name
        title
      end

      def nickname
        ""
      end

      def badge
        ""
      end

      def profile_path
        resource_locator(meeting).path
      end

      def avatar_url
        ActionController::Base.helpers.asset_path("decidim/meetings/icon.svg")
      end

      def deleted?
        false
      end

      def can_be_contacted?
        false
      end

      def has_tooltip?
        false
      end

      private

      def handle_locales(content, all_locales)
        if all_locales
          content.each_with_object({}) do |(locale, string), parsed_content|
            parsed_content[locale] = yield(string)
          end
        else
          yield(translated_attribute(content))
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-meetings-0.21.0 app/presenters/decidim/meetings/meeting_presenter.rb
decidim-meetings-0.20.1 app/presenters/decidim/meetings/meeting_presenter.rb
decidim-meetings-0.20.0 app/presenters/decidim/meetings/meeting_presenter.rb
decidim-meetings-0.19.1 app/presenters/decidim/meetings/meeting_presenter.rb
decidim-meetings-0.19.0 app/presenters/decidim/meetings/meeting_presenter.rb