Skip to content

Commit dfe322b

Browse files
committed
Move asset copying to precompile task
- Moved the code for copying Bootstrap glyphicons and TinyMCE skins from the initializer to a custom Rake task. - Created a new Rake task `assets:copy` to handle the copying of necessary files. - Ensured that the `assets:copy` task runs before `assets:precompile` by setting it as a prerequisite. - This change prevents the files from being copied every time the Rails application initializes (e.g., when starting the server or console), and only copies them during the asset precompilation process.
1 parent 097372c commit dfe322b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

config/initializers/assets.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,3 @@
1414
# application.js, application.css, and all non-JS/CSS in the app/assets
1515
# folder are already added.
1616
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
17-
18-
# Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over
19-
puts "Copying Bootstrap glyphicons to the public directory ..."
20-
source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*'))
21-
destination_dir = Rails.root.join('public', 'fonts', 'bootstrap')
22-
FileUtils.mkdir_p(destination_dir)
23-
FileUtils.cp_r(source_dir, destination_dir)
24-
25-
puts "Copying TinyMCE skins to the public directory ..."
26-
source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide'))
27-
destination_dir = Rails.root.join('public', 'tinymce', 'skins')
28-
FileUtils.mkdir_p(destination_dir)
29-
FileUtils.cp_r(source_dir, destination_dir)

lib/tasks/assets.rake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace :assets do
2+
desc 'Copy Bootstrap glyphicons and TinyMCE skins to the public directory'
3+
task :copy do
4+
# Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over
5+
puts 'Copying Bootstrap glyphicons to the public directory ...'
6+
source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*'))
7+
destination_dir = Rails.root.join('public', 'fonts', 'bootstrap')
8+
FileUtils.mkdir_p(destination_dir)
9+
FileUtils.cp_r(source_dir, destination_dir)
10+
11+
puts 'Copying TinyMCE skins to the public directory ...'
12+
source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide'))
13+
destination_dir = Rails.root.join('public', 'tinymce', 'skins')
14+
FileUtils.mkdir_p(destination_dir)
15+
FileUtils.cp_r(source_dir, destination_dir)
16+
end
17+
18+
# Run the copy task before precompiling assets
19+
task precompile: :copy
20+
end

0 commit comments

Comments
 (0)