Last active
August 29, 2015 14:04
-
-
Save scarfacedeb/c2c6f5bf7e5486a51cca to your computer and use it in GitHub Desktop.
Svg helper to reference icons
This file contains hidden or 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 svg_icon(icon, view_box: nil, css_class: "") | |
| view_box = view_box.join(" ") if view_box # no need by default, because we use symbols with viewBox | |
| element_id = "icon-#{icon}" | |
| css_class << " icon " | |
| css_class << element_id | |
| content_tag :svg, class: css_class, viewBox: view_box do | |
| content_tag :use, nil, :"xlink:href" => "##{element_id}" | |
| end | |
| end | |
| # OR | |
| def svg_icon(icon, view_box: [0,0,32,32], css_class: nil) | |
| view_box = view_box.join(" ") | |
| %Q{<svg class="icon icon-#{icon} #{css_class}" viewBox="#{view_box}"><use xlink:href="#icon-#{icon}"></use></svg>}.html_safe | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment