Merge pull request #8515 from tchak/fix-tags-validation
Améliorations sur la validation des balises dans les attestations
This commit is contained in:
commit
905d1f2605
3 changed files with 7 additions and 25 deletions
|
@ -8,6 +8,7 @@ module Administrateurs
|
|||
|
||||
def edit
|
||||
@attestation_template = build_attestation_template
|
||||
@attestation_template.validate
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -41,11 +41,11 @@ module TagsSubstitutionConcern
|
|||
end
|
||||
|
||||
define_combinator :tag_text_first_char do
|
||||
any_char.that_fail(lit('-') | tag_delimiter | eol)
|
||||
any_char.that_fail(lit('-') | tag_delimiter)
|
||||
end
|
||||
|
||||
define_combinator :tag_text_char do
|
||||
any_char.that_fail(tag_delimiter | eol)
|
||||
any_char.that_fail(tag_delimiter)
|
||||
end
|
||||
|
||||
define_combinator :tag_text do
|
||||
|
@ -53,10 +53,6 @@ module TagsSubstitutionConcern
|
|||
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
||||
end
|
||||
end
|
||||
|
||||
define_combinator :eol do
|
||||
lit("\r\n") | lit("\n")
|
||||
end
|
||||
end
|
||||
|
||||
DOSSIER_TAGS = [
|
||||
|
|
|
@ -32,25 +32,10 @@ namespace :benchmarks do
|
|||
|
||||
desc 'Attestation Template parser'
|
||||
task attestation_template_parser: :environment do
|
||||
progress = ProgressReport.new(AttestationTemplate.count)
|
||||
AttestationTemplate.find_each do |template|
|
||||
parsed = TagsSubstitutionConcern::TagsParser.parse(template.body)
|
||||
serialized = parsed.map do |token|
|
||||
case token
|
||||
in { tag: tag }
|
||||
"--#{tag}--"
|
||||
in { text: text }
|
||||
text
|
||||
end
|
||||
end.join('')
|
||||
if serialized != template.body
|
||||
throw "Template '#{serialized}' is not eq '#{template.body}' with attestation template #{template.id}"
|
||||
end
|
||||
progress.inc
|
||||
rescue => e
|
||||
pp "Error with attestation template #{template.id}"
|
||||
throw e
|
||||
procedure = Procedure.find(68139)
|
||||
Benchmark.bm do |x|
|
||||
x.report("Empty") { TagsSubstitutionConcern::TagsParser.parse('') }
|
||||
x.report("Démarche 68139") { TagsSubstitutionConcern::TagsParser.parse(procedure.attestation_template.body) }
|
||||
end
|
||||
progress.finish
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue