Module: CitationsHelper

Defined in:
app/helpers/citations_helper.rb

Instance Method Summary collapse

Instance Method Details



83
84
85
86
87
# File 'app/helpers/citations_helper.rb', line 83

def add_citation_link(object: nil, attribute: nil)
  link_to('Add citation', new_citation_path(citation: {
    citation_object_type: object.class.base_class.name,
    citation_object_id: object.id})) if object.has_citations?
end

#attributes_for_citation_object(citation) ⇒ Object



99
100
101
# File 'app/helpers/citations_helper.rb', line 99

def attributes_for_citation_object(citation)
  render
end

#citation_annotation_tag(citation) ⇒ Object



60
61
62
# File 'app/helpers/citations_helper.rb', line 60

def citation_annotation_tag(citation)
  (:span, citation_source_body(citation), class: [:annotation__citation])
end


74
75
76
77
# File 'app/helpers/citations_helper.rb', line 74

def citation_link(citation)
  return nil if citation.nil?
  link_to(citation_tag(citation).html_safe, citation.citation_object.metamorphosize)
end

#citation_list_tag(object) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'app/helpers/citations_helper.rb', line 64

def citation_list_tag(object)
  return nil unless object.has_citations? && object.citations.any?
  (:h3, 'Citations') +
    (:ul, class: 'annotations__citation_list') do
      object.citations.collect{|t|
        (:li, citation_annotation_tag(t))
      }.join.html_safe
    end
end

#citation_source_body(citation) ⇒ String

Returns Author year, pages, topics presently contains HTML.

Returns:

  • (String)

    Author year, pages, topics presently contains HTML



16
17
18
19
20
21
# File 'app/helpers/citations_helper.rb', line 16

def citation_source_body(citation)
  [
    [source_author_year_tag(citation.source) + citation.source.year_suffix.to_s, citation.pages].compact.join(':'),
    citation_topics_tag(citation)
  ].compact.join(' ').html_safe
end

#citation_source_body_label(citation) ⇒ Object

Author year, pages, topics

presently contains HTML


26
27
28
29
30
31
32
# File 'app/helpers/citations_helper.rb', line 26

def citation_source_body_label(citation)
  [
    [source_author_year_label(citation.source) + citation.source.year_suffix.to_s,
     citation.pages].compact.join(':'),
    citation_topics_label(citation)
  ].compact.join(' ')
end

#citation_tag(citation) ⇒ Object



3
4
5
6
# File 'app/helpers/citations_helper.rb', line 3

def citation_tag(citation)
  return nil if citation.nil?
  [citation.citation_object.class.name, ': ', object_tag(citation.citation_object&.metamorphosize), ' in ', citation_source_body(citation)].compact.join.html_safe
end

#citation_topics_label(citation) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/citations_helper.rb', line 34

def citation_topics_label(citation)
  return nil unless citation.topics.any?
  [
    '[',
    citation.citation_topics.collect{|ct|
      label_for_controlled_vocabulary_term(ct.topic.metamorphosize) + (!ct.pages.blank? ? ": #{ct.pages}" : '')
    }.compact.join(', '),
    ']'
  ].join
end

#citation_topics_tag(citation) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/citations_helper.rb', line 45

def citation_topics_tag(citation)
  return nil unless citation.topics.any?
  [
    '[',
    citation.citation_topics.collect{|ct|
      (:span, (controlled_vocabulary_term_tag(ct.topic.metamorphosize) + (!ct.pages.blank? ? ": #{ct.pages}" : '')), class: [:annotation__citation_topic])
    }.compact.join(', '),
    ']'
  ].join.html_safe
end

#citations_recent_objects_partialTrue

Returns indicates a custom partial should be used, see list_helper.rb.

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



95
96
97
# File 'app/helpers/citations_helper.rb', line 95

def citations_recent_objects_partial
  true
end

#citations_search_formObject



79
80
81
# File 'app/helpers/citations_helper.rb', line 79

def citations_search_form
  render('/citations/quick_search_form')
end

#citations_tag(object) ⇒ Object



56
57
58
# File 'app/helpers/citations_helper.rb', line 56

def citations_tag(object)
  object.citations.collect{|c| [source_author_year_tag(c.source) + c.source.year_suffix.to_s, c.pages].compact.join(': ')}.to_sentence
end


89
90
91
# File 'app/helpers/citations_helper.rb', line 89

def edit_citation_link(citation)
  edit_object_link(citation)
end

#label_for_citation(citation) ⇒ Object



8
9
10
11
# File 'app/helpers/citations_helper.rb', line 8

def label_for_citation(citation)
  return nil if citation.nil?
  [citation.citation_object.class.name, ': ', label_for(citation.citation_object&.metamorphosize), ' in ', citation_source_body_label(citation)].compact.join.html_safe
end

#quick_citation_tag(source_id, object, klass = nil) ⇒ Object



103
104
105
# File 'app/helpers/citations_helper.rb', line 103

def quick_citation_tag(source_id, object, klass = nil)
  (:span, 'Cite', data: {source_id: source_id, global_id: object.to_global_id.to_s, quick_citation: true}, class: klass)
end