summaryrefslogtreecommitdiff
path: root/helper.rb
blob: 41fd9eb475cb8e131855d7fd40a71a78a9f780f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
helpers do

  def embedded_svg image, options={}
    doc = Nokogiri::HTML::DocumentFragment.parse image
    svg = doc.at_css 'svg'
    title = doc.at_css 'title'
    if options[:class].present?
      svg['class'] = options[:class]
    end
    if options[:title].present?
      if options[:title] == "x"
        title.children.remove
      else
        title.children.remove
        text_node = Nokogiri::XML::Text.new(options[:title], doc)
        title.add_child(text_node)
      end
    end
    doc.to_html.html_safe
  end


end