fix(tags): relax parser roules
This commit is contained in:
parent
f970347c93
commit
59bdd4bd92
5 changed files with 19 additions and 6 deletions
|
@ -12,6 +12,13 @@ module TagsSubstitutionConcern
|
|||
doc.parse io
|
||||
end
|
||||
|
||||
def self.normalize(str)
|
||||
str
|
||||
.sub(/^[[:space:]]+/, '')
|
||||
.sub(/[[:space:]]+$/, '')
|
||||
.gsub(/[[:space:]]/, ' ')
|
||||
end
|
||||
|
||||
define_combinator :doc do
|
||||
many(tag | text) < eof
|
||||
end
|
||||
|
@ -24,7 +31,7 @@ module TagsSubstitutionConcern
|
|||
|
||||
define_combinator :tag do
|
||||
between(tag_delimiter, tag_delimiter, tag_text).fmap do |tag|
|
||||
{ tag: tag }
|
||||
{ tag: TagsParser.normalize(tag) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
stable_id = @type_de_champ.stable_id
|
||||
tags.push(
|
||||
{
|
||||
libelle: "#{libelle}/primaire",
|
||||
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/primaire",
|
||||
id: "tdc#{stable_id}/primaire",
|
||||
description: "#{description} (menu primaire)",
|
||||
lambda: -> (champs) {
|
||||
|
@ -19,7 +19,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
)
|
||||
tags.push(
|
||||
{
|
||||
libelle: "#{libelle}/secondaire",
|
||||
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/secondaire",
|
||||
id: "tdc#{stable_id}/secondaire",
|
||||
description: "#{description} (menu secondaire)",
|
||||
lambda: -> (champs) {
|
||||
|
|
|
@ -16,7 +16,7 @@ class TypesDeChamp::TypeDeChampBase
|
|||
stable_id = self.stable_id
|
||||
[
|
||||
{
|
||||
libelle: libelle.gsub(/[[:space:]]/, ' '),
|
||||
libelle: TagsSubstitutionConcern::TagsParser.normalize(libelle),
|
||||
id: "tdc#{stable_id}",
|
||||
description: description,
|
||||
lambda: -> (champs) {
|
||||
|
|
|
@ -512,10 +512,16 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
end
|
||||
|
||||
it 'allow for - before tag' do
|
||||
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- world ---numéro-du - dossier--")
|
||||
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- -- before-- --after -- -- around -- world ---numéro-du - dossier--")
|
||||
expect(tokens).to eq([
|
||||
{ text: "hello " },
|
||||
{ tag: "yolo" },
|
||||
{ text: " " },
|
||||
{ tag: "before" },
|
||||
{ text: " " },
|
||||
{ tag: "after" },
|
||||
{ text: " " },
|
||||
{ tag: "around" },
|
||||
{ text: " world -" },
|
||||
{ tag: "numéro-du - dossier" }
|
||||
])
|
||||
|
|
|
@ -38,7 +38,7 @@ describe Mails::InitiatedMail, type: :model do
|
|||
context 'template with invalid tag' do
|
||||
let(:email_body) { 'foo --numéro du -- bar' }
|
||||
|
||||
it { expect(subject.errors.full_messages).to eq(["Le contenu de l’email de notification de passage du dossier en instruction réfère au champ \"numéro du \" qui n’existe pas"]) }
|
||||
it { expect(subject.errors.full_messages).to eq(["Le contenu de l’email de notification de passage du dossier en instruction réfère au champ \"numéro du\" qui n’existe pas"]) }
|
||||
end
|
||||
|
||||
context 'template with unpublished tag' do
|
||||
|
|
Loading…
Reference in a new issue