Skip to content

Commit

Permalink
Refactor config methods. now single method returns boolean for erb
Browse files Browse the repository at this point in the history
  • Loading branch information
sourslaw committed Aug 22, 2023
1 parent 14f9282 commit 9af7b70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
39 changes: 8 additions & 31 deletions app/presenters/show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,18 @@

class ShowPresenter < Blacklight::ShowPresenter

def test_field
arr = [ "type_ssi", "format_ssim", "sp_physical_format_ssi" ]
# arr = [ "country_ssi", "sp_country_ssi", "continent_ssi", "sp_continent_ssi" ]
# does the document have anything in the array / check if array contains any or all ? . .
# document['country_ssi'].present? # just returns true or false
# arr.include?('continent_ssi')
# document.include?(document['continent_ssi']) # this does not work. can't access document like an array
arr.each do |field|
return document[field].present? # returns boolean if fields in the document are present in the arr array
end
end

def test_arr
arr = configuration.show_fields.to_a
def type_arr
new_arr =[]
arr.each do |item|
new_arr.push(item[0])

configuration.show_fields.to_a.each do |item|
if item[1][:type]==:primary

This comment has been minimized.

Copy link
@mberkowski

mberkowski Aug 22, 2023

Member

I love how much slimmer this got - very rubyist. If you want to take it one step further, you can use it in if-predicate form. (Though rubocop might moan about this)

new_arr.push(item[0]) if item[1][:type] == :primary

new_arr.push(item[0])
end
end
new_arr
# new_arr.each do |field|
# return document[field].present? # returns boolean if fields in the document are present in the arr array
# end
end

def type_arr
arr = configuration.show_fields.to_a
new_arr =[]
arr.each do |item|
new_arr.push(item[1][:type])
new_arr.each do |field| # returns boolean if any field in new_arr is present in the document
return document[field].present?
end
new_arr
end

def each_primary_field
Expand All @@ -47,8 +28,4 @@ def each_secondary_field
end
end

def render_field?(field_config)
field_presenter(field_config).render_field? and has_value? field_config
end

end
6 changes: 1 addition & 5 deletions app/views/catalog/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
<% doc_presenter = document_presenter(document) %>
<hr>

<%= doc_presenter.test_field==true ? "Details" : "" %>
<% doc_presenter.each_primary_field do |field_name, field, field_presenter| %>
<%= render "show_fields", document: document, field: field, field_name: field_name, field_presenter: field_presenter %>
<% end -%>


<%= doc_presenter.test_field==true ? "Details" : "" %>
<%= doc_presenter.test_field %>

<%= doc_presenter.type_arr==true ? "Details" : "" %>
<% doc_presenter.each_secondary_field do |field_name, field, field_presenter| %>
<%= render "show_fields", document: document, field: field, field_name: field_name, field_presenter: field_presenter %>
<% end -%>

0 comments on commit 9af7b70

Please sign in to comment.