Class: ApplicationHelper

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#show_svg(attachment, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/application_helper.rb', line 2

def show_svg(attachment, options = {})
  return if !attachment.content_type.include?("svg")

  attachment.open do |file|
    content = file.read
    doc = Nokogiri::HTML::DocumentFragment.parse content
    svg = doc.at_css "svg"

    # for security
    doc.search("script").each do |src|
      src.remove
    end

    options.each { |attr, value| svg[attr.to_s] = value }

    doc.to_html.html_safe
  end
end