app/helpers/image_helper.rb
# Embed an SVG file inline, allowing it to be styled with CSS.
Embed an SVG file inline, allowing it to be styled with CSS.
Embed an SVG file inline allowing it to be styled with CSS .
def embedded_svg(filename, options = {})
    file = File.read(Rails.root.join('app', 'assets', 'images', filename))
    doc = Nokogiri::HTML::DocumentFragment.parse file
    svg = doc.at_css 'svg'
    svg['class'] = "#{svg['class']} #{options[:class]}" if options[:class].present?
    svg['id'] = options[:id] if options[:id].present?
    svg['style'] = "#{svg['style']} #{options[:style]}" if options[:style].present?
    svg['width'] = options[:width] if options[:width].present?
    svg['height'] = options[:height] if options[:height].present?
    doc.to_html.html_safe
  end
def embedded_svg ( filename , options = { } ) file = File . read ( Rails . root . join ( 'app' , 'assets' , 'images' , filename ) ) doc = Nokogiri :: HTML :: DocumentFragment . parse file svg = doc . at_css 'svg' svg [ 'class' ] = "#{svg['class']} #{options[:class]}" if options [ :class ] . present? svg [ 'id' ] = options [ :id ] if options [ :id ] . present? svg [ 'style' ] = "#{svg['style']} #{options[:style]}" if options [ :style ] . present? svg [ 'width' ] = options [ :width ] if options [ :width ] . present? svg [ 'height' ] = options [ :height ] if options [ :height ] . present? doc . to_html . html_safe end
Embed an SVG file inline, allowing it to be styled with CSS.
Embed an SVG file inline allowing it to be styled with CSS .
filename
<not_specific>
options
<not_specific>