From c3c8e4246b5fb01e7a246ad416578a9dd4c4efe1 Mon Sep 17 00:00:00 2001 From: Jesse Doyle Date: Thu, 5 Sep 2019 14:27:50 -0600 Subject: [PATCH] ADO-2646 - FontAwesome 5 Pro * 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]: https://github.com/FortAwesome/font-awesome-sass/issues/146#issuecomment-515709093 SEE: https://dev.azure.com/AMA-Ent/AMA-Ent/_workitems/edit/2646 --- .rubocop.yml | 1 + .simplecov | 2 ++ README.md | 1 + app/assets/stylesheets/font_awesome_pro.scss | 5 +++++ app/assets/stylesheets/shared.scss | 1 + lib/ama/styles/engine.rb | 15 ++++++++++----- lib/ama/styles/internal/deployment.rb | 20 +++++++++++++------- lib/ama/styles/internal/environment.rb | 1 + lib/ama/styles/version.rb | 2 +- lib/ama/tasks/assets.rake | 2 +- spec/dummy/config/initializers/assets.rb | 1 + spec/lib/{ => ama}/tasks/assets_rake_spec.rb | 0 spec/support/shared_examples/rake.rb | 2 +- 13 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 app/assets/stylesheets/font_awesome_pro.scss rename spec/lib/{ => ama}/tasks/assets_rake_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 08f8b89d..01185d6e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,3 +19,4 @@ Metrics/BlockLength: Exclude: - 'spec/**/*' - '*.gemspec' + - 'lib/ama/tasks/assets.rake' diff --git a/.simplecov b/.simplecov index 1bb6a670..36ed11bf 100644 --- a/.simplecov +++ b/.simplecov @@ -1,7 +1,9 @@ SimpleCov.start 'rails' do SimpleCov.minimum_coverage 100.00 add_filter 'lib/ama/styles/version' + add_filter 'lib/ama/styles/engine' add_filter 'lib/ama/styles/internal/chat' add_filter 'lib/ama/styles/internal/commands/deploy' add_filter 'lib/ama/styles/internal/environment' + add_filter 'lib/ama/tasks' end diff --git a/README.md b/README.md index fb34ba99..08a52c34 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/assets/stylesheets/font_awesome_pro.scss b/app/assets/stylesheets/font_awesome_pro.scss new file mode 100644 index 00000000..a02fa3c1 --- /dev/null +++ b/app/assets/stylesheets/font_awesome_pro.scss @@ -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); } diff --git a/app/assets/stylesheets/shared.scss b/app/assets/stylesheets/shared.scss index ad1a4007..870e57b1 100644 --- a/app/assets/stylesheets/shared.scss +++ b/app/assets/stylesheets/shared.scss @@ -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"; diff --git a/lib/ama/styles/engine.rb b/lib/ama/styles/engine.rb index b2807742..7fab400c 100644 --- a/lib/ama/styles/engine.rb +++ b/lib/ama/styles/engine.rb @@ -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? + unless 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 diff --git a/lib/ama/styles/internal/deployment.rb b/lib/ama/styles/internal/deployment.rb index 65bd74c7..c7457d18 100644 --- a/lib/ama/styles/internal/deployment.rb +++ b/lib/ama/styles/internal/deployment.rb @@ -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 @@ -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 @@ -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) diff --git a/lib/ama/styles/internal/environment.rb b/lib/ama/styles/internal/environment.rb index 695016ae..7b606aff 100644 --- a/lib/ama/styles/internal/environment.rb +++ b/lib/ama/styles/internal/environment.rb @@ -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 diff --git a/lib/ama/styles/version.rb b/lib/ama/styles/version.rb index bb84b42f..dac9d41e 100644 --- a/lib/ama/styles/version.rb +++ b/lib/ama/styles/version.rb @@ -2,6 +2,6 @@ module AMA module Styles - VERSION = '2.9.0' + VERSION = '3.0.0' end end diff --git a/lib/ama/tasks/assets.rake b/lib/ama/tasks/assets.rake index 8d3a4c6f..b8094c38 100644 --- a/lib/ama/tasks/assets.rake +++ b/lib/ama/tasks/assets.rake @@ -26,7 +26,7 @@ namespace :assets do end desc 'Link FontAwesome 5 Pro into vendor/assets/fonts/font-awesome' - task :fa5_pro, [:source, :destination] do |task, args| + task :fa5_pro, %i[source destination] do |_task, args| source_path = File.join(args[:source], '*.{eot,svg,ttf,woff,woff2}') font_wildcard = File.expand_path(source_path) destination = File.join(args[:destination], 'vendor', 'assets', 'fonts', 'font-awesome') diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb index 91979fd9..1c29148d 100755 --- a/spec/dummy/config/initializers/assets.rb +++ b/spec/dummy/config/initializers/assets.rb @@ -3,4 +3,5 @@ Rails.application.config.eager_load = false Rails.application.config.assets.css_compressor = :sass +Rails.application.config.font_awesome_pro_source_path = '~/src/font-awesome' Rails.application.config.assets.precompile += %w(shared.css) diff --git a/spec/lib/tasks/assets_rake_spec.rb b/spec/lib/ama/tasks/assets_rake_spec.rb similarity index 100% rename from spec/lib/tasks/assets_rake_spec.rb rename to spec/lib/ama/tasks/assets_rake_spec.rb diff --git a/spec/support/shared_examples/rake.rb b/spec/support/shared_examples/rake.rb index 5085449d..7845fbb3 100644 --- a/spec/support/shared_examples/rake.rb +++ b/spec/support/shared_examples/rake.rb @@ -5,7 +5,7 @@ RSpec.shared_context 'rake' do let(:rake) { Rake::Application.new } let(:task_name) { self.class.top_level_description } - let(:task_path) { "/lib/tasks/#{task_name.split(':').first}" } + let(:task_path) { "/lib/ama/tasks/#{task_name.split(':').first}" } subject { rake[task_name] } def loaded_files_excluding_current_rake_file