Module: TaxonNamesHelper

Defined in:
app/helpers/taxon_names_helper.rb

Instance Method Summary (collapse)

Instance Method Details



144
145
146
147
148
149
# File 'app/helpers/taxon_names_helper.rb', line 144

def ancestor_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Up'
  taxon_name.ancestors.any? ? 
    link_to((:span, text, data: {icon: 'arrow-up'}, class: 'small-icon'), send(path,taxon_name.ancestors.first.metamorphosize), class: 'navigation-item', data: {arrow: 'ancestor'}) :
    (:div, (:span, text, class: 'small-icon', data: {icon: 'arrow-up'}), class: 'navigation-item disable')
end

- (Object) cached_classified_as_tag(taxon_name)



66
67
68
# File 'app/helpers/taxon_names_helper.rb', line 66

def cached_classified_as_tag(taxon_name)
  taxon_name.cached_classified_as ? taxon_name.cached_classified_as.strip.html_safe : ''
end

- (Object) current_author_year(taxon_name)



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

def current_author_year(taxon_name)
  return nil if taxon_name.nil? || taxon_name.cached_author_year.nil?
  taxon_name.cached_author_year
end


151
152
153
154
155
156
# File 'app/helpers/taxon_names_helper.rb', line 151

def descendant_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Down'
  taxon_name.descendants.any? ? 
    link_to((:span, text, data: {icon: 'arrow-down'}, class: 'small-icon'), send(path, taxon_name.descendants.first.metamorphosize), class: 'navigation-item', data: {arrow: 'descendant'}) : 
    (:div, (:span, text, class: 'small-icon', data: {icon: 'arrow-down'}), class: 'navigation-item disable') 
end


108
109
110
# File 'app/helpers/taxon_names_helper.rb', line 108

def edit_original_combination_task_link(taxon_name)
  link_to('Edit original combination', edit_protonym_original_combination_task_path(taxon_name)) if GENUS_AND_SPECIES_RANK_NAMES.include?(taxon_name.rank_string)
end


123
124
125
126
127
128
129
# File 'app/helpers/taxon_names_helper.rb', line 123

def edit_taxon_name_link(taxon_name)
  if taxon_name.type == 'Protonym'
    link_to((:span, 'Edit', 'data-icon' => 'edit', 'class' => 'small-icon'), edit_taxon_name_path(taxon_name.metamorphosize), 'class' => 'navigation-item')
  else
    link_to((:span, 'Edit', 'data-icon' => 'edit', 'class' => 'small-icon'), edit_combination_path(taxon_name), 'class' => 'navigation-item')
  end
end

- (Object) edit_taxon_name_path_string(taxon_name)

See #edit_object_path_string in navigation_helper.rb



113
114
115
116
117
118
119
120
121
# File 'app/helpers/taxon_names_helper.rb', line 113

def edit_taxon_name_path_string(taxon_name)
  if taxon_name.type == 'Protonym'
    'edit_taxon_name_path'
  elsif taxon_name.type == 'Combination'
    'edit_combination_path' 
  else
    nil 
  end
end

- (String the name in original combiantion, ...) full_original_taxon_name_tag(taxon_name)

Returns String the name in original combiantion, with author year, and HTML

Returns:

  • (String the name in original combiantion, with author year, and HTML)

    String the name in original combiantion, with author year, and HTML



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

def full_original_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  [
    original_taxon_name_tag(taxon_name), 
    history_author_year_tag(taxon_name)
  ].compact.join(" ").html_safe
end

- (String) full_taxon_name_tag(taxon_name)

Returns the current name/combination with author year, and HTML

Returns:

  • (String)

    the current name/combination with author year, and HTML



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

def full_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  [taxon_name_tag(taxon_name), taxon_name.cached_author_year].compact.join(" ").html_safe
end


158
159
160
161
162
163
164
165
# File 'app/helpers/taxon_names_helper.rb', line 158

def next_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Next'
  link_object = taxon_name.next_sibling

  link_object.nil? ? 
    (:div, (:span, text, class: 'small-icon icon-right', data: {icon: 'arrow-right'}), class:  'navigation-item disable') : 
    link_to((:span, text, data: {icon: 'arrow-right'}, class: 'small-icon icon-right'), send(path, link_object.metamorphosize), class: 'navigation-item', data: {arrow: 'next'})
end

- (Object) original_author_year(taxon_name)



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

def original_author_year(taxon_name)
  return nil if taxon_name.nil? || taxon_name.cached_author_year.nil?
  taxon_name.cached_author_year.gsub(/^\(|\)$/, '')
end


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

def original_taxon_name_link(taxon_name)
  return nil if taxon_name.nil?
  link_to(original_taxon_name_tag(taxon_name).html_safe, browse_nomenclature_task_path(taxon_name))
end

- (String) original_taxon_name_tag(taxon_name)

