Simple Icons Rails Gem
IMPORTANT
version 0.1.x gem 'simple-icons-rails', '~> 0.1.0'
version 0.2.x gem 'simple_icons_rails', '~> 0.2.0'
Description
The Simple Icons Rails Gem is a Ruby gem designed for importing and using the icons from Simple Icons in your Rails projects. Simple Icons provides a collection of more than 2500 SVG icons for various popular brands.
This gem simplifies the process of rendering Simple Icons in a Rails application, allowing you to easily include the icons in your views and customize their appearance. This gem is acting as a passthrough to Simple Icons CDN. The icons are not downloaded to your Rails application. This means that when a new icon is uploaded or an existing one updated, you can access it right away without having to update this gem.
For more information about Simple Icons, please visit their website: https://simpleicons.org/. You can also explore the Simple Icons GitHub repository at https://github.com/simple-icons.
Installation
To use the Simple Icons Rails Gem, follow these steps:
-
Add the gem to your Rails application's Gemfile:
gem 'simple_icons_rails', '~> 0.2.0'
-
Save the Gemfile and run the following command to install the gem:
bundle install
That's it! The Simple Icons Rails Gem is now installed and ready to be used in your Rails application.
Usage
To render Simple Icons in your Rails views, you can utilize the simpleicons
helper method provided by the gem. Here's an example of how to use it:
<%= simple_icon('[ICON SLUG]', '[COLOR]', html_options = {}) %>
Replace 'github' with the name of the specific icon you want to render. You can also customize the icon's appearance by passing additional options like width, height, class, and style. Use https://simpleicons.org/ to browse available icons.
[COLOR] is optional, and can be replaced by the hex colors or CSS keywords of the icon you want to you use. The color is defaulted to the HEX color of the icon shown in simpleicons.org website. For example:
<%= simple_icon('github') %>
<%= simple_icon('github', 'red') %>
<%= simple_icon('github', 'black', class: 'custom-class', style: 'color: red;') %>
<%= simple_icon('amazon', 'red', class: 'icon', height: '32', width: '32') %>
<%= simple_icon('github', '0cf', class: 'icon', height: '32', width: '32') %>
<%= simple_icon('simpleicons', '00ccff99', class: 'icon', height: '32', width: '32') %>
Advanced configuration
Version 0.2 and above You can add a file, simple_icons.rb
in your Rails app/config/initializers
folder to change the CDN. See example below for more details.
# config/initializers/simple_icons.rb
SimpleIconsRails.configure do |config|
config.cdn_url = "https://new-cdn-url.com/"
end
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/the-pew-inc/simple-icons-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the SimpleIconsRails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.