Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dassie/config/metadata_profiles/m3_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ properties:
sample_values:
- http://creativecommons.org/licenses/by/3.0/us/
view:
render_as: external_link
render_as: license
html_dl: true
abstract:
available_on:
Expand Down
2 changes: 1 addition & 1 deletion .koppie/config/metadata_profiles/m3_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ properties:
sample_values:
- http://creativecommons.org/licenses/by/3.0/us/
view:
render_as: external_link
render_as: license
html_dl: true
abstract:
available_on:
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/hyrax/attributes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def conform_field(field_name, options_hash)
options_hash&.with_indifferent_access&.fetch('render_term', nil) || field_name
end

# Authority-backed fields whose values are URIs with human-readable
# labels. Their semantic renderers always win over a profile-supplied
# render_as: the label still links to the URI, so rendering the bare
# URI (e.g. as an external_link) is strictly worse, and profiles
# already stored in existing flexible schemas carry the old setting.
SEMANTIC_RENDERERS = {
license: :license,
rights_statement: :rights_statement
}.freeze

# @param [String] field name
# @param [Hash<Hash>] a nested hash of view options...
# {:label=>{"en"=>"Title", "es"=>"Título"}, :html_dl=>true}
Expand All @@ -88,6 +98,8 @@ def conform_options(field_name, view_options)
)
end
view_options[:base_url] = request.base_url if respond_to?(:request) && request.respond_to?(:base_url)
semantic_renderer = SEMANTIC_RENDERERS[field_name.to_sym]
view_options[:render_as] = semantic_renderer if semantic_renderer
view_options
end

Expand Down
2 changes: 1 addition & 1 deletion config/metadata_profiles/m3_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ properties:
sample_values:
- http://creativecommons.org/licenses/by/3.0/us/
view:
render_as: external_link
render_as: license
html_dl: true
abstract:
available_on:
Expand Down
23 changes: 23 additions & 0 deletions spec/helpers/hyrax/attributes_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@
result = helper.conform_options(:date_created, {}.with_indifferent_access)
expect(result[:label]).to eq('Date created')
end

it 'applies the semantic renderer for license' do
result = helper.conform_options(:license, {}.with_indifferent_access)
expect(result[:render_as]).to eq(:license)
end

it 'applies the semantic renderer for rights_statement' do
result = helper.conform_options(:rights_statement, {}.with_indifferent_access)
expect(result[:render_as]).to eq(:rights_statement)
end

it 'overrides a stored external_link for license' do
# Flexible schemas seeded from earlier profiles carry
# render_as: external_link for license; the authority label must win
# anyway - it still links to the URI, and a bare URI is strictly worse.
result = helper.conform_options(:license, { render_as: 'external_link' }.with_indifferent_access)
expect(result[:render_as]).to eq(:license)
end

it 'leaves fields without a semantic renderer alone' do
result = helper.conform_options(:related_url, { render_as: 'external_link' }.with_indifferent_access)
expect(result[:render_as]).to eq('external_link')
end
Comment thread
ShanaLMoore marked this conversation as resolved.
end

describe '#schema' do
Expand Down
Loading