Skip to content

Instantly share code, notes, and snippets.

@jayperryworks
Last active August 29, 2015 14:11
Show Gist options
  • Save jayperryworks/ba24a0f4f5a4c91f601c to your computer and use it in GitHub Desktop.
Save jayperryworks/ba24a0f4f5a4c91f601c to your computer and use it in GitHub Desktop.
A simple ERB partial (for Middleman) to insert an external icon sprite. Based on the svg4everybody guidelines (https://github.com/jonathantneal/svg4everybody).
<%# A simple partial for inserting SVG sprites. %>
<%# @param id: (string) the ID of the sprite you want %>
<%# @param classes: (string, optional) any classes you'd like to add. %>
<%# @param role: ARIA role. use either 'img' (default) or 'presentation'. %>
<%# -> "presentation" designates it as simply decoration (and should be ignored by screenreaders) %>
<%# -> while "img" says it should have its own description. In the latter case, the title attribute acts like an alt tag. %>
<% classes ||= "" %>
<% title ||= "" %>
<% role ||= "img" %>
<svg class="icon <%= id %><%= " #{classes}" %>" title="<%= title %>" role="<%= role %>">
<use xlink:href="<%= asset_url("#{icons_dir}/spritemap.svg##{id}") %>"></use>
</svg>
<%# usage: %>
<%# partial("layouts/partials/icon", :locals => { :id => "[ NAME OF ICON ]", :classes => "[ ADDITIONAL CLASSES ]", :role => "img" }) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment