diff --git a/app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb b/app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb new file mode 100644 index 0000000000..90ff31c447 --- /dev/null +++ b/app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb @@ -0,0 +1,25 @@ +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 + nil + end + if parsed_uri.nil? + ERB::Util.h(value) + else + %(#{Hyrax.config.rights_statement_service_class.new.label(value)}) + end + end + end + end +end diff --git a/app/views/hyrax/base/_attribute_rows.html.erb b/app/views/hyrax/base/_attribute_rows.html.erb index ea388a6a13..fbc1a81cb2 100644 --- a/app/views/hyrax/base/_attribute_rows.html.erb +++ b/app/views/hyrax/base/_attribute_rows.html.erb @@ -10,4 +10,4 @@ <%= presenter.attribute_to_html(:related_url, render_as: :external_link) %> <%= presenter.attribute_to_html(:resource_type, render_as: :faceted) %> <%= presenter.attribute_to_html(:source) %> -<%= presenter.attribute_to_html(:rights_statement) %> +<%= presenter.attribute_to_html(:rights_statement, render_as: :rights_statement) %> diff --git a/lib/hyrax/configuration.rb b/lib/hyrax/configuration.rb index f70506c96b..99abdf4a68 100644 --- a/lib/hyrax/configuration.rb +++ b/lib/hyrax/configuration.rb @@ -228,6 +228,17 @@ def license_service_class @license_service_class ||= Hyrax::LicenseService end + # A configuration point for changing the behavior of the rights statement service. + # + # @!attribute [w] license_service_class + # A configuration point for changing the behavior of the license service. + # + # @see Hyrax::RightsStatementService for implementation details + attr_writer :rights_statement_service_class + def rights_statement_service_class + @rights_statement_service_class ||= Hyrax::RightsStatementService + end + attr_writer :banner_image def banner_image # This image can be used for free and without attribution. See here for source and license: https://github.com/samvera/hyrax/issues/1551#issuecomment-326624909 diff --git a/spec/lib/hyrax/configuration_spec.rb b/spec/lib/hyrax/configuration_spec.rb index 1f974b81b0..d6e7d4ad22 100644 --- a/spec/lib/hyrax/configuration_spec.rb +++ b/spec/lib/hyrax/configuration_spec.rb @@ -43,6 +43,8 @@ it { is_expected.to respond_to(:google_analytics_id?) } it { is_expected.to respond_to(:google_analytics_id) } it { is_expected.to respond_to(:libreoffice_path) } + it { is_expected.to respond_to(:license_service_class) } + it { is_expected.to respond_to(:license_service_class=) } it { is_expected.to respond_to(:max_days_between_fixity_checks=) } it { is_expected.to respond_to(:max_days_between_fixity_checks) } it { is_expected.to respond_to(:max_notifications_for_dashboard) } @@ -52,6 +54,8 @@ it { is_expected.to respond_to(:persistent_hostpath) } it { is_expected.to respond_to(:realtime_notifications?) } it { is_expected.to respond_to(:realtime_notifications=) } + it { is_expected.to respond_to(:rights_statement_service_class) } + it { is_expected.to respond_to(:rights_statement_service_class=) } it { is_expected.to respond_to(:redis_namespace) } it { is_expected.to respond_to(:subject_prefix) } it { is_expected.to respond_to(:translate_id_to_uri) } diff --git a/spec/renderers/hyrax/renderers/rights_statement_attribute_renderer_spec.rb b/spec/renderers/hyrax/renderers/rights_statement_attribute_renderer_spec.rb new file mode 100644 index 0000000000..7865f4e541 --- /dev/null +++ b/spec/renderers/hyrax/renderers/rights_statement_attribute_renderer_spec.rb @@ -0,0 +1,20 @@ +RSpec.describe Hyrax::Renderers::RightsStatementAttributeRenderer do + let(:field) { :rights_statement } + let(:renderer) { described_class.new(field, ['http://rightsstatements.org/vocab/InC/1.0/']) } + + describe "#attribute_to_html" do + subject { Nokogiri::HTML(renderer.render) } + + let(:expected) { Nokogiri::HTML(tr_content) } + + let(:tr_content) do + "