Skip to content

Commit af36b51

Browse files
authored
Merge pull request #870 from jmerle/sprites
Automatically generate spritesheets
2 parents 0f9ff40 + 8a71af9 commit af36b51

File tree

18 files changed

+267
-190
lines changed

18 files changed

+267
-190
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ group :app do
2222
gem 'browser'
2323
gem 'sass'
2424
gem 'coffee-script'
25+
gem 'chunky_png'
26+
gem 'sprockets-sass'
2527
end
2628

2729
group :production do

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GEM
1212
erubi (>= 1.0.0)
1313
rack (>= 0.9.0)
1414
browser (2.5.3)
15+
chunky_png (1.3.10)
1516
coderay (1.1.2)
1617
coffee-script (2.4.1)
1718
coffee-script-source
@@ -96,6 +97,8 @@ GEM
9697
rack (> 1, < 3)
9798
sprockets-helpers (1.2.1)
9899
sprockets (>= 2.2)
100+
sprockets-sass (2.0.0.beta2)
101+
sprockets (>= 2.0, < 4.0)
99102
strings (0.1.4)
100103
strings-ansi (~> 0.1.0)
101104
unicode-display_width (~> 1.4.0)
@@ -132,6 +135,7 @@ DEPENDENCIES
132135
activesupport (~> 5.2)
133136
better_errors
134137
browser
138+
chunky_png
135139
coffee-script
136140
erubi
137141
html-pipeline
@@ -153,6 +157,7 @@ DEPENDENCIES
153157
sinatra-contrib
154158
sprockets
155159
sprockets-helpers
160+
sprockets-sass
156161
thin
157162
thor
158163
tty-pager

assets/images/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sprites/**/*

assets/images/docs-1.png

-45.1 KB
Binary file not shown.

assets/images/[email protected]

-119 KB
Binary file not shown.

assets/images/docs-2.png

-19.6 KB
Binary file not shown.

assets/images/[email protected]

-47.5 KB
Binary file not shown.

assets/stylesheets/application.css.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//= depend_on docs-1.png
2-
//= depend_on [email protected]
3-
//= depend_on docs-2.png
4-
//= depend_on [email protected]
1+
//= depend_on sprites/docs.png
2+
//= depend_on sprites/[email protected]
3+
//= depend_on sprites/docs.json
54

65
/*!
76
* Copyright 2013-2019 Thibaut Courouble and other contributors

assets/stylesheets/global/_icons.scss

Lines changed: 0 additions & 182 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<% manifest = JSON.parse(File.read('assets/images/sprites/docs.json')) %>
2+
3+
%svg-icon {
4+
display: inline-block;
5+
vertical-align: top;
6+
width: 1rem;
7+
height: 1rem;
8+
pointer-events: none;
9+
fill: currentColor;
10+
}
11+
12+
%doc-icon {
13+
content: '';
14+
display: block;
15+
width: 1rem;
16+
height: 1rem;
17+
background-image: image-url('sprites/docs.png');
18+
background-size: <%= manifest['icons_per_row'] %>rem <%= manifest['icons_per_row'] %>rem;
19+
}
20+
21+
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
22+
%doc-icon { background-image: image-url('sprites/[email protected]'); }
23+
}
24+
25+
html._theme-dark {
26+
%darkIconFix {
27+
filter: invert(100%) grayscale(100%);
28+
-webkit-filter: invert(100%) grayscale(100%);
29+
}
30+
}
31+
32+
<%=
33+
items = []
34+
35+
manifest['items'].each do |item|
36+
rules = []
37+
rules << "background-position: -#{item['col']}rem -#{item['row']}rem;"
38+
rules << "@extend %darkIconFix !optional;" if item['dark_icon_fix']
39+
items << "._icon-#{item['type']}:before { #{rules.join(' ')} }"
40+
end
41+
42+
items.join('')
43+
%>

0 commit comments

Comments
 (0)