-
-
Save Kolenov/c0e47991f00ffe3cec59584c6e5c5cc1 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(source) | |
file = File.open("app/assets/images/#{source}", "rb") | |
raw file.read | |
end | |
# SVG internal link | |
#= svg_tag 'sprite/icons.svg', 'icon-facebook-invers' | |
module SvgHelper | |
def svg_tag(source, name, options = {}) | |
svg_tag_options = options.merge( | |
:class => ['icon', name, options[:class]].reject(&:blank?).join(" "), | |
) | |
content_tag(:svg, svg_tag_options) do | |
content_tag(:use, nil, "xlink:href" => path_to_image(source) + "#" + name) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment