Module: CitationsHelper
- Defined in:
- app/helpers/citations_helper.rb
Instance Method Summary collapse
- #add_citation_link(object: nil, attribute: nil) ⇒ Object
- #attributes_for_citation_object(citation) ⇒ Object
- #citation_annotation_tag(citation) ⇒ Object
- #citation_link(citation) ⇒ Object
- #citation_list_tag(object) ⇒ Object
- #citation_source_body(citation) ⇒ Object
- #citation_tag(citation) ⇒ Object
- #citation_topics_tag(citation) ⇒ Object
-
#citations_recent_objects_partial ⇒ True
Indicates a custom partial should be used, see list_helper.rb.
- #citations_search_form ⇒ Object
- #citations_tag(object) ⇒ Object
- #edit_citation_link(citation) ⇒ Object
- #quick_citation_tag(source_id, object, klass = nil) ⇒ Object
Instance Method Details
#add_citation_link(object: nil, attribute: nil) ⇒ Object
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) content_tag(:span, citation_source_body(citation), class: [:annotation__citation]) end |
#citation_link(citation) ⇒ Object
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.) 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? content_tag(:h3, 'Citations') + content_tag(:ul, class: 'annotations__citation_list') do object.citations.collect{|t| content_tag(: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? [[(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 = (citation.source) [citation.citation_object.class.name, ': ', object_tag(citation.citation_object&.), ' 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| content_tag(:span, (controlled_vocabulary_term_tag(ct.topic.) + (!ct.pages.blank? ? ": #{ct.pages}" : '')), class: [:annotation__citation_topic]) }.compact.join(', '), ']' ].join.html_safe end |
#citations_recent_objects_partial ⇒ True
Returns 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_form ⇒ Object
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| [(c.source) + c.source.year_suffix.to_s, c.pages].compact.join(': ')}.to_sentence end |
#edit_citation_link(citation) ⇒ Object
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) content_tag(:span, 'Cite', data: {source_id: source_id, global_id: object.to_global_id.to_s, quick_citation: true}, class: klass) end |