Module: Hyrax::AuthorityRenderingHelper

Defined in:
app/services/hyrax/authority_rendering_helper.rb

Overview

Shared rendering helpers for authority-backed values that may have been stored as either a real URI or as free text (the M3 metadata profile, plus bulk importers such as Bulkrax and Willow Sword, can both produce free-text values that the UI's authority dropdown did not constrain).

Constant Summary collapse

LINKABLE_URI_SCHEMES =

Schemes considered safe to emit in an <a href>. Anything else (notably javascript:, data:, custom schemes, or non-absolute strings like "moomin") is rendered as plain text so it cannot be activated as a link.

%w[http https].freeze

Class Method Summary collapse

Class Method Details

.linkable_uri?(value) ⇒ Boolean

Returns true when the value parses as an absolute URI with an allowed scheme, suitable to use as an anchor's href.

Parameters:

  • value (String, nil)

Returns:

  • (Boolean)

    true when the value parses as an absolute URI with an allowed scheme, suitable to use as an anchor's href.



19
20
21
22
23
24
25
26
# File 'app/services/hyrax/authority_rendering_helper.rb', line 19

def linkable_uri?(value)
  return false if value.blank?

  parsed = URI.parse(value)
  parsed.absolute? && LINKABLE_URI_SCHEMES.include?(parsed.scheme&.downcase)
rescue URI::InvalidURIError
  false
end