lfzawacki/musical-artifacts

View on GitHub
app/views/artifacts/_side_buttons.html.haml

Summary

Maintainability
Test Coverage
%span.pull-right.side-buttons

  - common_class = "btn btn-default"
  - favorite_class = "#{common_class} favorite #{"hidden" if !can?(:favorite, artifact)}"
  - unfavorite_class = "#{common_class} unfavorite #{"hidden" if !can?(:unfavorite, artifact)}"

  %span.side-button.favorite-artifact
    - if current_user.present?
      = link_to favorite_artifact_path(artifact), remote: true, class: favorite_class, method: :post do
        %span.favorite-count= artifact.favorite_count
        %i.fa.fa-star
        .small-label= t('.favorite')

      = link_to unfavorite_artifact_path(artifact), remote: true, class: unfavorite_class, method: :delete do
        %span.favorite-count= artifact.favorite_count
        %i.fa.fa-star
        .small-label= t('.unfavorite')

    - else
      = link_to new_user_session_path, class: "#{common_class} inactive-favorite" do
        %span.favorite-count= artifact.favorite_count
        %i.fa.fa-star
        .small-label= t('.favorite')

  - if can?(:download, artifact) && artifact.file.try(:url)
    = download_link(artifact, class: 'btn-download') do
      %span.side-button.download-count.btn.btn-default
        = number_with_delimiter(artifact.download_count)
        %i.fa.fa-download
        .small-label
          = t('.download')
          = "(#{number_to_human_size(artifact.file.file.size)})"

  - elsif artifact.mirrors.present?
    - mirror = artifact.mirrors.first
    = external_link_to mirror, class: '' do
      %span.side-button.download-count.btn.btn-default
        %i.fa.fa-external-link-square
        %i.fa.fa-download
        .small-label
          = t('.download_mirror')
          %br
          = domain_from_link(mirror)