Module: DocumentHelper
- Defined in:
- app/helpers/document_helper.rb
Overview
DocumentHelper
Instance Method Summary collapse
- #blacklight_link(document) ⇒ Object
- #link_from_api(link) ⇒ Object
- #localize_link(link) ⇒ Object
- #next_link(links) ⇒ Object
- #previous_link(links) ⇒ Object
- #publication_state_badge(document) ⇒ Object
- #sort_link(link) ⇒ Object
Instance Method Details
#blacklight_link(document) ⇒ Object
57 58 59 |
# File 'app/helpers/document_helper.rb', line 57 def blacklight_link(document) "#{BLACKLIGHT_URL}/catalog/#{document.friendlier_id}" end |
#link_from_api(link) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/document_helper.rb', line 31 def link_from_api(link) # Append facet - Full URI returned uri = URI.parse(link["links"]["self"]) {action: "add", link: "/admin/documents?#{uri.query}"} rescue # Remove facet - Only path and query returned uri = URI.parse(link["links"]["remove"]) {action: "remove", link: "/admin/documents?#{uri.query}"} end |
#localize_link(link) ⇒ Object
22 23 24 25 |
# File 'app/helpers/document_helper.rb', line 22 def localize_link(link) uri = URI.parse(link) "/admin/documents?#{uri.query}" end |
#next_link(links) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/helpers/document_helper.rb', line 49 def next_link(links) if links["next"] link_to "Next", localize_link(links["next"]), {class: "btn btn-outline-primary btn-sm"} else link_to "Next", "javascript:;", {class: "btn btn-outline-primary btn-sm disabled", "aria-disabled": true} end end |
#previous_link(links) ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/helpers/document_helper.rb', line 41 def previous_link(links) if links["prev"] link_to "Previous", localize_link(links["prev"]), {class: "btn btn-outline-primary btn-sm"} else link_to "Previous", "javascript:;", {class: "btn btn-outline-primary btn-sm disabled", "aria-disabled": true} end end |
#publication_state_badge(document) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/document_helper.rb', line 5 def publication_state_badge(document) case document.publication_state when "draft" link_to("#document_publication_state") do tag.span("Draft", class: "badge badge-secondary") end when "published" link_to("#document_publication_state") do tag.span("Published", class: "badge badge-success") end when "unpublished" link_to("#document_publication_state") do tag.span("Unpublished", class: "badge badge-danger") end end end |
#sort_link(link) ⇒ Object
27 28 29 |
# File 'app/helpers/document_helper.rb', line 27 def sort_link(link) link_to link["attributes"]["label"], localize_link(link["links"]["self"]), {class: "dropdown-item"} end |