Show section numbers only if none of sections start with numbers

This commit is contained in:
Paul Chavard 2021-04-02 18:19:56 +01:00
parent f77285ded6
commit 4feda01b6f
2 changed files with 15 additions and 4 deletions

View file

@ -22,6 +22,20 @@ class Champs::HeaderSectionChamp < Champ
# The user cannot enter any information here so it doesnt make much sense to search
end
def libelle_with_section_index
if libelle_with_section_index? || siblings.any?(&:libelle_with_section_index?)
libelle
else
"#{section_index}. #{libelle}"
end
end
private
def libelle_with_section_index?
libelle =~ /^\d/
end
def section_index
siblings
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }

View file

@ -1,5 +1,2 @@
%h2.header-section
- libelle_starts_with_number = (champ.libelle =~ /^\d/)
- if !libelle_starts_with_number
= "#{champ.section_index}."
= champ.libelle
= champ.libelle_with_section_index