-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·66 lines (48 loc) · 2.02 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
require 'nokogiri'
require 'open-uri'
cheatsheet_url = 'https://github.com/driftyco/ionicons/raw/master/cheatsheet.html'
font_url = 'https://github.com/driftyco/ionicons/raw/master/fonts/ionicons.ttf'
task :default => [:update]
desc "Updates the ionicons-codes.h file with the latest codes"
task :updateCodes do
doc = Nokogiri::HTML(open(cheatsheet_url))
version = doc.css('title')[0].text.gsub(/ Cheatsheet/, "")
updateReadme(version)
updatePodspec(version)
# update the icon codes
codes_file = File.open('ionicons/ionicon.swift', 'a')
codes_file.puts("public enum ionicon: String {")
doc.css('div.icon-row').each do |icon_row|
icon_name = icon_row.css('div.preview-icon span.size-12 i')[0]["class"][5..-1].split('-')
icon_name.delete('ion')
icon_name = icon_name.map(&:capitalize).join('').gsub('Ios', 'iOS').gsub('Ip', 'iP')
icon_code = icon_row.css('div.usage input.css')[0]['value'].gsub('\\', '')
definition = "\tcase #{icon_name} = \"\\u{#{icon_code}}\""
codes_file.puts(definition)
end
codes_file.puts("}")
codes_file.close()
end
desc "Updates to the lastest ionicons font file"
task :updateFont do
File.open('ionicons/ionicons.ttf', 'wb') do |file|
file.write open(font_url).read
end
end
def updateReadme(version)
text = File.read('README.md')
new_contents = text.gsub(/Currently using.*$/, "Currently using #{version}")
readme_file = File.open('ionicons/README.md', 'w') { |file| file.puts new_contents }
end
def updatePodspec(version)
version = version.delete('^0-9\.')
text = File.read('IoniconsSwift.podspec')
text = text.gsub( /s.version = \".*\"/, "s.version = \"#{version}\"")
text = text.gsub(/:tag =>.*\"/, ":tag => \"#{version}\"")
podspec_file = File.open('IoniconsSwift.podspec', 'w') { |file| file.puts text }
end
desc "Updates to the latest ionicons font file and updates the ionicons-codes.h with the latest codes"
task :update do
Rake::Task[:updateCodes].execute
Rake::Task[:updateFont].execute
end