lfzawacki/musical-artifacts

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

Summary

Maintainability
Test Coverage
- search_fields = Artifact.search_fields + ['q']

.filter-sidebar.light-item.filter-licenses
  - license_params = params.slice(*search_fields)
  - if params[:license] == 'free'
    - text = t('.all_licenses')
    - path = artifacts_path(license_params.except(:license))
  - else
    - text = t('.free_licenses')
    - path = artifacts_path(license_params.merge(license: 'free'))

  = link_to path do
    %i.fa.fa-book
    = text

- [:tags, :apps, :formats].each do |tag_type|
  - if @tags[tag_type].any?
    .filter-sidebar.dark-item
      %h3.tag-title= t("artifacts.index.filters.#{tag_type}")
      - @tags[tag_type].each do |tag|
        - tags = params[tag_type].try(:split, ',').to_a

        - if tag_type == :tags
          - merge_with = ([tag.name] + tags).join(',')
        - else
          - merge_with = tag.name

        - new_params = params.slice(*search_fields).merge(tag_type => merge_with)

        - if tags.include?(tag.name)
          %span.tag-filter.selected-tag= "#{tag.name} (#{tag.count})"
        - else
          = link_to "#{tag.name} (#{tag.count})", artifacts_path(new_params), class: "tag-filter #{tag_type.to_s.singularize}-tag"