-
-
Save bradonomics/3e9edc70bc982d26c9428d5d154bc5f5 to your computer and use it in GitHub Desktop.
SVG inline helpers for Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inline svg from @tomeara https://gist.github.com/tomeara/6515860 | |
def inline_svg(path) | |
file = File.open("app/assets/images/#{path}", "rb") | |
raw file.read | |
end | |
# Use SVG internal link | |
def use_svg(clazz) | |
content_tag(:svg, content_tag(:use, "", { "xlink:href" => '#icon-' + clazz }), class: "icon icon-#{clazz}") | |
end | |
# Render defs just after body tag | |
# = inline_svg('icons/svgdefs.svg') | |
# SVG internal link | |
#= use_svg('bell') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment