Module: CitationsHelper

Defined in:
app/helpers/citations_helper.rb

Instance Method Summary collapse

Instance Method Details



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

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



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

def attributes_for_citation_object(citation)
  render
end

#citation_annotation_tag(citation) ⇒ Object



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

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


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

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



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

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



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

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



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

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



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

def citations_recent_objects_partial
  true
end

#citations_search_formObject



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

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

#citations_tag(object) ⇒ Object



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

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


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

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



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

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