Skip to content

Commit

Permalink
Merge pull request #1320 from jonkerz/replace-hardcoded-taxt-constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkerz committed Jul 23, 2021
2 parents 5b80704 + b2a110e commit 608bdc2
Show file tree
Hide file tree
Showing 38 changed files with 234 additions and 230 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Rake/Desc:

### RSpec.

RSpec/DescribedClass:
Enabled: false

RSpec/EmptyExampleGroup:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion app/decorators/type_name_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def most_recent_before_now_taxon

# TODO: Cheating a lot to quickly make it work on the site and in the AntWeb export at the same time.
def citation_for_by_subsequent_designation_of
"#{Taxt.reference_to_ref_tag(reference)}: #{pages}"
"#{Taxt.ref(reference.id)}: #{pages}"
end
end
2 changes: 1 addition & 1 deletion app/models/history_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def citation_taxt
raise 'not supported' if taxt_type?
return unless reference_id || pages

"#{Taxt.to_ref_tag(reference_id || 'REFERENCE_ID MISSING')}: #{pages || 'PAGES_MISSING'}"
"#{Taxt.ref(reference_id || 'REFERENCE_ID MISSING')}: #{pages || 'PAGES_MISSING'}"
end
alias_method :citation, :citation_taxt

Expand Down
42 changes: 26 additions & 16 deletions app/models/taxt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,38 @@ def reference reference
end
end

module RecordToTag
def taxon_to_tax_tag taxon
"{#{TAX_TAG} #{taxon.id}}"
end
module_function

def protonym_to_pro_tag protonym
"{#{PRO_TAG} #{protonym.id}}"
end
def tax taxon_id
tag TAX_TAG, taxon_id
end

def reference_to_ref_tag reference
"{#{REF_TAG} #{reference.id}}"
end
def taxac taxon_id
tag TAXAC_TAG, taxon_id
end

module_function
def pro protonym_id
tag PRO_TAG, protonym_id
end

extend RecordToTag # Included as a shorthand.
def proac protonym_id
tag PROAC_TAG, protonym_id
end

def prott protonym_id
tag PROTT_TAG, protonym_id
end

def prottac protonym_id
tag PROTTAC_TAG, protonym_id
end

def ref reference_id
tag REF_TAG, reference_id
end

# TODO: DRY w.r.t. `RecordToTag::reference_to_ref_tag`.
def to_ref_tag reference_or_id
reference_id = reference_or_id.is_a?(Reference) ? reference_or_id.id : reference_or_id
"{#{REF_TAG} #{reference_id}}"
def tag tag, content
"{#{tag} #{content}}"
end

# Taxon-related tags.
Expand Down
2 changes: 1 addition & 1 deletion app/services/markdowns/bolton_keys_to_ref_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def replace_with_ref_tags
part.gsub(/(?<bolton_key>.*?):/) do
reference = find_reference $LAST_MATCH_INFO[:bolton_key]
if reference
"{#{Taxt::REF_TAG} #{reference.id}}:"
"#{Taxt.ref(reference.id)}:"
else
"#{Regexp.last_match(1)}: "
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_show/_taxon_description.haml
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,5 @@
.show-on-hover
-if user_is_at_least_helper?
=link_to "Edit", edit_reference_path(reference), class: "btn-tiny btn-normal"
=copy_to_clipboard_button Taxt.reference_to_ref_tag(reference), "ref #{reference.id}"
=copy_to_clipboard_button Taxt.ref(reference.id), "ref #{reference.id}"
=copy_to_clipboard_button reference.id
4 changes: 2 additions & 2 deletions app/views/catalog/_show/logged_in_only/_editors_sidebar.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=taxon.name.epithet_html

.tiny-margin-bottom
=copy_to_clipboard_button Taxt.taxon_to_tax_tag(taxon), "tax #{taxon.id}"
=copy_to_clipboard_button Taxt.tax(taxon.id), "tax #{taxon.id}"
=copy_to_clipboard_button taxon.id

.additional-editor-data.callout.no-border-callout.logged-in-only-background
Expand All @@ -13,7 +13,7 @@
=protonym.decorate.link_to_protonym_epithet

