Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Forked from josepmartins/inline_svg_helpers.rb
Last active November 1, 2017 10:45
Show Gist options
  • Save Kolenov/c0e47991f00ffe3cec59584c6e5c5cc1 to your computer and use it in GitHub Desktop.
Save Kolenov/c0e47991f00ffe3cec59584c6e5c5cc1 to your computer and use it in GitHub Desktop.
SVG inline helpers for Rails
# 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