Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emojis:generate_borders Rake task #13773

Merged
merged 10 commits into from
Jun 8, 2020
42 changes: 42 additions & 0 deletions lib/tasks/emojis.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# frozen_string_literal: true

def gen_border(codepoint)
input = Rails.root.join('public', 'emoji', "#{codepoint}.svg")
dest = Rails.root.join('public', 'emoji', "#{codepoint}_border.svg")
doc = File.open(input) { |f| Nokogiri::XML(f) }
svg = doc.at_css('svg')
if svg.key?('viewBox')
view_box = svg['viewBox'].split(' ').map(&:to_i)
view_box[0] -= 2
view_box[1] -= 2
view_box[2] += 4
view_box[3] += 4
svg['viewBox'] = view_box.join(' ')
end
g = Nokogiri::XML::Node.new 'g', doc
doc.css('svg > *').each do |elem|
border_elem = elem.dup

border_elem.delete('fill')
border_elem['stroke'] = 'white'

style = border_elem['style'] || ''
old_width = border_elem['stroke-width'] || '0px'
style += " stroke-width: calc(#{old_width} + 4px)"
border_elem['style'] = style.strip

g.add_child(border_elem)
end
svg.prepend_child(g)
File.write(dest, doc.to_xml)
puts "Wrote bordered #{codepoint}.svg to #{dest}!"
end

def codepoints_to_filename(codepoints)
codepoints.downcase.gsub(/\A[0]+/, '').tr(' ', '-')
end
Expand All @@ -23,8 +55,10 @@ namespace :emojis do

HTTP.get(source).to_s.split("\n").each do |line|
next if line.start_with? '#'

parts = line.split(';').map(&:strip)
next if parts.size < 2

codes << [parts[0], parts[1].start_with?('fully-qualified')]
end

Expand Down Expand Up @@ -55,4 +89,12 @@ namespace :emojis do
File.write(dest, Oj.dump(map))
puts "Wrote emojo to destination! (#{dest})"
end

desc 'Generate emoji variants with white borders'
task :generate_borders do
codepoints = %w(1f3b1 1f41c 1f519 26ab 1f5a4 2b1b 25fe 25fc 2712 25aa 1f4a3 1f3b3 1f464 1f465 1f4f7 1f4f8 2663 27b0 1f4b1 1f576 2734 1f50c 1f51a 1f482-200d-2640-fe0f 1f482-1f3fb-200d-2640-fe0f 1f482-1f3fc-200d-2640-fe0f 1f482-1f3fd-200d-2640-fe0f 1f482-1f3fe-200d-2640-fe0f 1f482-1f3ff-200d-2640-fe0f 1f4fd 1f373 1f98d 1f482 1f482-1f3fb 1f482-1f3fc 1f482-1f3fd 1f482-1f3fe 1f482-1f3ff 2714 2797 1f4b2 2796 2716 2795 1f52a 1f573 1f579 1f54b 1f58a 1f58b 1f482-200d-2642-fe0f 1f482-1f3fb-200d-2642-fe0f 1f482-1f3fc-200d-2642-fe0f 1f482-1f3fd-200d-2642-fe0f 1f482-1f3fe-200d-2642-fe0f 1f482-1f3ff-200d-2642-fe0f 1f3a4 1f393 1f3a5 1f3bc 1f51b 1f51c 2660 1f5e3 1f577 1f4de 2122 1f51d 1f3a9 1f983 1f4fc 1f4f9 1f3ae 1f403 1f3f4 3030)
codepoints.each do |cc|
gen_border cc
end
end
end
13 changes: 13 additions & 0 deletions public/emoji/1f373_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions public/emoji/1f393_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/emoji/1f3a4_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions public/emoji/1f3a5_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/emoji/1f3a9_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions public/emoji/1f3ae_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/emoji/1f3b1_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions public/emoji/1f3b3_border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading