FontAwesome Free

Add fontawesome free to your Rails app
Icons/chart bar
Used 29 times
Created by
C Chuck

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zNPsjP"
Template Source

Review the code before running this template on your machine.

# install fontawesome-free via yarn
run "yarn add @fortawesome/fontawesome-free"

# create css folder and application.scss
run "mkdir app/javascript/stylesheets" if !Dir.exist?('app/javascript/stylesheets') 
run "touch app/javascript/stylesheets/application.scss" if !File.exist?('app/javascript/stylesheets/application.scss') 

# add reference to fontawesome-free to application.scss
inject_into_file 'app/javascript/stylesheets/application.scss' do <<~EOF
	@import '~@fortawesome/fontawesome-free';
    EOF
end

# add requre of css/application.scss && import of fontawesome-free to application.js
inject_into_file 'app/javascript/packs/application.js' do <<~EOF
  require("stylesheets/application.scss")
  import "@fortawesome/fontawesome-free/js/all"
  EOF
end
Comments

Sign up or Login to leave a comment.