publisher_helper.rb 1.44 KB
Newer Older
1 2 3 4 5
#   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
Steffen van Bergerem's avatar
Steffen van Bergerem committed
6
  def service_button(service)
7
    provider_title = I18n.t("services.index.share_to", provider: service.provider.titleize)
Steffen van Bergerem's avatar
Steffen van Bergerem committed
8
    content_tag :div,
9
                class:   "btn btn-link service_icon dim",
zauberstuhl's avatar
zauberstuhl committed
10
                title:   "#{provider_title} (#{service.nickname})",
11 12
                id:      service.provider,
                maxchar: service.class::MAX_CHARACTERS,
13 14
                data:    {toggle: "tooltip", placement: "bottom"} do
      if service.provider == "wordpress"
15
        content_tag(:span, "", class: "social-media-logos-wordpress-16x16")
Steffen van Bergerem's avatar
Steffen van Bergerem committed
16
      else
17
        content_tag(:i, "", class: "entypo-social-#{service.provider} small")
Steffen van Bergerem's avatar
Steffen van Bergerem committed
18 19 20
      end
    end
  end
21 22 23 24 25 26 27 28 29 30 31 32 33

  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

34 35 36 37
  def publisher_open?
    publisher_boolean?(:open)
  end

38 39 40 41 42
  private

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