-
Notifications
You must be signed in to change notification settings - Fork 13
/
Rakefile
117 lines (90 loc) · 2.86 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new('test:units') do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/units/**/*_test.rb']
t.warning = false
end
Rake::TestTask.new('test:pdf') do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/pdf/*/test_case.rb']
t.warning = false
end
desc 'Run all unit and pdf tests'
task test: %i( test:units test:pdf )
namespace :emoji do
desc 'Update emoji > rake emoji:update VERSION=0.0.0'
task update: %i(
clean_all
twemoji:load
update_index
twemoji:update_version
)
desc 'Update emoji/index.yml from emoji/images'
task :update_index do
require 'prawn/emoji'
require 'yaml'
emoji_files = Prawn::Emoji.root.join('emoji', 'images', '*.png')
emoji_names = Pathname.glob(emoji_files).map { |f| f.basename('.png').to_s }
index_file = Prawn::Emoji.root.join('emoji', 'index.yml')
index_file.write emoji_names.sort.to_yaml
puts 'Updated index.yml'
end
desc 'Clean all emojis'
task :clean_all do
require 'prawn/emoji'
require 'fileutils'
FileUtils.rm(Prawn::Emoji.root.join('emoji', 'images').glob('*.png'))
puts 'Cleaned'
end
namespace :twemoji do
desc 'Load and put github.com/twitter/twemoji/assets/72x72/*.png to the emoji/images/'
task :load do
require 'prawn/emoji'
require 'open-uri'
require 'zip'
require 'tempfile'
target_version = ENV['VERSION']
image_dir = Prawn::Emoji.root.join('emoji', 'images')
puts "Loading source of v#{target_version} from github.com/twitter/twemoji ..."
source_zip = Tempfile.open do |t|
t.binmode
t.write URI.open("https://github.com/twitter/twemoji/archive/v#{target_version}.zip").read
t
end
puts 'Loaded'
Zip::File.open(source_zip.path) do |source|
emojis = source.glob("twemoji-#{target_version}/assets/72x72/*.png")
puts "Saving #{emojis.size} emoji files..."
emojis.each do |image|
emoji_name = EmojiName.new(File.basename(image.name))
image_dir.join(emoji_name.name).binwrite(image.get_input_stream.read)
end
end
end
desc 'Update version in LICENSE file'
task :update_version do
require 'prawn/emoji'
license_file = Prawn::Emoji.root.join('emoji', 'LICENSE')
license_file.write("Twemoji #{ENV['VERSION']} Graphics licensed under CC-BY4.0.")
puts 'Updated LICENSE'
end
class EmojiName
attr_reader :original_name
def initialize(original_name)
@original_name = original_name
end
def name
@name ||= convert
end
private
def convert
codepoints = original_name.gsub('.png', '').split('-')
Prawn::Emoji::Char.format_codepoint(codepoints) + '.png'
end
end
end
end