.tiny-margin-bottom
=copy_to_clipboard_button Taxt.protonym_to_pro_tag(protonym), "pro #{protonym.id}"
=copy_to_clipboard_button Taxt.pro(protonym.id), "pro #{protonym.id}"
=copy_to_clipboard_button protonym.id

=render 'protonyms/shared/additional_data_for_editors', protonym: protonym
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/hover_previews/_taxon.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.tiny-margin-bottom
-if user_is_editor?
=link_to "Edit taxon", edit_taxa_path(taxon), class: "btn-tiny btn-normal"
=copy_to_clipboard_button Taxt.taxon_to_tax_tag(taxon), "tax #{taxon.id}"
=copy_to_clipboard_button Taxt.tax(taxon.id), "tax #{taxon.id}"
=copy_to_clipboard_button taxon.id
%strong Taxon:
=decorated_taxon.link_to_taxon_with_author_citation
Expand All @@ -25,7 +25,7 @@
.tiny-margin-bottom
-if user_is_editor?
=link_to "Edit protonym", edit_protonym_path(protonym), class: "btn-tiny btn-normal"
=copy_to_clipboard_button Taxt.protonym_to_pro_tag(protonym), "pro #{protonym.id}"
=copy_to_clipboard_button Taxt.pro(protonym.id), "pro #{protonym.id}"
=copy_to_clipboard_button protonym.id
%strong Protonym:
=decorated_protonym.link_to_protonym
Expand Down
2 changes: 1 addition & 1 deletion app/views/protonyms/hover_previews/_protonym.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.tiny-margin-bottom
-if user_is_at_least_helper?
=link_to "Edit protonym", edit_protonym_path(protonym), class: "btn-tiny btn-normal"
=copy_to_clipboard_button Taxt.protonym_to_pro_tag(protonym), "pro #{protonym.id}"
=copy_to_clipboard_button Taxt.pro(protonym.id), "pro #{protonym.id}"
=copy_to_clipboard_button protonym.id

.div
Expand Down
2 changes: 1 addition & 1 deletion app/views/protonyms/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
=@protonym.name.epithet_html

.tiny-margin-bottom
=copy_to_clipboard_button Taxt.protonym_to_pro_tag(@protonym), "pro #{@protonym.id}"
=copy_to_clipboard_button Taxt.pro(@protonym.id), "pro #{@protonym.id}"
=copy_to_clipboard_button @protonym.id

=render 'protonyms/shared/additional_data_for_editors', protonym: @protonym
Expand Down
2 changes: 1 addition & 1 deletion app/views/references/hover_previews/_reference.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.tiny-margin-bottom
-if user_is_at_least_helper?
=link_to "Edit", edit_reference_path(reference), class: "btn-tiny btn-normal"
=copy_to_clipboard_button Taxt.reference_to_ref_tag(reference), "ref #{reference.id}"
=copy_to_clipboard_button Taxt.ref(reference.id), "ref #{reference.id}"
=copy_to_clipboard_button reference.id

%strong Reference:
Expand Down
2 changes: 1 addition & 1 deletion app/views/references/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
=@reference.key_with_suffixed_year
.small-margin-bottom
=copy_to_clipboard_button Taxt.reference_to_ref_tag(@reference), "ref #{@reference.id}"
=copy_to_clipboard_button Taxt.ref(@reference.id), "ref #{@reference.id}"
=copy_to_clipboard_button @reference.id

.tiny-margin-bottom
Expand Down
28 changes: 14 additions & 14 deletions app/views/shared/_markdown_formatting_help.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
%tr
%td Taxon link
%td
%code {tax 429349}
%td=markdown "{#{Taxt::TAX_TAG} 429349}"
%code=Taxt.tax(429349)
%td=markdown Taxt.tax(429349)
%tr
%td Taxon link (with author citation)
%td
%code {taxac 429349}
%td=markdown "{#{Taxt::TAXAC_TAG} 429349}"
%code=Taxt.taxac(429349)
%td=markdown Taxt.taxac(429349)

