Module: AttributionsHelper

Defined in:
app/helpers/attributions_helper.rb

Instance Method Summary collapse

Instance Method Details

Returns:

  • (String, nil)


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.authorship_sentence(b.collect{|c| c.name})].compact.join(' ')
  s
end


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.authorship_sentence(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.authorship_sentence(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.authorship_sentence(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.

Returns:

  • (String (html), nil)

    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
  (: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.authorship_sentence(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


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

Returns:

  • (String, nil)

    no html in _label



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