-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a rights_statement renderer to render the statement text rather t…
…han the URL
- Loading branch information
Julie Allinson
committed
Oct 11, 2017
1 parent
ec97667
commit cf947a5
Showing
6 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
app/renderers/hyrax/renderers/rights_statement_attribute_renderer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
%(<a href=#{ERB::Util.h(value)} target="_blank">#{Hyrax.config.rights_statement_service_class.new.label(value)}</a>) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
spec/renderers/hyrax/renderers/rights_statement_attribute_renderer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
"<tr><th>Rights statement</th>\n" \ | ||
"<td><ul class='tabular'>" \ | ||
"<li class=\"attribute rights_statement\"><a href=\"http://rightsstatements.org/vocab/InC/1.0/\" target=\"_blank\">In Copyright</a></li>" \ | ||
"</ul></td></tr>" | ||
end | ||
|
||
it { expect(renderer).not_to be_microdata(field) } | ||
it { expect(subject).to be_equivalent_to(expected) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters