Skip to content

Commit

Permalink
Generate emoji from css instead of image files
Browse files Browse the repository at this point in the history
* Split create new stylesheet for emoji size classes
* Add class name underneath emojis
  • Loading branch information
Anule Ndukwu committed Jan 25, 2019
1 parent ccda263 commit a8694bc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 49 deletions.
Binary file added app/assets/images/emojis/1f44d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions app/assets/stylesheets/atoms/_emoji-specs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.emoji {
display: inline-block;
text-indent: -9999px;
height: 1em;
width: 1em;
content: '';
background-size: 100% auto;
position: relative;
background-repeat: no-repeat;
}

.emoji--inline {
top: .2em;
}

.emoji--huge {
width: 6em;
height: 6em;
}

.emoji--bigger {
width: 4em;
height: 4em;
}

.emoji--big {
width: 3em;
height: 3em;
}

.emoji--med {
width: 2.4em;
height: 2.4em;
}

.emoji--small {
width: 1.8em;
height: 1.8em;
}
40 changes: 0 additions & 40 deletions app/assets/stylesheets/atoms/_emoji.scss
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
.emoji {
display: inline-block;
text-indent: -9999px;
height: 1em;
width: 1em;
content: '';
background-size: 100% auto;
position: relative;
background-repeat: no-repeat;
}

.emoji--inline {
top: .2em;
}

.emoji--huge {
width: 6em;
height: 6em;
}

.emoji--bigger {
width: 4em;
height: 4em;
}

.emoji--big {
width: 3em;
height: 3em;
}

.emoji--med {
width: 2.4em;
height: 2.4em;
}

.emoji--small {
width: 1.8em;
height: 1.8em;
}

.emoji--grinning-face {
background-image: image-url('emojis/1f600.png');
}
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/cfa_styleguide_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@import 'atoms/example';
@import 'atoms/icons';
@import 'atoms/emoji';
@import 'atoms/emoji-specs';
@import 'atoms/images';
@import 'atoms/illustrations';
@import 'atoms/layout';
Expand Down
21 changes: 17 additions & 4 deletions app/controllers/cfa/styleguide/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ def form_builder
end

def emojis
@emojis = Dir.chdir(File.expand_path('../../../assets/images', File.dirname(__FILE__))) do
Dir.glob('emojis/*')
classes = Dir.chdir(File.expand_path('../../../assets/stylesheets/atoms', File.dirname(__FILE__))) do
File.read('_emoji.scss').scan(/\.(\S*) {.*/)
end
@emoji_pairs = Dir.chdir(File.expand_path('../../../assets/images/', File.dirname(__FILE__))) do
Dir.glob('emoji_pairs/*')
emojis = []
emoji_pairs = []

classes.each do |c|
if c[0].include?('emoji-pair')
emoji_pairs.push(c[0])
else
emojis.push(c[0])
end
end

emojis
emoji_pairs

@emojis = emojis
@emoji_pairs = emoji_pairs
end
end
end
Expand Down
13 changes: 8 additions & 5 deletions app/views/cfa/styleguide/pages/emojis.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% content_for(:template_name) { "styleguide" } %>
<%#= stylesheet_link_tag "atoms/_emojis" %>

<section class="slab slab--styleguide" id="atoms">
<div class="grid">
Expand Down Expand Up @@ -28,9 +29,10 @@
</div>
<div class="grid__item width-three-fourths">
<div class="grid">
<% @emojis.each do |path| %>
<% @emojis.each do |c| %>
<div class="grid__item width-one-sixth">
<%= image_tag path, class: "emoji--big" %>
<div class="emoji emoji--big <%= "#{c}" %>"></div>
<p><%= c %></p>
</div>
<% end %>
</div>
Expand All @@ -45,9 +47,10 @@
</div>
<div class="grid__item width-three-fourths">
<div class="grid">
<% @emoji_pairs.each do |path| %>
<div class="grid__item width-one-sixth">
<%= image_tag path, class: "emoji--big" %>
<% @emoji_pairs.each do |c| %>
<div class="grid__item width-one-fourth">
<div class="emoji emoji--big <%= "#{c}" %>"></div>
<p><%= c %></p>
</div>
<% end %>
</div>
Expand Down

0 comments on commit a8694bc

Please sign in to comment.