-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathRakefile
More file actions
137 lines (114 loc) · 2.98 KB
/
Rakefile
File metadata and controls
137 lines (114 loc) · 2.98 KB
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
$: << "lib"
require 'erb'
require 'account'
require 'pathname'
class WEBSITE
attr_accessor :fox_count
def initialize
@fox_count = 0
@locals = {}
end
def root
Pathname.new File.dirname __FILE__
end
def accounts
Account.import File.open 'ruby-committers.yml'
end
def stylesheet_link_tag ogm
"<style>\n" +
File.read('public/stylesheets/site.css') +
"</style>\n"
end
def get_binding
binding
end
def link_to text, url
"<a href=\"#{url}\">#{h text}</a>".untaint
end
def h string
if string.tainted?
string = ERB::Util.h string
end
string.untaint
end
def image_tag src, attributes = {}
attrs = attributes.map { |k,v|
v = "\"#{h v}\""
[k, v].join "="
}
if attrs.any?
"<img src=\"images/#{src}\" #{attrs.join " "} />".untaint
else
"<img src=\"images/#{src}\" />".untaint
end
end
def render options
partial = options[:partial]
collection = options[:collection]
collection.map { |object|
@locals[partial.to_s] = object
filename = "views/accounts/_#{partial}.html.erb"
erb = ERB.new File.read(filename), 0, '<>-'
erb.filename = filename
erb.result binding
}.join
end
def link_to_service name, service
stringy = service.key.to_s
case service.name
when 'twitter'
link_to name, 'http://twitter.com/' + stringy
when 'friendfeed'
link_to name, 'http://friendfeed.com/' + stringy
when 'mixi'
link_to name, 'http://mixi.jp/show_friend.pl?id=' + stringy
when 'github'
link_to name, 'http://github.com/' + stringy
when 'facebook'
if service.key =~ /^\s*\d+$/
link_to name, 'http://www.facebook.com/profile.php?id=' + stringy
else
link_to name, 'http://www.facebook.com/' + stringy
end
when 'iddy'
link_to name, 'http://iddy.jp/profile/' + stringy
end
end
def method_missing name, *args
super unless @locals.key? name.to_s
@locals[name.to_s]
end
end
require 'net/http'
def make_website
erb = ERB.new File.read('views/layouts/application.html.erb'), 0, '<>-'
ws = WEBSITE.new
binding = ws.get_binding do
fn = 'views/accounts/index.html.erb'
inner = ERB.new File.read(fn), 0, '<>-'
inner.filename = fn
inner.result(ws.get_binding)
end
erb.result(binding)
end
file 'ruby-committers.yml' do
url = URI.parse 'https://raw.github.com/yugui/rubycommitters/master/ruby-committers.yml'
res = Net::HTTP.get_response(url)
File.open('ruby-committers.yml', 'wb') { |f| f.write res.body }
end
file 'public/index.html' => 'ruby-committers.yml' do
File.open('public/index.html', 'wb') { |f| f.write make_website }
end
task :clobber do
rm "public/index.html"
end
task "missing-images" do
need = Dir.entries('public/images/people/photos').sort.map { |x|
x.sub(/\..*$/, '')
}
have = Dir.entries('public/images/people/lines').sort.map { |x|
x.sub(/\..*$/, '')
}
p need - have
end
task :default => 'public/index.html'