-
Notifications
You must be signed in to change notification settings - Fork 23
/
Rakefile
714 lines (603 loc) · 21.6 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# Maintainer: Chris -- https://github.com/unregistered
require 'pathname'
require 'pry' if ENV["DEBUG"]
PACKAGEMAKER_PATH = '/Applications/Xcode.app/Contents/Applications/PackageMaker.app/Contents/MacOS/PackageMaker'
task :default => [:all]
desc "Does rake -T"
task :help do
sh "rake -T"
end
desc "Cleans out the build directory"
task :clean do
rm_rf "build"
end
desc "Alias for build:all"
task :all => ['build:all']
namespace :install do
desc "Installs for Adium on Mac OS X"
task :adium do
sh "open build/trollicons.AdiumEmoticonset"
puts "Restart Adium".red
end
desc "Installs in iChat.app, requires root"
task :ichat do
sh "sudo cp -R ./build/-trollicons-ichat/ /Applications/iChat.app/Contents/PlugIns/Standard.smileypack/Contents/Resources/"
puts "Restart iChat".red
end
desc "Installs for Colloquy on Mac OS X"
task :colloquy do
sh "cp -R ./build/trollicons.colloquyEmoticons ~/Library/Application\\ Support/Colloquy/Emoticons/"
puts "Restart Colloquy".red
end
end
namespace :build do
desc "Builds all packages we have support for."
task :all => [:adium, :colloquy, :pidgin, :digsby, :gajim, :miranda, :trillian, :ichat, :extension, :psi]
desc "Builds for Adium on OSX"
task :adium do
require 'builder'
puts "\nBuilding for Adium".bold
ri = RIcons.new
#Adium uses an XML file
b = Builder::XmlMarkup.new(:target=>(markup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:adium."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.dict{
b.key "AdiumSetVersion"
b.real "1.3"
b.key "Emoticons"
b.dict{
ri.each_emoticon do |r|
b.key r.cleanpath
b.dict{
b.key "Equivalents"
b.array{
r.aliases.each {|a| b.string "[#{a}]" }
}
b.key "Name"
b.string r.name
}
end
}
}
end
ri.dump_icons_to_folder('trollicons.AdiumEmoticonset')
Pathname.new('./build/trollicons.AdiumEmoticonset/Emoticons.plist').open('w'){|io| io << markup}
end
desc "Builds for Colloquy"
task :colloquy do
require 'builder'
puts "\nBuilding for Colloquy".bold
ri = RIcons.new
#Colloquy uses an XML file Info.plist
b = Builder::XmlMarkup.new(:target=>(infomarkup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:colloquy."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.dict{
b.key "CFBundleDevelopmentRegion"
b.string "English"
b.key "CFBundleGetInfoString"
b.string "Trollicons Colloquy Chat Emoticons"
b.key "CFBundleIdentifier"
b.string "cc.javelin.colloquy.emoticons.trollicons"
b.key "CFBundleInfoDictionaryVersion"
b.string "6.0"
b.key "CFBundleName"
b.string "Trollicons"
b.key "CFBundlePackageType"
b.string "coEm"
}
end
#Colloquy uses an XML file menu.plist
b = Builder::XmlMarkup.new(:target=>(menumarkup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:colloquy."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.array{
ri.each_emoticon do |r|
b.dict{
b.key "image"
b.string r.cleanpath
b.key "insert"
b.string "[" + r.aliases.first + "]"
b.key "name"
b.string r.name
}
end
}
end
#Colloquy uses an XML file emoticons.plist
b = Builder::XmlMarkup.new(:target=>(emoticonsmarkup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:colloquy."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.dict{
ri.each_emoticon do |r|
b.key r.aliases.first
b.array{
r.aliases.each {|a| b.string "[#{a}]" }
}
end
}
end
#Colloquy uses a CSS file emoticons.css
css = ".emoticon samp { display: none; }\n"
css += ".emoticon:after { vertical-align: -25%; }\n"
ri.each_emoticon do |r|
css += ".emoticon." + r.aliases.first + ":after { content: url( \"" + r.cleanpath + "\" ); }\n"
end
ri.dump_icons_to_folder('trollicons.colloquyEmoticons/Contents/Resources')
Pathname.new('./build/trollicons.colloquyEmoticons/Contents/Info.plist').open('w'){|io| io << infomarkup}
Pathname.new('./build/trollicons.colloquyEmoticons/Contents/Resources/menu.plist').open('w'){|io| io << menumarkup}
Pathname.new('./build/trollicons.colloquyEmoticons/Contents/Resources/emoticons.plist').open('w'){|io| io << emoticonsmarkup}
Pathname.new('./build/trollicons.colloquyEmoticons/Contents/Resources/emoticons.css').open('w'){|io| io << css}
end
desc "Builds for iChat"
task :ichat do
require 'builder'
puts "\nBuilding for iChat".bold
next unless file_exists '/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker'
ri = RIcons.new
#iChat uses an XML file
b = Builder::XmlMarkup.new(:target=>(markup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:ichat."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.dict{
b.key "Smileys"
b.array{
ri.each_emoticon do |r|
b.dict{
b.key "ASCII Representations"
b.array{
r.aliases.each {|a| b.string "[#{a}]"}
}
b.key "Image Name"
b.string r.cleanpath
b.key "Description"
b.string r.name
b.key "Speech Description"
b.string "Trollicon #{r.name}"
}
end
}
}
end
ri.dump_icons_to_folder('-trollicons-ichat')
mkdir_p './build/-trollicons-ichat/English.lproj'
Pathname.new('./build/-trollicons-ichat/English.lproj/Smileys.plist').open('w'){|io| io << markup}
# Make a .pkg file
puts "Making a pkg installer".bold
cmd = PACKAGEMAKER_PATH + " "
cmd += "--root ./build/-trollicons-ichat "
cmd += "--out ./build/trollicons-ichat.pkg "
cmd += "--install-to /Applications/iChat.app/Contents/PlugIns/Standard.smileypack/Contents/Resources "
cmd += "--id com.sagargp.trollicons "
cmd += "--title \"Trollicons for iChat\""
sh cmd
# Distribute the uninstaller
puts "Creating uninstaller".bold
cmd = PACKAGEMAKER_PATH + " "
cmd += "--root ./iChat-uninstaller/Resources "
cmd += "--out ./build/trollicons-ichat-uninstaller.pkg "
cmd += "--install-to /Applications/iChat.app/Contents/PlugIns/Standard.smileypack/Contents/Resources "
cmd += "--id com.sagargp.trollicons-uninstaller "
cmd += "--title \"Uninstall Trollicons for iChat\""
sh cmd
end
desc "Builds for Messages.app"
task :imessages do
require 'builder'
puts "\nBuilding for Messages.app".bold
next unless file_exists PACKAGEMAKER_PATH
ri = RIcons.new
#iChat uses an XML file
b = Builder::XmlMarkup.new(:target=>(markup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:ichat."
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
b.plist "version"=>"1.0" do
b.dict{
b.key "Smileys"
b.array{
ri.each_emoticon do |r|
b.dict{
b.key "ASCII Representations"
b.array{
r.aliases.each {|a| b.string "[#{a}]"}
}
b.key "Image Name"
b.string r.cleanpath
b.key "Description"
b.string r.name
b.key "Speech Description"
b.string "Trollicon #{r.name}"
}
end
}
}
end
ri.dump_icons_to_folder('-trollicons-ichat')
mkdir_p './build/-trollicons-ichat/English.lproj'
Pathname.new('./build/-trollicons-ichat/English.lproj/Smileys.plist').open('w'){|io| io << markup}
# Make a .pkg file
puts "Making a pkg installer".bold
cmd = PACKAGEMAKER_PATH + " "
cmd += "--root ./build/-trollicons-ichat "
cmd += "--out ./build/trollicons-ichat.pkg "
cmd += "--install-to /Applications/iChat.app/Contents/PlugIns/Standard.smileypack/Contents/Resources "
cmd += "--id com.sagargp.trollicons "
cmd += "--title \"Trollicons for iChat\""
sh cmd
# Distribute the uninstaller
puts "Creating uninstaller".bold
cmd = PACKAGEMAKER_PATH + " "
cmd += "--root ./iChat-uninstaller/Resources "
cmd += "--out ./build/trollicons-ichat-uninstaller.pkg "
cmd += "--install-to /Applications/iChat.app/Contents/PlugIns/Standard.smileypack/Contents/Resources "
cmd += "--id com.sagargp.trollicons-uninstaller "
cmd += "--title \"Uninstall Trollicons for iChat\""
sh cmd
end
desc "Builds for Pidgin"
task :pidgin do
puts "\nBuilding for Pidgin".bold
#Create markup, from adium2pidgin.py
iconStr = "#################################################\n"
iconStr += "## Auto-generated, run rake build:pidgin ##\n"
iconStr += "# Created by Sagar Pandya (sagargp@gmail.com) #\n"
iconStr += "# www.reddit.com/user/sagarp #\n"
iconStr += "# www.reddit.com/r/fffffffuuuuuuuuuuuu #\n"
iconStr += "## See https://github.com/sagargp/trollicons ##\n"
iconStr += "#################################################\n"
iconStr += "Name=Trollicons\n"
iconStr += "Description=An iconset made out of rage faces from reddit.com's F7U12 sub\n"
iconStr += "Icon=Happy-SoMuchWin.png\n"
iconStr += "Author=Sagar Pandya\n\n"
iconStr += "[default]\n";
ri = RIcons.new.each_emoticon do |r|
iconStr += "#{r.cleanpath} #{r.aliases.collect{|a| "[#{a}]"}.join(' ')}\n"
end
#Write
ri.dump_icons_to_folder('trollicons-pidgin')
Pathname.new('build/trollicons-pidgin/theme').open('w'){|io| io << iconStr}
end
desc "Builds for Digsby"
task :digsby do
puts "\nBuilding for Adium".bold
list = "trollicons\n"
ri = RIcons.new.each_emoticon do |r|
r.aliases.each do |a|
list += "#{r.cleanpath} [#{a}]\n"
end
end
ri.dump_icons_to_folder('trollicons-digsby')
Pathname.new('build/trollicons-digsby/emoticons.txt').open('w'){|io| io << list}
end
desc "Builds for Gajim"
task :gajim do
puts "\nBuilding for Gajim".bold
string = "#Name=\"Trollicons\"\n"
string += "#Description=\"This is the trollicons pack for Gajim. Find it on github.\"\n"
string += "#Icon=\"Happy-SoMuchWin.png\"\n"
string += "#Author=\"Sagar Pandya\"\n\n"
string += "#[default]\n"
string += "emoticons = {"
list = []
ri = RIcons.new.each_emoticon do |r|
list.push("'#{r.cleanpath}': ['#{r.aliases.collect{|a| "[#{a}]"}.join('\', \'')}']")
end
string += list.join(",\n")
string += "}"
ri.dump_icons_to_folder('trollicons-gajim')
Pathname.new('build/trollicons-gajim/emoticons.py').open('w'){|io| io << string}
end
desc "Builds for Miranda"
task :miranda do
puts "\nBuilding for Miranda".bold
string = "Name=\"Trollicons\"\r\n"
string += "Description=\"This is the trollicons pack for Miranda. Find it on github.\"\r\n"
string += "Icon=\"Happy-SoMuchWin.png\"\r\n"
string += "Author=\"Sagar Pandya\"\r\n\r\n"
string += "[default]\r\n"
ri = RIcons.new.each_emoticon do |r|
string += "Smiley = \"#{r.cleanpath}\", 0, \"#{r.aliases.collect{|a| "[#{a}]"}.join(' ')}\"\r\n"
end
ri.dump_icons_to_folder('trollicons-miranda')
Pathname.new('build/trollicons-miranda/Trollicons.msl').open('w'){|io| io << string}
end
desc "Builds for Trillian"
task :trillian do
require 'quick_magick'
require 'builder'
puts "\nBuilding for Trillian".bold
ri = RIcons.new
#Trillian uses an XML file
b = Builder::XmlMarkup.new(:target=>(markup=String.new), :indent=>2)
b.comment! "Auto-generated. Run rake build:trillian. github.com/sagargp/trollicons"
ri.each_emoticon do |r|
b.bitmap :name => r.name, :file => "../../stixe/plugins/trollicons-trillian/icons/#{r.cleanpath}"
end
b.prefs{
b.control :name => "emoticons", :type => "emoticons" do
ri.each_category do |cat|
b.group :text => "#{cat.name};".to_sym, :initial => 0 do
cat.files.each do |r|
r.aliases.each_with_index do |a, i|
# Get image size
image = QuickMagick::Image.open( r.to_s ).first
b.emoticon :text => "[#{a.to_s}]", :button => (i==0 ? "yes" : "") do
b.source :name => r.name, :left => "0", :right => "#{image.width}", :top => "0", :bottom => "#{image.height+10}"
end
end
end
end
end
# Some required stuff
b << "&Emoticon-Extensions;\n"
b << "&iniMenuItemColor;\n"
b << "&iniIconMenuItemSettings;\n"
b.font :name => "selection", :source => 'ttfDefault', :type => '&iniDefaultFontName;'.to_sym, :size => '&iniDefaultFontSize;'.to_sym
end
}
# It also uses a desc.txt file
string = "Trollicons emoticon set built on #{Time.now}\nemot"
ri.dump_icons_to_folder('trollicons-trillian/icons')
#binding.pry
cp ri.files.select{|f| f.aliases.include? 'trollicons'}.first.to_s, "build/trollicons-trillian/emoticon.png" # Header image
cp ri.files.select{|f| f.aliases.include? 'win'}.first.to_s, "build/trollicons-trillian/preview.png" # Header image
preview = QuickMagick::Image.open("build/trollicons-trillian/preview.png").first
preview.save "build/trollicons-trillian/preview.bmp"
rm "build/trollicons-trillian/preview.png"
Pathname.new('./build/trollicons-trillian/main.xml').open('w'){|io| io << markup}
Pathname.new('./build/trollicons-trillian/desc.txt').open('w'){|io| io << string}
end
desc "Builds a Chrome extension/user-script"
task :extension do
require "json"
puts "\nBuilding Chrome extension".bold
next unless file_exists './extension/lib/trollicons.pem'
# open extension/trollicons/manifest.json
# add 0.1 to the version number
manifestFile = File.new("extension/trollicons/manifest.json", "r")
manifest = JSON.parse(manifestFile.read)
manifest['version'] = String((Float(manifest['version']) + 0.1).round(1))
manifestFile.close()
manifestFile = File.new("extension/trollicons/manifest.json", "w")
manifestFile.write(JSON.pretty_generate(manifest))
manifestFile.close()
cmd = "cp -r Icons/ extension/trollicons/img"
cmd += " && \"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\" --pack-extension=extension/trollicons/ --pack-extension-key=extension/lib/trollicons.pem"
system cmd
puts "\nBuilding extension Zip file for upload to Chrome website".bold
cmd = "cd extension/trollicons"
cmd += "&& zip -r ../../build/trollicons-chrome.zip *"
cmd += "&& cd -"
system cmd
puts "\nCleaning up...".bold
cmd = "mv extension/trollicons.crx build/"
cmd += " && rm -rf extension/trollicons/img"
system cmd
end
desc "Builds for Psi"
task :psi do
require 'builder'
puts "\nBuilding for Psi".bold
ri = RIcons.new
#Psi uses an XML file
b = Builder::XmlMarkup.new(:target=>(markup=String.new), :indent=>2)
b.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
b.icondef do
b.meta{
b.name "Trollicons"
b.version "1.3"
b.description "This is the trollicons pack for Psi. Find it on github."
b.home "https://github.com/sagargp/trollicons"
b.author "Sagar Pandya", :email=>"sagargp@gmail.com"
b.creation "#{Time.now.year}-#{Time.now.month}-#{Time.now.day}"
}
ri.each_emoticon do |r|
b.icon{
r.aliases.each {|a| b.text "[#{a}]"}
b.object r.cleanpath, :mime => "image/png"
}
end
end
ri.dump_icons_to_folder('trollicons-psi')
Pathname.new('build/trollicons-psi/icondef.xml').open('w'){|io| io << markup}
end
end
desc "Tweet a message"
task :tweet do
require "rubygems"
require "twitter"
require "json"
auth = JSON.parse(File.new("trolliconsAuth.ignore", "r").read)
print "Type the message: "
STDIN.gets
Twitter.configure do |config|
config.consumer_key = auth['consumer_key']
config.consumer_secret = auth['consumer_secret']
config.oauth_token = auth['oauth_token']
config.oauth_token_secret = auth['oauth_token_secret']
end
client = Twitter::Client.new
client.update $_
end
desc "Checks out submodule of binaries"
task :submodule do
sh "git submodule init"
sh "git submodule update"
end
desc "Packages all folders in build/ for distribution"
task :dist do
mkdir_p 'build'
n = Pathname.new('./build').children.select{|f| f.extname != '.zip' and f.directory? and f.basename.to_s[0] != '-' }.each do |d|
Dir.chdir('./build/') do
sh "zip -r #{d.basename}.zip #{d.basename}"
end
end
if n.count > 0
puts "Done, built #{n.count} packages".green
else
puts "No packages found. Perhaps you'd like to build some?".red
Rake::Task["help"].execute
end
end
desc "Deploys all archives to GitHub"
task :deploy => :submodule do
Dir.chdir('./build') do
Pathname.new('.').each_child.select{|c| c.extname == '.zip'}.each do |f|
mv f.to_s, "../trollicon-binaries/#{f.basename}"
end
end
print "\nNOTE: Chrome extension requires manual upload!\n".red
end
desc "Lists all faces and aliases"
task :doc do
ri = RIcons.new
ri.each_category do |c|
puts "#{c.name}".bold
c.files.each do |r|
print "\t#{r.name} : "
r.aliases.each{|a| print "[#{a}]"}
print "\n"
end
end
end
class RIcons
begin
include Rake::DSL
rescue Exception
end
attr_accessor :files
def initialize
@files = self.get_files
@count = files.count
end
def get_categories
Pathname.new("Icons").children.select{|d| d.directory?}.map{|d| RCategory.new(d)}
end
def get_files(directory="Icons")
puts "Scanning Icon directory"
files = []
Pathname.new(directory).children.each do |f|
if f.directory? # WE NEED TO GO DEEPER
files = files | Pathname.new(f).children.select{|f| (f.extname == '.png' || f.extname == '.gif') }.map{|f| RIcon.new(f).init } # Merge arrays
else
files << RIcon.new(f).init if f.extname == '.png'
end
end
unless files.count
puts "No files found"
return []
end
puts "Processing #{files.count} files.".green
# Process the Trollicons version file
v = files.index(Pathname.new("Icons/Trollicons-trollicons.png"))
files[v].name = " Trollicons (#{files.count} icons) (build date: #{Time.now.month}-#{Time.now.day}-#{Time.now.year})"
files
end
def each_category
get_categories.each do |c|
yield c if block_given?
end
self
end
def each_emoticon
files.each do |f|
yield f if block_given?
end
self
end
def dump_icons_to_folder(folder)
#Check for name collisions
seen = []
files.each do |f|
unless seen.find_index(f.cleanpath)
seen << f.cleanpath
else
puts "Found a naming collision with #{f.cleanpath}. Please resolve it.".red
return
end
end
# Check for alias collisions
c = Hash.new(0)
files.each do |f|
f.aliases.each do |a|
c[a] += 1
puts "Alias collision on #{a} in #{f}".red if c[a] > 1
end
end
#Clean old stuff
rm_rf "build/#{folder}"
mkdir_p "build/#{folder}"
files.each{|f| cp f.to_s, "build/#{folder}/#{f.cleanpath}"}
puts "Moved #{files.count} files.".green
end
end
class RCategory
attr_accessor :name, :path, :files
def initialize(dir)
@path = dir
@name = @path.basename
@files = get_files
puts "Warning: empty category \"#{@name}\"".yellow if @files.empty?
end
def get_files
@path.children.select{|f| f.extname == '.png'}.map{|f| RIcon.new(f).init}
end
end
class RIcon < Pathname
attr_accessor :file, :name, :aliases, :namespace, :cleanpath
def initialize(pathname)
super(pathname)
@file = pathname
end
def init
@aliases = @file.basename.to_s.chomp(@file.extname).split("-")
#extract the face name, now the rest will contain aliases
@name = @aliases.shift
# correct for folders
if @file.to_s =~ /^Icons\/(.*)\/(.*)$/
@namespace = $1
@name = "#{@namespace} - #{@name}"
@cleanpath = @name.gsub(/\!|\?| |'|"/, '') + @file.extname
elsif @file.to_s =~ /^Icons\/(.*)$/
@cleanpath = @name.gsub(/\!|\?| |'|"/, '') + @file.extname
end
self
end
#def basename(*args) Pathname.new(File.basename(@path, *args)) end
end
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def bold
colorize(1)
end
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
end
def file_exists file
t = Pathname.new(file).file?
unless t
puts "#{file} not found. Skipping...".red
end
t
end