Sha256: 4f6909a15848fc1b3817b24b812bba30113a440a57ff9a58cd530e20605390a4

Contents?: true

Size: 983 Bytes

Versions: 29

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  module Renderers
    # This is used by PresentsAttributes to show licenses
    #   e.g.: presenter.attribute_to_html(:rights_statement, render_as: :rights_statement)
    class RightsStatementAttributeRenderer < AttributeRenderer
      private

      ##
      # Special treatment for license/rights.  A URL from the Hyrax gem's config/hyrax.rb is stored in the descMetadata of the
      # curation_concern.  If that URL is valid in form, then it is used as a link.  If it is not valid, it is used as plain text.
      def attribute_value_to_html(value)
        begin
          parsed_uri = URI.parse(value)
        rescue URI::InvalidURIError
          nil
        end
        if parsed_uri.nil?
          ERB::Util.h(value)
        else
          label = Hyrax.config.rights_statement_service_class.new.label(value) { value }
          %(<a href=#{ERB::Util.h(value)} target="_blank">#{label}</a>)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.4 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.3 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.2 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.0 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.0.rc3 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.0.rc2 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-5.0.0.rc1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-3.6.0 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0.rc3 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0.rc2 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0.rc1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-3.5.0 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0.beta2 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-3.4.2 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-4.0.0.beta1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-3.4.1 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
hyrax-3.4.0 app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb