Skip to content

Commit

Permalink
cp Bootstrap & TinyMCE w/ rails assets:precompile
Browse files Browse the repository at this point in the history
This commit moves the logic for copying Bootstrap glyphicons and TinyMCE skins to the public directory from the assets.rb initializer to a dedicated Rake task. The new task, `assets:copy_assets`, is invoked as part of the `assets:precompile` process. This change ensures that the file copying logic is only executed during the assets precompilation process, which prevents redundant copying of these files.
  • Loading branch information
aaronskiba committed Jan 3, 2025
1 parent a82d97c commit 5f1af3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
13 changes: 0 additions & 13 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,3 @@
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

# Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over
puts "Copying Bootstrap glyphicons to the public directory ..."
source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*'))
destination_dir = Rails.root.join('public', 'fonts', 'bootstrap')
FileUtils.mkdir_p(destination_dir)
FileUtils.cp_r(source_dir, destination_dir)

puts "Copying TinyMCE skins to the public directory ..."
source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide'))
destination_dir = Rails.root.join('public', 'tinymce', 'skins')
FileUtils.mkdir_p(destination_dir)
FileUtils.cp_r(source_dir, destination_dir)
24 changes: 24 additions & 0 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

namespace :assets do
desc 'Copy Bootstrap glyphicons and TinyMCE skins to the public directory'
task :copy_assets do
# Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over
puts 'Copying Bootstrap glyphicons to the public directory ...'
source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*'))
destination_dir = Rails.root.join('public', 'fonts', 'bootstrap')
FileUtils.mkdir_p(destination_dir)
FileUtils.cp_r(source_dir, destination_dir)

puts 'Copying TinyMCE skins to the public directory ...'
source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide'))
destination_dir = Rails.root.join('public', 'tinymce', 'skins')
FileUtils.mkdir_p(destination_dir)
FileUtils.cp_r(source_dir, destination_dir)
end

# Set assets:copy_assets as an extension of assets:precompile
Rake::Task['assets:precompile'].enhance do
Rake::Task['assets:copy_assets'].invoke
end
end

0 comments on commit 5f1af3d

Please sign in to comment.