Fork me on GitHub

Anyicon

Ruby on Rails view helpers for rendering SVG icons from any GitHub collection.

Gem Version MIT License GitHub Stars
View on GitHub RubyGems
# Gemfile
gem 'anyicon'

Why Anyicon?

One helper, thousands of icons, zero JavaScript.

Dead Simple

One helper method. Pass the icon name, get an SVG. No asset pipeline configuration needed.

📦

12,000+ Icons

Font Awesome, Heroicons, Tabler, Carbon, Ionicons, Feather, and more. All built-in.

🔌

Auto-Fetch & Cache

Icons are downloaded from GitHub on first use and cached locally. No manual downloads.

🎨

Fully Customizable

Pass any HTML attribute: class, id, fill, width, height, data-*, aria-*, and more.

🔒

Secure by Default

SVG attribute allowlist, path traversal protection, SSRF prevention with host validation.

🚀

Bring Your Own

Add any GitHub-hosted icon collection with a simple configuration block.

Usage

Just call the helper in your views.

app/views/example.html.erb
<%# Positional argument %>
<%= anyicon "heroicons_outline:check" %>

<%# Keyword argument %>
<%= anyicon icon: "fontawesome_solid:star" %>

<%# With HTML attributes %>
<%= anyicon "tabler_icons_outline:heart",
    class: "w-6 h-6",
    fill: "red",
    id: "fav-icon" %>

<%# Stimulus & accessibility %>
<%= anyicon "ionicons:heart",
    "data-controller": "icon",
    "aria-label": "Favorite",
    role: "img" %>

How It Works

From helper call to rendered SVG in milliseconds.

1

Call the helper

Use anyicon "collection:icon_name" in any view, partial, or layout.

2

Auto-fetch if needed

If the icon isn't cached locally, Anyicon downloads the SVG from the configured GitHub repo.

3

Cache & render

The SVG is saved to app/assets/images/icons/ and rendered inline with your custom attributes.

Configuration

Works out of the box, but fully configurable.

config/initializers/anyicon.rb
Anyicon.configure do |config|
  # Add your own collections
  config.add_collections(
    my_icons: {
      repo: "user/repo",
      path: "path/to/icons",
      branch: "main"
    }
  )

  # Optional: GitHub token for higher API rate limits
  # (60/hour without vs 5,000/hour with token)
  config.github_token = ENV["GITHUB_TOKEN"]
end

Built-in Collections

12,000+ icons ready to use. Just reference them by name.

Quick Start

Up and running in 30 seconds.

Terminal
# Add to your Gemfile
$ bundle add anyicon

# Or generate the initializer
$ rails generate anyicon:install

# Use in any view
<%= anyicon "heroicons_outline:check", class: "w-5 h-5" %>