Created
July 5, 2015 05:08
-
-
Save thattimc/cc1df515853446770035 to your computer and use it in GitHub Desktop.
Embedded SVG to 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
def embedded_svg(filename, options = {}) | |
assets = Rails.application.assets | |
file = assets.find_asset(filename).body.force_encoding("UTF-8") | |
doc = Nokogiri::HTML::DocumentFragment.parse file | |
svg = doc.at_css "svg" | |
if options[:class].present? | |
svg["class"] = options[:class] | |
end | |
raw doc | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment