Skip to content

Commit

Permalink
ADO-2646 - FontAwesome 5 Pro
Browse files Browse the repository at this point in the history
* We are looking to use pro-only FontAwesome 5 icons in an
  upcoming feature. We have a perpetual enterprise license
  for FontAwesome Pro, but we are forbidden from distributing
  the webfont files to "non-creators" in the license.
* Uploading the webfont files to this open-source package
  is considered a breach of the pro license (according to
  fontawesome support), so we need to create conditions
  to "enable" the pro icon set specifically for our
  organization's use.
* Symlink in the pro fontawesome files into
  'vendor/assets/fonts/font-awesome` when the configuration
  value of `font_awesome_pro_source_path` is provided.
* Because the files are symlinked into the vendored asset
  directory, they override the free files provided by
  the `font-awesome-sass` gem [1] in the asset pipeline.
* The `font-awesome-sass` gem does not provide unicode
  mappings for the pro-only icons. If we wish to use
  them, we need to define the unicode mapping in
  the `font_awesome_pro.scss` file.

[1]: FortAwesome/font-awesome-sass#146 (comment)
SEE: https://dev.azure.com/AMA-Ent/AMA-Ent/_workitems/edit/2646
  • Loading branch information
Jesse Doyle committed Sep 5, 2019
1 parent 2b127d7 commit 4e2f2b6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem that will carry and deploy AMA assets.

```ruby
Rails.configuration.assets.precompile += %w(shared.css)
Rails.configuration.font_awesome_pro_source_path = '~/source/to/font-awesome'
Rails.configuration.stylesheet_resolver.remote = Rails.env.production?
```
* Add the `ASSET_CLOUDFRONT_URL` variable to the relevant `.env` file for the application.
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/font_awesome_pro.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* NOTE: font-awesome-sass does not define the pro-only icons. If you want
* use one, you must define it below.
*/
.#{$fa-css-prefix}-tire:before { content: fa-content(\f631); }
1 change: 1 addition & 0 deletions app/assets/stylesheets/shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "webfonts/index";
@import "font-awesome-sprockets";
@import "font-awesome";
@import "font_awesome_pro";
@import "foundation_and_overrides";
@import "foundation";
@import "layout/index";
Expand Down
15 changes: 10 additions & 5 deletions lib/ama/styles/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ class Engine < ::Rails::Engine
end

config.after_initialize do |app|
# are we using bundled assets? (i.e. dev/local)
if app.config.stylesheet_resolver.local? && Rails.env.development?
if !app.root.join('vendor', 'assets', 'fonts', 'font-awesome').exist?
Rake::Task['assets:fa5_pro'].invoke(
'~/src/rails_envs/font-awesome',
app.root.to_s
)
# is a source location provided for the font awesome pro font files?
if app.config.font_awesome_pro_source_path.present?
# are there already pro files in the application asset folder?
if !app.root.join('vendor', 'assets', 'fonts', 'font-awesome').exist?
Rake::Task['assets:fa5_pro'].invoke(
app.config.font_awesome_pro_source_path,
app.root.to_s
)
end
end
end
end
Expand Down
20 changes: 13 additions & 7 deletions lib/ama/styles/internal/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Deployment

def run
sprockets_tasks
# upload_files
upload_files
log('Generating fallback stylesheet...'.colorize(:yellow))
# upload_fallback_stylesheet
upload_fallback_stylesheet
log('Verifying S3 integrity...'.colorize(:yellow))
# request
request
log('SUCCESS!'.colorize(:green) + ' 🎨')
end

Expand Down Expand Up @@ -49,10 +49,12 @@ def log(msg)

def precompile_assets
Rake::Task['assets:copy_raw_assets'].invoke
Rake::Task['assets:fa5_pro'].invoke(
'~/src/rails_envs/ama_styles',
GEM_ROOT_PATH
)
if (font_awesome_pro?)
Rake::Task['assets:fa5_pro'].invoke(
Rails.configuration.font_awesome_pro_source_path,
GEM_ROOT_PATH
)
end
Rake::Task['assets:precompile'].invoke
end

Expand All @@ -70,6 +72,10 @@ def assets_files
end
end

def font_awesome_pro?
Rails.configuration.font_awesome_pro_source_path.present?
end

def upload_files
assets_files.each do |file|
path = Pathname.new(file)
Expand Down
1 change: 1 addition & 0 deletions lib/ama/styles/internal/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def configure_assets
config.eager_load = false
config.assets.css_compressor = :sass
config.assets.precompile += %w[shared.css]
config.font_awesome_pro_source_path = ENV['FONT_AWESOME_PRO_SOURCE_PATH']
end

def configure_api
Expand Down
2 changes: 1 addition & 1 deletion lib/ama/styles/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module AMA
module Styles
VERSION = '2.9.0'
VERSION = '3.0.0'
end
end

0 comments on commit 4e2f2b6

Please sign in to comment.