Skip to content

Commit c225a83

Browse files
authored
Merge pull request #143 from amatsuda/inline_css_assets
Inline images into application.css during asset compilation
2 parents e0ebe4c + 2c44778 commit c225a83

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ group :development do
2323
gem "rubocop-minitest"
2424
gem "rubocop-performance"
2525
gem "rubocop-rake"
26+
gem "sass"
2627
gem "sprockets"
2728
gem "uglifier"
28-
gem "yui-compressor"
2929
end
3030

3131
gem "base64" if RUBY_VERSION >= "3.3"

Gemfile.lock

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: https://github.com/simplecov-ruby/simplecov
3-
revision: 0260b1f309e76c8ed87731ebbc348b05d753b8a2
3+
revision: b6c2d4208a5fa395ce09d7e1d3b074f680ee29b0
44
specs:
55
simplecov (0.22.0)
66
docile (~> 1.1)
@@ -16,9 +16,12 @@ GEM
1616
remote: https://rubygems.org/
1717
specs:
1818
ast (2.4.2)
19+
base64 (0.2.0)
1920
concurrent-ruby (1.3.4)
2021
docile (1.4.1)
2122
execjs (2.9.1)
23+
ffi (1.17.0)
24+
logger (1.6.1)
2225
minitest (5.15.0)
2326
parallel (1.24.0)
2427
parser (3.3.4.2)
@@ -29,9 +32,11 @@ GEM
2932
rack (3.1.7)
3033
rainbow (3.1.1)
3134
rake (13.2.1)
35+
rb-fsevent (0.11.2)
36+
rb-inotify (0.11.1)
37+
ffi (~> 1.0)
3238
regexp_parser (2.9.2)
3339
rexml (3.3.6)
34-
strscan
3540
rubocop (1.28.2)
3641
parallel (~> 1.10)
3742
parser (>= 3.1.0.0)
@@ -51,34 +56,38 @@ GEM
5156
rubocop-rake (0.6.0)
5257
rubocop (~> 1.0)
5358
ruby-progressbar (1.13.0)
59+
sass (3.7.4)
60+
sass-listen (~> 4.0.0)
61+
sass-listen (4.0.0)
62+
rb-fsevent (~> 0.9, >= 0.9.4)
63+
rb-inotify (~> 0.9, >= 0.9.7)
5464
simplecov_json_formatter (0.1.4)
5565
sprockets (4.2.1)
5666
concurrent-ruby (~> 1.0)
5767
rack (>= 2.2.4, < 4)
58-
strscan (3.1.0)
59-
strscan (3.1.0-java)
6068
uglifier (4.2.0)
6169
execjs (>= 0.3.0, < 3)
6270
unicode-display_width (2.5.0)
63-
yui-compressor (0.12.0)
6471

6572
PLATFORMS
6673
arm64-darwin-22
6774
ruby
6875
universal-java-1.8
6976

7077
DEPENDENCIES
78+
base64
79+
logger
7180
minitest
7281
rake (>= 11)
7382
rubocop
7483
rubocop-minitest
7584
rubocop-performance
7685
rubocop-rake
86+
sass
7787
simplecov!
7888
simplecov-html!
7989
sprockets
8090
uglifier
81-
yui-compressor
8291

8392
BUNDLED WITH
8493
2.3.15

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ namespace :assets do
3434
task :compile do
3535
puts "Compiling assets"
3636
require "sprockets"
37+
require "sprockets/sass_processor"
38+
39+
Sprockets.register_processor("text/css") do |input|
40+
{data: input[:data].gsub(/(?<!-|_)url\(['"]?(.+?)['"]?\)/) { "asset-data-url(\"#{Regexp.last_match(1)}\")" }}
41+
end
42+
43+
Sprockets.register_processor "text/css", Sprockets::ScssProcessor
44+
3745
assets = Sprockets::Environment.new do |env|
3846
env.append_path "assets/javascripts"
3947
env.append_path "assets/stylesheets"
48+
env.append_path "public"
4049
env.js_compressor = :uglify
41-
env.css_compressor = :yui
50+
env.css_compressor = :scss
4251
end
4352
assets["application.js"].write_to("public/application.js")
4453
assets["application.css"].write_to("public/application.css")

assets/stylesheets/screen.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ abbr.timeago {
125125
}
126126

127127
a.src_link {
128-
background: url("./magnify.png") no-repeat left 50%;
128+
background: url("magnify.png") no-repeat left 50%;
129129
padding-left: 18px;
130130
}
131131

public/application.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)