Class: Blacklight::LinkAlternatePresenter
- Inherits:
-
Object
- Object
- Blacklight::LinkAlternatePresenter
- Includes:
- ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
- Defined in:
- app/presenters/blacklight/link_alternate_presenter.rb
Overview
Create <link rel=“alternate”> links from a documents dynamically
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #href(format) ⇒ Object
-
#initialize(view_context, document, options) ⇒ LinkAlternatePresenter
constructor
A new instance of LinkAlternatePresenter.
-
#render ⇒ Object
Renders links to alternate representations provided by export formats.
Constructor Details
#initialize(view_context, document, options) ⇒ LinkAlternatePresenter
Returns a new instance of LinkAlternatePresenter.
7 8 9 10 11 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 7 def initialize(view_context, document, ) @view_context = view_context @document = document @options = { unique: false, exclude: [] }.merge() end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
13 14 15 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 13 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 13 def @options end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
13 14 15 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 13 def view_context @view_context end |
Instance Method Details
#href(format) ⇒ Object
29 30 31 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 29 def href(format) view_context.polymorphic_url(view_context.search_state.url_for_document(document), format: format) end |
#render ⇒ Object
Renders links to alternate representations provided by export formats. Returns empty string if no links available.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 17 def render seen = Set.new safe_join(document.export_formats.map do |format, spec| next if [:exclude].include?(format) || ([:unique] && seen.include?(spec[:content_type])) seen.add(spec[:content_type]) tag(:link, rel: "alternate", title: format, type: spec[:content_type], href: href(format)) end.compact, "\n") end |