From 7959fe0721ec689151661c6a729de78c1ddc9804 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 22 Jun 2022 15:43:58 +0200 Subject: [PATCH] refactor wip --- .../communication/block/template/embed.rb | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/app/models/communication/block/template/embed.rb b/app/models/communication/block/template/embed.rb index a02f6df85..053f90ee6 100644 --- a/app/models/communication/block/template/embed.rb +++ b/app/models/communication/block/template/embed.rb @@ -5,31 +5,23 @@ class Communication::Block::Template::Embed < Communication::Block::Template::Ba protected - def has_iframe? - - @doc = Nokogiri::XML(code) - is_iframe = @doc.xpath("//iframe") - - if !is_iframe.empty? - return true - end + def check_accessibility + super + accessibility_error 'accessibility.blocks.templates.embed.title_missing' if has_iframe_without_title? + accessibility_error 'accessibility.blocks.templates.embed.transcription_missing' if has_iframe? && transcription.blank? + end + def has_iframe? + !nokogiri.xpath("//iframe").empty? end def has_iframe_without_title? - - if has_iframe? - - Nokogiri::XML(code).at('iframe').attr('title') - - end - + return false unless has_iframe? + nokogiri.at('iframe').attr('title') end - def check_accessibility - super - accessibility_error 'accessibility.blocks.templates.embed.title_missing' if has_iframe? && !has_iframe_without_title? - accessibility_error 'accessibility.blocks.templates.embed.transcription_missing' if has_iframe? && transcription.blank? + def nokogiri + @nokogiri ||= Nokogiri::XML(code) end end -- GitLab