Last active
January 29, 2023 18:19
-
-
Save josepmartins/7091420d90300870f347 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