forked from sagargp/trollicons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
355 lines (296 loc) · 10.4 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
# Maintainer: Chris -- https://github.com/unregistered
require 'pathname'
#require 'pry'
#require 'RMagick'
task :default => [:help]
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
`open build/trollicons.AdiumEmoticonset`
puts "Restart Adium".red
end
end
namespace :build do
desc "Builds all packages we have support for."
task :all => [:adium, :pidgin, :digsby, :miranda, :trillian, :extension]
desc "Builds for Adium on OSX"
task :adium do
require 'builder'
puts "\nBuilding for Adium".bold
A = 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{
A.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
A.dump_icons_to_folder('trollicons.AdiumEmoticonset')
Pathname.new('./build/trollicons.AdiumEmoticonset/Emoticons.plist').open('w'){|io| io << markup}
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";
P = RIcons.new.each_emoticon do |r|
iconStr += "#{r.cleanpath} #{r.aliases.collect{|a| "[#{a}]"}.join(' ')}\n"
end
#Write
P.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"
D = RIcons.new.each_emoticon do |r|
r.aliases.each do |a|
list += "#{r.cleanpath} [#{a}]\n"
end
end
D.dump_icons_to_folder('trollicons-digsby')
Pathname.new('build/trollicons-digsby/emoticons.txt').open('w'){|io| io << list}
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"
M = RIcons.new.each_emoticon do |r|
string += "Smiley = \"#{r.cleanpath}\", 0, \"#{r.aliases.collect{|a| "[#{a}]"}.join(' ')}\"\r\n"
end
M.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 'RMagick'
require 'builder'
puts "\nBuilding for Trillian".bold
T = RIcons.new
#Adium 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"
T.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
#<group text="&wordBasicSmileys;" initial="1">
b.group :text => '&wordBasicSmileys;'.to_sym, :initial => 1 do
T.each_emoticon do |r|
r.aliases.each_with_index do |a, i|
# Get image size
image = Magick::Image.read( r.to_s ).first
b.emoticon :text => "[#{a.to_s}]", :button => (i==0 ? "yes" : "") do
b.source :name => r.name, :left => "0", :right => "#{image.columns}", :top => "0", :bottom => "#{image.rows+10}"
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"
T.dump_icons_to_folder('trollicons-trillian/icons')
#binding.pry
cp T.files.select{|f| f.aliases.include? 'trollicons'}.first.to_s, "build/trollicons-trillian/emoticon.png" # Header image
cp T.files.select{|f| f.aliases.include? 'win'}.first.to_s, "build/trollicons-trillian/preview.png" # Header image
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
puts "\nBuilding browser extension".bold
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
end
desc "Deploys all archives to github"
task :deploy => [:clean, 'build:all', :dist] do
require 'net/github-upload'
login = `git config github.user`.chomp # your login for github
token = `git config github.token`.chomp # your token for github
repos = 'sagargp/trollicons' # your repos name (like 'taberareloo')
gh = Net::GitHub::Upload.new(
:login => login,
:token => token
)
gh.delete_all repos
Pathname.new('./build').each_child.select{|c| c.extname == '.zip'}.each do |f|
puts "Uploading #{f.to_s} to github"
gh.upload(
:repos => repos,
:file => f.to_s,
:description => "#{f.basename} - Auto-uploaded from Rake. See Readme for which file to download."
)
end
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? }.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
class RIcons
begin
include Rake::DSL
rescue Exception
end
attr_accessor :files
def initialize
@files = self.get_files
@count = files.count
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' }.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_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 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 bold
return "\e[1m#{self}\e[0m"
end
def red
return "\e[31m#{self}\e[0m"
end
def green
return "\e[32m#{self}\e[0m"
end
end