forked from activeldap/activeldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
310 lines (270 loc) · 9.22 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
# -*- ruby -*-
require 'thread'
require 'find'
require 'rubygems'
require 'bundler/setup'
require 'jeweler'
require 'rake/testtask'
require "rake/clean"
require "yard"
$KCODE = "u" if RUBY_VERSION < "1.9"
base_dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(base_dir, 'lib'))
require 'active_ldap'
project_name = "ActiveLdap"
ENV["VERSION"] ||= ActiveLdap::VERSION
version = ENV["VERSION"]
spec = nil
Jeweler::Tasks.new do |_spec|
spec = _spec
spec.name = 'activeldap'
spec.version = version.dup
spec.rubyforge_project = 'ruby-activeldap'
spec.authors = ['Will Drewry', 'Kouhei Sutou']
spec.email = ['redpig@dataspill.org', 'kou@cozmixng.org']
spec.summary = 'ActiveLdap is a object-oriented API to LDAP'
spec.homepage = 'http://ruby-activeldap.rubyforge.org/'
spec.files = FileList["lib/**/*",
"{benchmark,examples,po}/**/*",
"bin/*",
"doc/text/**/*",
"COPYING",
"Gemfile",
"LICENSE",
"README.textile",
"TODO"]
spec.test_files = FileList['test/test_*.rb']
spec.description = <<-EOF
'ActiveLdap' is a ruby library which provides a clean
objected oriented interface to the Ruby/LDAP library. It was inspired
by ActiveRecord. This is not nearly as clean or as flexible as
ActiveRecord, but it is still trivial to define new objects and manipulate
them with minimal difficulty.
EOF
spec.license = "Ruby's or GPLv2 or later"
end
Rake::Task["release"].prerequisites.clear
Jeweler::RubygemsDotOrgTasks.new do
end
Rake::TestTask.new(:test) do |test|
test.libs << "lib"
test.libs << "test"
test.pattern = "test/**/test_*.rb"
end
begin
require "gettext_i18n_rails/tasks"
rescue LoadError
puts "gettext_i18n_rails is not installed, you probably should run 'rake gems:install' or 'bundle install'."
end
reference_base_dir = Pathname.new("doc/reference")
doc_en_dir = reference_base_dir + "en"
html_base_dir = Pathname.new("doc/html")
html_reference_dir = html_base_dir + spec.name
YARD::Rake::YardocTask.new do |task|
task.options += ["--title", project_name]
task.options += ["--charset", "UTF-8"]
task.options += ["--readme", "README.textile"]
task.options += ["--files", "doc/text/**/*"]
task.options += ["--output-dir", doc_en_dir.to_s]
task.options += ["--charset", "utf-8"]
template_files = FileList["lib/rails/generators/**/templates/*.rb"]
task.files += FileList["lib/**/*.rb"] - template_files - ["README.textile"]
end
task :yard do
doc_en_dir.find do |path|
next if path.extname != ".html"
html = path.read
html = html.gsub(/<div id="footer">.+<\/div>/m,
"<div id=\"footer\"></div>")
path.open("w") do |html_file|
html_file.print(html)
end
end
end
include ERB::Util
def apply_template(content, paths, templates, project_name, language)
content = content.sub(/lang="en"/, "lang=\"#{language}\"")
title = nil
content = content.sub(/<title>(.+?)<\/title>/m) do
title = $1
templates[:head].result(binding)
end
content = content.sub(/<body(?:.*?)>/) do |body_start|
"#{body_start}\n#{templates[:header].result(binding)}\n"
end
content = content.sub(/<\/body/) do |body_end|
"\n#{templates[:footer].result(binding)}\n#{body_end}"
end
content
end
def erb_template(name)
file = File.join("doc/templates", "#{name}.html.erb")
template = File.read(file)
erb = ERB.new(template, nil, "-")
erb.filename = file
erb
end
def rsync_to_rubyforge(spec, source, destination, options={})
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
host = "#{config["username"]}@rubyforge.org"
rsync_args = "-av --exclude '*.erb' --chmod=ug+w"
rsync_args << " --delete" if options[:delete]
remote_dir = "/var/www/gforge-projects/#{spec.rubyforge_project}/"
sh("rsync #{rsync_args} #{source} #{host}:#{remote_dir}#{destination}")
end
def rake(*arguments)
ruby($0, *arguments)
end
namespace :reference do
translate_languages = [:ja]
supported_languages = [:en, *translate_languages]
html_files = FileList["#{doc_en_dir}/**/*.html"].to_a
directory reference_base_dir.to_s
CLOBBER.include(reference_base_dir.to_s)
po_dir = "doc/po"
pot_file = "#{po_dir}/#{spec.name}.pot"
namespace :pot do
directory po_dir
file pot_file => [po_dir, *html_files] do |t|
sh("xml2po", "--keep-entities", "--output", t.name, *html_files)
end
desc "Generates pot file."
task :generate => pot_file
end
namespace :po do
translate_languages.each do |language|
namespace language do
po_file = "#{po_dir}/#{language}.po"
if File.exist?(po_file)
file po_file => html_files do |t|
sh("xml2po", "--keep-entities", "--update", t.name, *html_files)
end
else
file po_file => pot_file do |t|
sh("msginit",
"--input", pot_file,
"--output-file", t.name,
"--locale", language.to_s)
end
end
desc "Updates po file for #{language}."
task :update => po_file
end
end
desc "Updates po files."
task :update do
ruby($0, "clobber")
ruby($0, "yard")
translate_languages.each do |language|
ruby($0, "reference:po:#{language}:update")
end
end
end
namespace :translate do
translate_languages.each do |language|
po_file = "#{po_dir}/#{language}.po"
translate_doc_dir = "#{reference_base_dir}/#{language}"
desc "Translates documents to #{language}."
task language => [po_file, reference_base_dir, *html_files] do
commands = []
doc_en_dir.find do |path|
base_path = path.relative_path_from(doc_en_dir)
translated_path = "#{translate_doc_dir}/#{base_path}"
if path.directory?
mkdir_p(translated_path)
next
end
case path.extname
when ".html"
command = "xml2po --keep-entities " +
"--po-file #{po_file} --language #{language} " +
"#{path} > #{translated_path} &"
commands << command
else
cp(path.to_s, translated_path, :preserve => true)
end
end
commands << "wait"
sh(commands.join("\n"))
end
end
end
translate_task_names = translate_languages.collect do |language|
"reference:translate:#{language}"
end
desc "Translates references."
task :translate => translate_task_names
desc "Generates references."
task :generate => [:yard, :translate]
namespace :publication do
task :prepare do
supported_languages.each do |language|
raw_reference_dir = reference_base_dir + language.to_s
prepared_reference_dir = html_reference_dir + language.to_s
rm_rf(prepared_reference_dir.to_s)
head = erb_template("head.#{language}")
header = erb_template("header.#{language}")
footer = erb_template("footer.#{language}")
raw_reference_dir.find do |path|
relative_path = path.relative_path_from(raw_reference_dir)
prepared_path = prepared_reference_dir + relative_path
if path.directory?
mkdir_p(prepared_path.to_s)
else
case path.basename.to_s
when /(?:file|method|class)_list\.html\z/
cp(path.to_s, prepared_path.to_s)
when /\.html\z/
relative_dir_path = relative_path.dirname
current_path = relative_dir_path + path.basename
if current_path.basename.to_s == "index.html"
current_path = current_path.dirname
end
top_path = html_base_dir.relative_path_from(prepared_path.dirname)
paths = {
:top => top_path,
:current => current_path,
}
templates = {
:head => head,
:header => header,
:footer => footer
}
content = apply_template(File.read(path.to_s),
paths,
templates,
spec.name,
language)
File.open(prepared_path.to_s, "w") do |file|
file.print(content)
end
else
cp(path.to_s, prepared_path.to_s)
end
end
end
end
File.open("#{html_reference_dir}/.htaccess", "w") do |file|
file.puts("RedirectMatch permanent ^/#{spec.name}/$ " +
"#{spec.homepage}#{spec.name}/en/")
end
end
end
desc "Upload document to rubyforge."
task :publish => [:generate, "reference:publication:prepare"] do
rsync_to_rubyforge(spec, "#{html_reference_dir}/", spec.name)
end
end
namespace :html do
desc "Publish HTML to Web site."
task :publish do
rsync_to_rubyforge(spec, "#{html_base_dir}/", "")
end
end
desc "Upload document and HTML to rubyforge."
task :publish => ["html:publish", "reference:publish"]
desc "Tag the current revision."
task :tag do
sh("git", "tag", "-a", version, "-m", "release #{version}!!!")
end
# vim: syntax=ruby