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.
9 10 11 12 13 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 9 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.
15 16 17 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 15 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 15 def @options end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
15 16 17 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 15 def view_context @view_context end |
Instance Method Details
#href(format) ⇒ Object
31 32 33 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 31 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.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/presenters/blacklight/link_alternate_presenter.rb', line 19 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 |