From 7a7083c2ad15770d6fa100496bfaecf271b1cc26 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Mon, 22 Jun 2015 20:38:13 +0200 Subject: [PATCH] helper for facet lists --- app/helpers/search_helper.rb | 13 +++++++++++++ app/views/search/index.html.slim | 18 +++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 app/helpers/search_helper.rb diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb new file mode 100644 index 0000000..d1c5945 --- /dev/null +++ b/app/helpers/search_helper.rb @@ -0,0 +1,13 @@ +module SearchHelper + def facet_list(facets) + return unless facets.present? + content_tag(:ul) do + facets.each do |term, count| + concat content_tag(:li, + "#{term} (#{count})", + class: "facet" + ) + end + end + end +end diff --git a/app/views/search/index.html.slim b/app/views/search/index.html.slim index 91f2428..5a1dc06 100644 --- a/app/views/search/index.html.slim +++ b/app/views/search/index.html.slim @@ -1,17 +1,13 @@ div = render 'search/form' -.row - .small-4.columns - ul - - @paper_type_facets.each do |paper_type, count| - li.facet - = "#{paper_type} (#{count})" - .small-4.columns.end - ul - - @originator_facets.each do |originator, count| - li.facet - = "#{originator} (#{count})" + +- if params[:q].present? + .row + .small-4.columns + = facet_list(@paper_type_facets) + .small-4.columns.end + = facet_list(@originator_facets) .clearfix - if params[:q].present?