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
|
doc.parse io
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.normalize(str)
|
||||||
|
str
|
||||||
|
.sub(/^[[:space:]]+/, '')
|
||||||
|
.sub(/[[:space:]]+$/, '')
|
||||||
|
.gsub(/[[:space:]]/, ' ')
|
||||||
|
end
|
||||||
|
|
||||||
define_combinator :doc do
|
define_combinator :doc do
|
||||||
many(tag | text) < eof
|
many(tag | text) < eof
|
||||||
end
|
end
|
||||||
|
@ -24,7 +31,7 @@ module TagsSubstitutionConcern
|
||||||
|
|
||||||
define_combinator :tag do
|
define_combinator :tag do
|
||||||
between(tag_delimiter, tag_delimiter, tag_text).fmap do |tag|
|
between(tag_delimiter, tag_delimiter, tag_text).fmap do |tag|
|
||||||
{ tag: tag }
|
{ tag: TagsParser.normalize(tag) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
stable_id = @type_de_champ.stable_id
|
stable_id = @type_de_champ.stable_id
|
||||||
tags.push(
|
tags.push(
|
||||||
{
|
{
|
||||||
libelle: "#{libelle}/primaire",
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/primaire",
|
||||||
id: "tdc#{stable_id}/primaire",
|
id: "tdc#{stable_id}/primaire",
|
||||||
description: "#{description} (menu primaire)",
|
description: "#{description} (menu primaire)",
|
||||||
lambda: -> (champs) {
|
lambda: -> (champs) {
|
||||||
|
@ -19,7 +19,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
)
|
)
|
||||||
tags.push(
|
tags.push(
|
||||||
{
|
{
|
||||||
libelle: "#{libelle}/secondaire",
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)}/secondaire",
|
||||||
id: "tdc#{stable_id}/secondaire",
|
id: "tdc#{stable_id}/secondaire",
|
||||||
description: "#{description} (menu secondaire)",
|
description: "#{description} (menu secondaire)",
|
||||||
lambda: -> (champs) {
|
lambda: -> (champs) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class TypesDeChamp::TypeDeChampBase
|
||||||
stable_id = self.stable_id
|
stable_id = self.stable_id
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
libelle: libelle.gsub(/[[:space:]]/, ' '),
|
libelle: TagsSubstitutionConcern::TagsParser.normalize(libelle),
|
||||||
id: "tdc#{stable_id}",
|
id: "tdc#{stable_id}",
|
||||||
description: description,
|
description: description,
|
||||||
lambda: -> (champs) {
|
lambda: -> (champs) {
|
||||||
|
|
|
@ -512,10 +512,16 @@ describe TagsSubstitutionConcern, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allow for - before tag' do
|
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([
|
expect(tokens).to eq([
|
||||||
{ text: "hello " },
|
{ text: "hello " },
|
||||||
{ tag: "yolo" },
|
{ tag: "yolo" },
|
||||||
|
{ text: " " },
|
||||||
|
{ tag: "before" },
|
||||||
|
{ text: " " },
|
||||||
|
{ tag: "after" },
|
||||||
|
{ text: " " },
|
||||||
|
{ tag: "around" },
|
||||||
{ text: " world -" },
|
{ text: " world -" },
|
||||||
{ tag: "numéro-du - dossier" }
|
{ tag: "numéro-du - dossier" }
|
||||||
])
|
])
|
||||||
|
|
|
@ -38,7 +38,7 @@ describe Mails::InitiatedMail, type: :model do
|
||||||
context 'template with invalid tag' do
|
context 'template with invalid tag' do
|
||||||
let(:email_body) { 'foo --numéro du -- bar' }
|
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
|
end
|
||||||
|
|
||||||
context 'template with unpublished tag' do
|
context 'template with unpublished tag' do
|
||||||
|
|
Loading…
Reference in a new issue