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)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Author year, pages, topics presently contains HTML. 
- 
  
    
      #citation_source_body_label(citation)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Author year, pages, topics presently contains HTML. 
- #citation_tag(citation) ⇒ Object
- #citation_topics_label(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
- #label_for_citation(citation) ⇒ Object
- #quick_citation_tag(source_id, object, klass = nil) ⇒ Object
Instance Method Details
#add_citation_link(object: nil, attribute: nil) ⇒ Object
| 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) content_tag(:span, citation_source_body(citation), class: [:annotation__citation]) end | 
#citation_link(citation) ⇒ Object
| 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.) 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? 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) ⇒ String
Returns 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) [ [(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) [ [(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&.), ' 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.) + (!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| 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.
| 95 96 97 | # File 'app/helpers/citations_helper.rb', line 95 def citations_recent_objects_partial true end | 
#citations_search_form ⇒ Object
| 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| [(c.source) + c.source.year_suffix.to_s, c.pages].compact.join(': ')}.to_sentence end | 
#edit_citation_link(citation) ⇒ Object
| 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&.), ' 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) content_tag(:span, 'Cite', data: {source_id: source_id, global_id: object.to_global_id.to_s, quick_citation: true}, class: klass) end |