Skip to content

Commit

Permalink
Add #rights_statement_links helper to rights field
Browse files Browse the repository at this point in the history
  • Loading branch information
bmquinn committed May 25, 2016
1 parent 3572c88 commit f00587f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/helpers/sufia/sufia_helper_behavior.rb
Expand Up @@ -122,6 +122,12 @@ def link_to_profile(args)
link_to text, Sufia::Engine.routes.url_helpers.profile_path(user)
end

# @param [Hash] options hash from blacklight passes from helper_method
# invocation. Maps rights URIs to links with labels.
def rights_statement_links(options = {})
options[:value].map { |right| link_to RightsService.label(right), right }.to_sentence.html_safe
end

def link_to_telephone(user = nil)
@user ||= user
link_to @user.telephone, "wtai://wp/mc;#{@user.telephone}" if @user.telephone
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/sufia/templates/catalog_controller.rb
Expand Up @@ -75,7 +75,7 @@ def self.modified_field
config.add_index_field solr_name("date_uploaded", :stored_sortable, type: :date), label: "Date Uploaded", itemprop: 'datePublished', helper_method: :human_readable_date
config.add_index_field solr_name("date_modified", :stored_sortable, type: :date), label: "Date Modified", itemprop: 'dateModified', helper_method: :human_readable_date
config.add_index_field solr_name("date_created", :stored_searchable), label: "Date Created", itemprop: 'dateCreated'
config.add_index_field solr_name("rights", :stored_searchable), label: "Rights"
config.add_index_field solr_name("rights", :stored_searchable), label: "Rights", helper_method: :rights_statement_links
config.add_index_field solr_name("resource_type", :stored_searchable), label: "Resource Type"
config.add_index_field solr_name("format", :stored_searchable), label: "File Format"
config.add_index_field solr_name("identifier", :stored_searchable), label: "Identifier"
Expand Down
16 changes: 16 additions & 0 deletions spec/helpers/sufia_helper_spec.rb
Expand Up @@ -217,4 +217,20 @@ def create_models(model, user1, user2)
expect(subject).to include('class="glyphicon glyphicon-new-window"')
end
end

describe "#rights_statement_links" do
it "maps the url to a link with a label" do
expect(helper.rights_statement_links(
value: ["http://creativecommons.org/publicdomain/zero/1.0/"]
)).to eq("<a href=\"http://creativecommons.org/publicdomain/zero/1.0/\">CC0 1.0 Universal</a>")
end

it "converts multiple rights statements to a sentence" do
expect(helper.rights_statement_links(
value: ["http://creativecommons.org/publicdomain/zero/1.0/",
"http://creativecommons.org/publicdomain/mark/1.0/",
"http://www.europeana.eu/portal/rights/rr-r.html"]
)).to eq("<a href=\"http://creativecommons.org/publicdomain/zero/1.0/\">CC0 1.0 Universal</a>, <a href=\"http://creativecommons.org/publicdomain/mark/1.0/\">Public Domain Mark 1.0</a>, and <a href=\"http://www.europeana.eu/portal/rights/rr-r.html\">All rights reserved</a>")
end
end
end
7 changes: 6 additions & 1 deletion spec/views/catalog/_index_list_default.html.erb_spec.rb
Expand Up @@ -6,7 +6,10 @@
'depositor_tesim' => ['jcoyne@justincoyne.com'],
'proxy_depositor_ssim' => ['atz@stanford.edu'],
'description_tesim' => ['This links to http://example.com/ What about that?'],
'date_uploaded_dtsi' => '2013-03-14T00:00:00Z' }
'date_uploaded_dtsi' => '2013-03-14T00:00:00Z',
'rights_tesim' => ["http://creativecommons.org/publicdomain/zero/1.0/",
"http://creativecommons.org/publicdomain/mark/1.0/",
"http://www.europeana.eu/portal/rights/rr-r.html"] }
end
let(:document) { SolrDocument.new(attributes) }
let(:blacklight_configuration_context) do
Expand Down Expand Up @@ -34,5 +37,7 @@
expect(rendered).to include '<a href="/users/atz@stanford-dot-edu">atz@stanford.edu</a>'
expect(rendered).to include '<span class="attribute-label h4">Owner:</span>'
expect(rendered).to include '<a href="/users/jcoyne@justincoyne-dot-com">jcoyne@justincoyne.com</a>'
expect(rendered).to include '<span class="attribute-label h4">Rights:</span>'
expect(rendered).to include '<a href="http://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0 Universal</a>, <a href="http://creativecommons.org/publicdomain/mark/1.0/">Public Domain Mark 1.0</a>, and <a href="http://www.europeana.eu/portal/rights/rr-r.html">All rights reserved</a>'
end
end

0 comments on commit f00587f

Please sign in to comment.