npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@optimuspwnius/fontawesome-subset

v6.0.8

Published

Utility to create subsets for Font Awesome 6 (Free and Pro) for use with Ruby on Rails + Propshaft.

Downloads

187

Readme

FontAwesome Subset For Ruby on Rails CSS-Bundling

It's like TailwindCSS but for FontAwesome!

Installation

In Procfile.dev add

fontawesome: yarn build:fontawesome --watch

In package.json under "scripts" add

"build:fontawesome": "subset"

Some options you can add to the build:fontawesome subset command are:

Use Font Awesome Pro (requires subscription and your npm token to be setup beforehand)

"build:fontawesome": "subset --pro"

Remove all whitespace to make the file as small as possible. This option just adds the style="compressed" option to the sass compiler when it builds the output file.

"build:fontawesome": "subset --minify"

Sets the output path and filename. The default is app/assets/builds/fontawesome.css

"build:fontawesome": "subset --output app/assets/myfonts.css"

Create lib/tasks/build.rake and add the following

namespace :build do

  desc "Builds FontAwesome by subsetting icons."
  task :fontawesome do
    unless system "yarn install && yarn build:fontawesome"
      raise "cssbundling-rails: Command build:fontawesome failed, ensure yarn is installed and `yarn build:fontawesome` runs without errors"
    end
  end

  Rake::Task["assets:precompile"].enhance(["build:fontawesome"])

end

Add this to your helper in app/helpers/application_helper.rb

# This has been adapted from the font-awesome-sass gem found at: https://github.com/FortAwesome/font-awesome-sass/blob/master/lib/font_awesome/sass/rails/helpers.rb
def icon(style, name, text = nil, html_options = {}, &block)
  text, html_options = nil, text if text.is_a?(Hash)
  style = style.to_s
  name  = name.to_s.dasherize

  content_class = "#{ style } fa-#{ name }"
  content_class << " #{html_options[:class]}" if html_options.key?(:class)
  html_options[:class] = content_class

  html = content_tag(:i, nil, html_options)

  unless text.blank?
    html = "#{ html } #{ text.to_s }"
  end

  if block_given?
    html = "#{ html } #{ capture(block) }"
  end

  html.html_safe
end

Reference the stylesheet in your layout:

= stylesheet_link_tag 'fontawesome'

After installation, run your proc file which will watch your development app and create icon subsets on the fly. In production during deploy your app should automatically run the rake task build:fontawesome and create the icon subsets and css.

Usage

Use the icon method from the helper as this is what we are scanning for to create subsets. The icon() method's first parameter is the icon type and can be a symbol (like :fas, :fad, :far, :fal, :fab, or :fass) or just a string (like this... "fas"). The second parameter is the actual icon name and can be a symbol (like :mug_hot, :file, or :poo) or a string (like "mug-hot" or "poo")

In your app you should reference your fonts like this:

icon(:fas, :mug_hot)

# OR

icon('fas', 'mug-hot')

# OR

icon :fas, :mug_hot

Requests

PRs welcome. If you need help just open an issue.

Special Thanks

Thanks to omacranger for the nifty fontawesome-subset package: https://github.com/omacranger/fontawesome-subset