Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Last active May 4, 2018 08:17
Show Gist options
  • Save Kolenov/a59a581b0f9e6306e237dc80549902c4 to your computer and use it in GitHub Desktop.
Save Kolenov/a59a581b0f9e6306e237dc80549902c4 to your computer and use it in GitHub Desktop.
SVG Sprite for Plei
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
## Usage
# = svg_icon_tag 'social-icons.svg', 'twitter-icon'
module SvgHelper
def svg_icon_tag(source, name, options = {})
svg_tag_options = options.merge(class: ['symbol', 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
# Inline svg from @tomeara https://gist.github.com/tomeara/6515860
# or add #https://github.com/Keyamoon/svgxuse for IE
def inline_svg(source)
file = File.open("app/assets/images/#{source}", "rb")
raw file.read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment