Module: CitationsHelper

Defined in:
app/helpers/citations_helper.rb

Instance Method Summary collapse

Instance Method Details



52
53
54
55
56
# File 'app/helpers/citations_helper.rb', line 52

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



68
69
70
# File 'app/helpers/citations_helper.rb', line 68

def attributes_for_citation_object(citation)
  render
end

#citation_annotation_tag(citation) ⇒ Object



29
30
31
# File 'app/helpers/citations_helper.rb', line 29

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


43
44
45
46
# File 'app/helpers/citations_helper.rb', line 43

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



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

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) ⇒ Object



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

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

#citation_tag(citation) ⇒ Object



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

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

#citation_topics_tag(citation) ⇒ Object



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

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



64
65
66
# File 'app/helpers/citations_helper.rb', line 64

def citations_recent_objects_partial
  true
end

#citations_search_formObject



48
49
50
# File 'app/helpers/citations_helper.rb', line 48

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

#citations_tag(object) ⇒ Object



25
26
27
# File 'app/helpers/citations_helper.rb', line 25

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


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

def edit_citation_link(citation)
  edit_object_link(citation)
end

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



72
73
74
# File 'app/helpers/citations_helper.rb', line 72

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