publisher_helper.rb 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9
#   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
  def remote?
    params[:controller] != "tags"
  end

Steffen van Bergerem's avatar
Steffen van Bergerem committed
10
  def service_button(service)
zauberstuhl's avatar
zauberstuhl committed
11 12 13
    provider_title = I18n.t(
      "services.index.share_to",
      provider: service.provider.titleize)
Steffen van Bergerem's avatar
Steffen van Bergerem committed
14
    content_tag :div,
15
                class:   "btn btn-link service_icon dim",
zauberstuhl's avatar
zauberstuhl committed
16
                title:   "#{provider_title} (#{service.nickname})",
17 18 19 20
                id:      "#{service.provider}",
                maxchar: "#{service.class::MAX_CHARACTERS}",
                data:    {toggle: "tooltip", placement: "bottom"} do
      if service.provider == "wordpress"
21
        content_tag(:span, "", class: "social-media-logos-wordpress-16x16")
Steffen van Bergerem's avatar
Steffen van Bergerem committed
22
      else
23
        content_tag(:i, "", class: "entypo-social-#{ service.provider } small")
Steffen van Bergerem's avatar
Steffen van Bergerem committed
24 25 26
      end
    end
  end
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  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

  private

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