%tr
%td Protonym link (full protonym name)
%td
%code {pro 154891}
%td=markdown "{#{Taxt::PRO_TAG} 154891}"
%code=Taxt.pro(154891)
%td=markdown Taxt.pro(154891)
%tr
%td Protonym link (full protonym name, with author citation)
%td
%code {proac 154891}
%td=markdown "{#{Taxt::PROAC_TAG} 154891}"
%code=Taxt.proac(154891)
%td=markdown Taxt.proac(154891)
%tr
%td Terminal taxon link of a protonym
%td
%code {prott 154891}
%td=markdown "{#{Taxt::PROTT_TAG} 154891}"
%code=Taxt.prott(154891)
%td=markdown Taxt.prott(154891)
%tr
%td Terminal taxon link of a protonym (with author citation)
%td
%code {prottac 154891}
%td=markdown "{#{Taxt::PROTTAC_TAG} 154891}"
%code=Taxt.prottac(154891)
%td=markdown Taxt.prottac(154891)

%tr
%td Reference link (expandable)
%td
%code {ref 126902}
%td=markdown "{#{Taxt::REF_TAG} 126902}"
%code=Taxt.ref(126902)
%td=markdown Taxt.ref(126902)

%table.margin-bottom
%caption AntCat-specific markdown (cleanup-related)
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/history_item_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

Given("there is a protonym {string} with a history item {string} and a markdown link to {string}") do |name, content, key_with_year|
reference = ReferenceStepsHelpers.find_reference_by_key(key_with_year)
taxt = "#{content} {#{Taxt::REF_TAG} #{reference.id}}"
taxt = "#{content} #{Taxt.ref(reference.id)}"
step %(there is a subfamily protonym "#{name}" with a history item "#{taxt}")
end

Expand Down
6 changes: 3 additions & 3 deletions features/step_definitions/markdown_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ def markdown_textarea

Then("the markdown textarea should contain a markdown link to {string}") do |key_with_year|
reference = ReferenceStepsHelpers.find_reference_by_key(key_with_year)
expect(markdown_textarea.value).to include "{#{Taxt::REF_TAG} #{reference.id}}"
expect(markdown_textarea.value).to include Taxt.ref(reference.id)
end

When("I fill in {string} with {string} and a markdown link to {string}") do |field_name, value, key_with_year|
reference = ReferenceStepsHelpers.find_reference_by_key(key_with_year)
step %(I fill in "#{field_name}" with "#{value} {#{Taxt::REF_TAG} #{reference.id}}")
step %(I fill in "#{field_name}" with "#{value} #{Taxt.ref(reference.id)}")
end

Then("the markdown textarea should contain a markdown link to Eciton") do
eciton = Taxon.find_by!(name_cache: "Eciton")
expect(markdown_textarea.value).to include "{#{Taxt::TAX_TAG} #{eciton.id}}"
expect(markdown_textarea.value).to include Taxt.tax(eciton.id)
end

When("I clear the markdown textarea") do
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/reference_section_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
taxon = Taxon.find_by!(name_cache: name)
tag_taxon = Taxon.find_by!(name_cache: tagged_name)

create :reference_section, references_taxt: "{#{Taxt::TAX_TAG} #{tag_taxon.id}}", taxon: taxon
create :reference_section, references_taxt: Taxt.tax(tag_taxon.id), taxon: taxon
end

# Editing.
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/reference_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@

Given("there is a reference referenced in a history item") do
reference = create :any_reference
create :history_item, :taxt, taxt: "{#{Taxt::REF_TAG} #{reference.id}}"
create :history_item, :taxt, taxt: Taxt.ref(reference.id)
end
2 changes: 1 addition & 1 deletion features/step_definitions/what_links_here_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
atta = Taxon.find_by!(name_cache: "Atta")
reference = create :any_reference, author_string: 'Batiatus'

create :history_item, :taxt, taxt: "{#{Taxt::TAX_TAG} #{atta.id}}: {#{Taxt::REF_TAG} #{reference.id}}", protonym: eciton
create :history_item, :taxt, taxt: "#{Taxt.tax(atta.id)}: #{Taxt.ref(reference.id)}", protonym: eciton
end
Loading

0 comments on commit 608bdc2

Please sign in to comment.