Skip to content

Commit 35c1708

Browse files
amatsudaAMHOL
andcommitted
Inline assets in the CSS using Sprockets
This proc changes `url()` calls in *.css e.g.) background-image: url("DataTables-1.10.20/images/sort_both.png"); into base64 encoded inline image via `rake assets:compile`. Note that all images referenced in CSS will be loaded this way, whether or not the user enables SIMPLECOV_INLINE_ASSETS option. This idea and code is taken from #113 by @AMHOL Co-authored-by: AMHOL <[email protected]>
1 parent 6ebb78a commit 35c1708

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ namespace :assets do
3636
require "sprockets"
3737
require "sprockets/sass_processor"
3838

39+
Sprockets.register_processor("text/css") do |input|
40+
{data: input[:data].gsub(/(?<!-|_)url\(['"]?(.+?)['"]?\)/) { "asset-data-url(\"#{Regexp.last_match(1)}\")" }}
41+
end
42+
3943
Sprockets.register_processor "text/css", Sprockets::ScssProcessor
4044

4145
assets = Sprockets::Environment.new do |env|

0 commit comments

Comments
 (0)