Midwest::Iconable
Overview
Midwest::Iconable is an opt-in model concern that lets you declare a canonical icon for any ActiveModel class. Once declared, the icon is available at both the class and instance level, is inherited by subclasses, and is automatically picked up by components like midwest_breadcrumbs.
Setup
Midwest::Iconable is not required by default. Add the require wherever you need it — typically your model file, an initializer, or a shared concern:
require 'midwest/iconable'Declaring an icon
Include the concern and call the icon macro with any icon name from the Midwest icon set:
class Post < ApplicationRecord include Midwest::Iconable icon :'document-text-outline'endClass and instance access
The icon is available at both levels:
Post.icon # => :'document-text-outline'Post.new.icon # => :'document-text-outline'Inheritance
Subclasses inherit the parent's icon unless they declare their own. Overriding on a subclass does not affect the parent or any siblings:
class Content < ApplicationRecord include Midwest::Iconable icon :'documents-outline'endclass Article < Content # inherits icon from Contentendclass Draft < Content icon :'document-outline' # overrides for this class onlyendContent.icon # => :'documents-outline'Article.icon # => :'documents-outline' (inherited)Draft.icon # => :'document-outline' (overridden)Breadcrumbs integration
When an Iconable model is passed as a positional argument to midwest_breadcrumbs, its icon is automatically rendered alongside the breadcrumb label — no extra options required.
This works for both collection arguments (a class) and record arguments (an instance):
# Collection breadcrumb — renders Posts.icon beside "Posts"midwest_breadcrumbs({ title: 'Home', path: '/' }, Post)# Collection + record — both render with their iconmidwest_breadcrumbs({ title: 'Home', path: '/' }, Post, @post)