Returns the taxon name in original combination, without author year, with HTML

Returns:

  • (String)

    the taxon name in original combination, without author year, with HTML



21
22
23
24
# File 'app/helpers/taxon_names_helper.rb', line 21

def original_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  taxon_name.cached_original_combination.nil? ? taxon_name.cached_html.html_safe || taxon_name.name : taxon_name.cached_original_combination.html_safe
end

- (Object) parent_taxon_name_for_select(taxon_name)

@taxon_name.parent.andand.display_name(:type => :for_select_list)



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

def parent_taxon_name_for_select(taxon_name)
  taxon_name.parent ? taxon_name_for_select(taxon_name.parent) : nil
end


167
168
169
170
171
172
173
174
# File 'app/helpers/taxon_names_helper.rb', line 167

def previous_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Previous'
  link_object = taxon_name.previous_sibling

  link_object.nil? ? 
    (:div, (:span, text, class: 'small-icon', data: {icon: 'arrow-left'}), class: 'navigation-item disable') : 
    link_to((:span, text, data: {icon: 'arrow-left'}, class: 'small-icon'), send(path, link_object.metamorphosize), class: 'navigation-item', data: {arrow: 'back'})
end

- (Object) rank_tag(taxon_name)



131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/taxon_names_helper.rb', line 131

def rank_tag(taxon_name)
  case taxon_name.type
  when 'Protonym'
    if taxon_name.rank_class
      taxon_name.rank.downcase
    else
      (:em, 'ERROR')
    end
  when 'Combination'
    (:em, 'n/a')
  end
end

- (String) taxon_name_autocomplete_selected_tag(taxon_name)

Returns no HTML inside <input>

Returns:

  • (String)

    no HTML inside <input>



14
15
16
17
# File 'app/helpers/taxon_names_helper.rb', line 14

def taxon_name_autocomplete_selected_tag(taxon_name)
  return nil if taxon_name.nil?
  [taxon_name.cached, taxon_name.cached_author_year].compact.join(' ') 
end


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

def taxon_name_browse_link(taxon_name)
  return nil if taxon_name.nil?
  [ link_to(taxon_name_tag(taxon_name), browse_nomenclature_task_path(taxon_name.metamorphosize)).html_safe,  taxon_name.cached_author_year].compact.join(' ').html_safe
end

- (Object) taxon_name_for_select(taxon_name)



94
95
96
# File 'app/helpers/taxon_names_helper.rb', line 94

def taxon_name_for_select(taxon_name)
  taxon_name.name if taxon_name
end

- (Object) taxon_name_gender_sentence_tag(taxon_name)



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

def taxon_name_gender_sentence_tag(taxon_name)
  return nil if taxon_name.nil?
  "The name is #{taxon_name.gender_name}." if taxon_name.gender_name
end

- (Object) taxon_name_latinization_tag(taxon_name)



70
71
72
73
# File 'app/helpers/taxon_names_helper.rb', line 70

def taxon_name_latinization_tag(taxon_name)
  list = taxon_name.taxon_name_classifications.with_type_array(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES).map(&:classification_label)
  (:span,  "The word \"#{taxon_name.name}\" has the following Latin-based classifications: #{list.to_sentence}.", class: 'history__latinized_classifications') if list.any?
end


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

def taxon_name_link(taxon_name)
  return nil if taxon_name.nil?
  link_to(taxon_name_tag(taxon_name), taxon_name.metamorphosize).html_safe
end

- (Object) taxon_name_rank_select_tag(taxon_name: TaxonName.new, code: nil)

TODO: Scope to code



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

def taxon_name_rank_select_tag(taxon_name: TaxonName.new, code:  nil)
  select(:taxon_name, :rank_class, options_for_select(RANKS_SELECT_OPTIONS, selected: taxon_name.rank_string) ) 
end

- (Object) taxon_name_short_status(taxon_name)



53
54
55
56
57
58
59
# File 'app/helpers/taxon_names_helper.rb', line 53

def taxon_name_short_status(taxon_name)
  if taxon_name.unavailable_or_invalid?
    (:span, 'This name is not valid/accepted.', class: :brief_status, data: {icon: :attention}) 
  else
    (:span, 'This name is valid/accepted.', class: :brief_status, data: {icon: :ok }) 
  end
end

- (String) taxon_name_tag(taxon_name)

Returns the taxon name without author year, with HTML

Returns:

  • (String)

    the taxon name without author year, with HTML



5
6
7
8
9
10
# File 'app/helpers/taxon_names_helper.rb', line 5

def taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  return taxon_name.name if taxon_name.new_record?
  # TODO: fix generation of empty string cached author year
  taxon_name.cached_html.html_safe || taxon_name.name.html_safe
end

- (Object) taxon_names_search_form



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

def taxon_names_search_form
  render '/taxon_names/quick_search_form'
end