Module: AttributionsHelper
- Defined in:
- app/helpers/attributions_helper.rb
Instance Method Summary collapse
- #attribution_copyright_label(attribution) ⇒ String?
- #attribution_copyright_tag(attribution) ⇒ Object
- #attribution_creators_tag(attribution) ⇒ Object
- #attribution_editors_tag(attribution) ⇒ Object
- #attribution_license_tag(attribution) ⇒ Object
-
#attribution_list_tag(object) ⇒ String (html)?
A ul/li of tags for the object.
- #attribution_nexml_label(attribution) ⇒ Object
- #attribution_owners_tag(attribution) ⇒ Object
- #attribution_tag(attribution) ⇒ Object
-
#attribution_to_json(attribution) ⇒ Object
An attempt at a Human readable simplified response suitable for JSON API responses.
- #copyright_agents(attribution) ⇒ Object
-
#label_for_attribution(attribution) ⇒ String?
!! if _tag labels add HTML then they must be removed here.
Instance Method Details
#attribution_copyright_label(attribution) ⇒ String?
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/attributions_helper.rb', line 50 def attribution_copyright_label(attribution) a = attribution.copyright_year b = copyright_agents(attribution) return nil unless a or b.any? s = '©' s << [a, Utilities::Strings.(b.collect{|c| c.name})].compact.join(' ') s end |
#attribution_copyright_tag(attribution) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/attributions_helper.rb', line 60 def attribution_copyright_tag(attribution) a = attribution.copyright_year b = copyright_agents(attribution) return nil unless a or b.any? s = '©' s << [a, Utilities::Strings.(b.collect{|c| c.name})].compact.join(' ') s.html_safe end |
#attribution_creators_tag(attribution) ⇒ Object
76 77 78 79 80 |
# File 'app/helpers/attributions_helper.rb', line 76 def attribution_creators_tag(attribution) a = attribution.creator_roles.eager_load(:organization, :person).collect{|b| b.agent} return nil unless a.any? ('Created by ' + Utilities::Strings.(a.collect{|b| b.name})).html_safe end |
#attribution_editors_tag(attribution) ⇒ Object
82 83 84 85 86 |
# File 'app/helpers/attributions_helper.rb', line 82 def attribution_editors_tag(attribution) a = attribution.editor_roles.eager_load(:organization, :person).collect{|b| b.agent} return nil unless a.any? ('Edited by ' + Utilities::Strings.(a.collect{|b| b.name})).html_safe end |
#attribution_license_tag(attribution) ⇒ Object
33 34 35 36 |
# File 'app/helpers/attributions_helper.rb', line 33 def attribution_license_tag(attribution) return nil if attribution.nil? || attribution.license.blank? 'License: ' + CREATIVE_COMMONS_LICENSES[attribution.license][:name] end |
#attribution_list_tag(object) ⇒ String (html)?
Returns a ul/li of tags for the object.
96 97 98 99 100 |
# File 'app/helpers/attributions_helper.rb', line 96 def attribution_list_tag(object) return nil unless object.has_attribution? && object.attribution content_tag(:h3, 'Attribution') + attribution_tag(object.attribution) end |
#attribution_nexml_label(attribution) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/attributions_helper.rb', line 38 def attribution_nexml_label(attribution) return nil if attribution.nil? a = [ attribution_creators_tag(attribution), attribution_owners_tag(attribution), attribution.copyright_year ] a.compact.join(', ').html_safe end |
#attribution_owners_tag(attribution) ⇒ Object
88 89 90 91 92 |
# File 'app/helpers/attributions_helper.rb', line 88 def attribution_owners_tag(attribution) a = attribution.owner_roles.eager_load(:organization, :person).collect{|b| b.agent} return nil unless a.any? ('Owned by ' + Utilities::Strings.(a.collect{|b| b.name})).html_safe end |
#attribution_tag(attribution) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/attributions_helper.rb', line 3 def attribution_tag(attribution) return nil if attribution.nil? a = [ attribution_copyright_tag(attribution), attribution_creators_tag(attribution), attribution_editors_tag(attribution), attribution_owners_tag(attribution), attribution_license_tag(attribution), ] a.compact.join('. ').html_safe end |
#attribution_to_json(attribution) ⇒ Object
An attempt at a Human readable simplified response suitable for JSON API responses.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/attributions_helper.rb', line 104 def attribution_to_json(attribution) return nil if attribution.nil? a = attribution h = a.attributes.select{|k,v| %w{copyright_year license}.include?(k)} if a.roles.load.any? ::Attribution::ATTRIBUTION_ROLES.each do |r| role = "#{r}_roles" h[r] = [] if a.send(role).any? a.send(role).order('roles.position ASC').each do |role| b = { agent_type: role.agent_type } case role.agent_type when :person b.merge!({ name: role.person.cached, orcid: role.person.orcid, wikidata_id: role.person.wikidata_id }) when :organization b.merge! role.organization.attributes.select{|k,v| %w{ name alternate_name description disambiguating_description address email telephone duns global_location_number legal_name copyright_year license}.include?(k)} end h[r].push b.select{|c,d| !d.nil?} end end end end h end |
#copyright_agents(attribution) ⇒ Object
70 71 72 73 |
# File 'app/helpers/attributions_helper.rb', line 70 def copyright_agents(attribution) return [] if attribution.blank? attribution.copyright_holder_roles.eager_load(:organization, :person).collect{|b| b.agent} end |
#label_for_attribution(attribution) ⇒ String?
!! if _tag labels add HTML then they must be removed here
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/attributions_helper.rb', line 19 def label_for_attribution(attribution) return nil if attribution.nil? a = [ attribution_copyright_label(attribution), attribution_creators_tag(attribution), attribution_editors_tag(attribution), attribution_owners_tag(attribution), attribution_license_tag(attribution), ] a.compact.join('. ').html_safe end |