Module: ZendeskAppsSupport::Validations::Svg

Defined in:
lib/zendesk_apps_support/validations/svg.rb

Class Method Summary collapse

Class Method Details

.call(package) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zendesk_apps_support/validations/svg.rb', line 8

def call(package)
  errors = []
  package.svg_files.each do |svg|
    markup = svg.read
    clean_markup = Loofah.scrub_xml_document(markup, :prune).to_html
    filepath = svg.relative_path

    next if clean_markup == markup
    begin
      IO.write(filepath, clean_markup)
      package.warnings << I18n.t('txt.apps.admin.warning.sanitised_svg', svg: filepath)
    rescue
      errors << ValidationError.new(:dirty_svg, svg: filepath)
    end
  end
  errors
end