Introducing Icons: Add any icon library to your Ruby app
Source: Dev.to
Almost two years ago I announced Rails Icons. I started that article with the notion that I have no app where I do not use icons. That is still true today.
I also still use Rails for all my SaaS apps, but what if you don’t? What if you use one of the many other amazing Ruby frameworks, like Hanami, Rodauth, or maybe Padrino? Or what if, instead of Perron (a Rails‑based SSG), you use Jekyll, Middleman, or Bridgetown?
You cannot use the elegant way of adding SVG icons—of any of the small dozen icon libraries—in your app or site. Sad! 😞
So, after ~210k downloads, I extracted the core (Ruby) part from Rails Icons into its own gem: Icons. ⭐
Now Rails Icons’ core features rely on the Icons gem, and only the Rails‑specific parts (helper and generators) live in the Rails Icons gem itself, while the usage of Rails Icons remains unchanged.
This new setup allows you to either:
- Build your own layer (like Rails Icons) around Icons and package it into a gem, or
- Use Icons directly in any Ruby app.
Usage
# Sync any of the supported libraries from their respective (GitHub) repository
Icons::Sync.new("lucide").now
# Render an icon
icon = Icons::Icon.new(
name: "check",
library: "lucide",
variant: "outline",
arguments: { class: "text-gray-500" }
)
svg = icon.svg
If you want to build a layer around the Icons gem for a framework or SSG (if you still don’t use Perron 😅), feel free to reach out—I’m happy to help.
You can find the source of the Icons gem on GitHub. ⭐