Sha256: 5bec8e4ab4e6c26ec07a35ed131719393e1a5789dd0e886d75c429454e80891e

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Events
    # This module is used to be included in event classes inheriting from SimpleEvent
    # whose resource is coauthorable.
    #
    # It adds the following methods related with the creator author: author_name, author_nickname, author_path and author_url to the i18n interpolations.
    module CoauthorEvent
      extend ActiveSupport::Concern

      included do
        i18n_attributes :author_name, :author_nickname, :author_path, :author_url

        def author_nickname
          author_presenter&.nickname.to_s
        end

        def author_name
          author_presenter&.name.to_s
        end

        def author_path
          author_presenter&.profile_path.to_s
        end

        def author_url
          author_presenter&.profile_url.to_s
        end

        def author_presenter
          return unless author
          @author_presenter ||= Decidim::UserPresenter.new(author)
        end

        def author
          resource.creator_author if resource.respond_to?(:creator_author)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.14.4 lib/decidim/events/coauthor_event.rb
decidim-core-0.14.3 lib/decidim/events/coauthor_event.rb
decidim-core-0.14.2 lib/decidim/events/coauthor_event.rb
decidim-core-0.14.1 lib/decidim/events/coauthor_event.rb
decidim-core-0.13.1 lib/decidim/events/coauthor_event.rb
decidim-core-0.13.0 lib/decidim/events/coauthor_event.rb
decidim-core-0.13.0.pre1 lib/decidim/events/coauthor_event.rb