Skip to content

Commit

Permalink
move into helper
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Oct 20, 2016
1 parent 84cba4f commit 85c3a6f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Metrics/MethodLength:
Enabled: false

Metrics/BlockLength:
Max: 28
Max: 30

Style/BlockDelimiters:
Exclude:
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def unique_custom_fields
config.document_unique_id_param = 'ids'

# solr field configuration for search results/index views
config.index.title_field = 'full_title_ssim'
config.index.preferred_title_field = 'readonly_title_tesim'
config.index.title_field = 'readonly_title_tesim'
config.add_show_field 'creator_ssim', label: 'Creator'

config.add_search_field 'all_fields', label: 'Everything'
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/index_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module IndexHelper
def render_index_document(document)
field = index_presenter(document).label(document_show_link_field(document))
span = []
if field.length == 1 || !field.is_a?(Array)
span << content_tag(:span, style: 'display: block;', dir: field.dir) do
link_to_document(document, document_show_link_field(document))
end
else
field.each do |value|
span << content_tag(:span, style: 'display: block;', dir: value.dir) do
link_to(value, url_for_document(document), document_link_params(document, {}))
end
end
end
safe_join span
end
end
13 changes: 1 addition & 12 deletions app/presenters/rtl_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def label(field_or_string_or_proc, opts = {})
value = case field_or_string_or_proc
when Symbol
config = field_config(field_or_string_or_proc)
value_from_symbol(field_or_string_or_proc)
@document[field_or_string_or_proc]
when Proc
field_or_string_or_proc.call(@document, opts)
when String
Expand All @@ -16,17 +16,6 @@ def label(field_or_string_or_proc, opts = {})

private

def value_from_symbol(field)
default_title_field = @configuration.index.title_field
preferred_title_field = @configuration.index.preferred_title_field

if field.to_s == default_title_field && @document.key?(preferred_title_field)
@document[preferred_title_field]
else
@document[field]
end
end

def label_value(value, config)
if value.is_a?(Array) && value.count > 1
value.collect { |v| field_values(config, value: v) }
Expand Down
23 changes: 1 addition & 22 deletions app/views/catalog/_index_header_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,15 @@
<%= render_index_doc_actions document, wrapping_class: "index-document-functions col-sm-3 col-lg-2" %>
<% end %>
<h3 class="index_title document-title-heading <%= document_actions.present? ? "col-sm-9 col-lg-10" : "col-md-12" %>">
<div class="row">
</div>
<% if counter = document_counter_with_offset(document_counter) %>
<span style="" class="document-counter col-sm-1">
<%= t('blacklight.search.documents.counter', counter: counter) %>
</span>
<% end %>
<div class="col-sm-11">
<% field = index_presenter(document).label(document_show_link_field(document)) %>
<% if field.length == 1 || !field.is_a?(Array) %>
<% valdir = Array(field).first.dir %>
<span style="display: block;" dir="<%= valdir %>">
<%= link_to_document document, document_show_link_field(document), counter: counter %>
</span>
<% else %>
<% valdirs = [] %>
<% field.each do |value| %>
<% valdirs << value.dir %>
<% end %>
<% field.each do |value| %>
<span style="display: block;" dir="<%= valdirs[field.index(value)] %>">
<%= link_to value, '/' %>
</span>
<% end %>
<% end %>
<%= render_index_document document %>
</div>
</h3>
Expand Down

0 comments on commit 85c3a6f

Please sign in to comment.