publisher_helper.rb 1.47 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

module PublisherHelper
8
  def service_button(service)
9
    provider_title = I18n.t("services.index.share_to", provider: service.provider.titleize)
10
    content_tag :div,
11
                class:   "btn btn-link service_icon dim",
12
                title:   "#{provider_title} (#{service.nickname})",
13 14
                id:      service.provider,
                maxchar: service.class::MAX_CHARACTERS,
15 16
                data:    {toggle: "tooltip", placement: "bottom"} do
      if service.provider == "wordpress"
17
        content_tag(:span, "", class: "social-media-logos-wordpress-16x16")
18
      else
19
        content_tag(:i, "", class: "entypo-social-#{service.provider} small")
20 21 22
      end
    end
  end
23 24 25 26 27 28 29 30 31 32 33 34 35

  def public_selected?(selected_aspects)
    "public" == selected_aspects.try(:first) || publisher_boolean?(:public)
  end

  def all_aspects_selected?(selected_aspects)
    !all_aspects.empty? && all_aspects.size == selected_aspects.size && !public_selected?(selected_aspects)
  end

  def aspect_selected?(aspect, selected_aspects)
    selected_aspects.include?(aspect) && !all_aspects_selected?(selected_aspects) && !public_selected?(selected_aspects)
  end

36 37 38 39
  def publisher_open?
    publisher_boolean?(:open)
  end

40 41 42 43 44
  private

  def publisher_boolean?(option)
    @stream.try(:publisher).try(option) == true
  end
45
end