Skip to content

Instantly share code, notes, and snippets.

@scarfacedeb
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save scarfacedeb/c2c6f5bf7e5486a51cca to your computer and use it in GitHub Desktop.

Select an option

Save scarfacedeb/c2c6f5bf7e5486a51cca to your computer and use it in GitHub Desktop.
Svg helper to reference icons
def svg_icon(icon, view_box: nil, css_class: "")
view_box = view_box.join(" ") if view_box # no need by default, because we use symbols with viewBox
element_id = "icon-#{icon}"
css_class << " icon "
css_class << element_id
content_tag :svg, class: css_class, viewBox: view_box do
content_tag :use, nil, :"xlink:href" => "##{element_id}"
end
end
# OR
def svg_icon(icon, view_box: [0,0,32,32], css_class: nil)
view_box = view_box.join(" ")
%Q{<svg class="icon icon-#{icon} #{css_class}" viewBox="#{view_box}"><use xlink:href="#icon-#{icon}"></use></svg>}.html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment