forked from holidays/holidays
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrakefile.rb
150 lines (121 loc) · 4.24 KB
/
rakefile.rb
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
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'yaml'
require 'fileutils'
require 'lib/holidays'
require 'data/build_defs'
desc 'Run all tests'
task :test => ["test:lib", "test:defs"]
namespace :test do
desc 'Run the unit tests.'
Rake::TestTask.new(:lib) do |t|
t.libs << 'lib'
t.test_files = FileList['test/defs/test*.rb'].exclude('test_helper.rb')
t.verbose = false
end
desc 'Run the definition tests.'
Rake::TestTask.new(:defs) do |t|
t.libs << 'lib'
t.test_files = FileList['test/test*.rb'].exclude('test_helper.rb')
t.verbose = false
end
end
task :doc => ["defs:manifest", :rdoc]
desc 'Generate documentation.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = 'Ruby Holidays Gem'
rdoc.options << '--all' << '--inline-source' << '--line-numbers'
rdoc.options << '--charset' << 'utf-8'
#rdoc.template = 'extras/rdoc_template.rb'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('data/SYNTAX')
rdoc.rdoc_files.include('lib/holidays/MANIFEST')
rdoc.rdoc_files.include('REFERENCES')
rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('LICENSE')
rdoc.rdoc_files.include('lib/*.rb')
end
spec = Gem::Specification.new do |s|
s.name = 'holidays'
s.version = '0.9.4'
s.author = 'Alex Dunae'
s.homepage = 'http://code.dunae.ca/holidays'
s.platform = Gem::Platform::RUBY
s.description = <<-EOF
A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!
EOF
s.summary = 'A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!'
s.files = FileList["{lib}/**/*", "{data}/**/*", "*.rb"].to_a
s.test_files = FileList['test/defs/test*.rb'].exclude('test_helper.rb')
s.has_rdoc = true
s.extra_rdoc_files = ['README.rdoc', 'data/SYNTAX', 'lib/holidays/MANIFEST', 'REFERENCES', 'CHANGELOG', 'LICENSE']
end
desc 'Build the gem.'
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
end
desc 'Definition file tasks'
namespace :defs do
DATA_PATH = 'data'
desc 'Create the gem spec'
task :create_gemspec do
File.open("holidays.gemspec","w") do |file|
file.puts <<-EOH
# Auto-generated gemspec
Gem::Specification.new do |s|
s.name = "holidays"
s.version = "0.9.4"
s.date = "2008-12-29"
s.summary = "A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!"
s.email = "[email protected]"
s.homepage = "http://code.dunae.ca/holidays"
s.description = "A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!"
s.has_rdoc = true
s.author = "Alex Dunae"
s.extra_rdoc_files = ['README.rdoc', 'data/SYNTAX', 'lib/holidays/MANIFEST', 'REFERENCES', 'CHANGELOG', 'LICENSE']
s.rdoc_options << '--all' << '--inline-source' << '--line-numbers' << '--charset' << 'utf-8'
EOH
file.puts " s.test_files = ['" + Dir.glob("{test}/**/*").join("','") + "']"
file.puts " s.files = ['" + Dir.glob("{data,lib,test}/**/*").join("','") + "']"
file.puts 'end'
end
end
desc 'Build holiday definition files'
task :build_all do
# load the index
def_index = YAML.load_file("#{DATA_PATH}/index.yaml")
# create a dir for the generated tests
FileUtils.mkdir_p('test/defs')
def_index['defs'].each do |region, files|
puts "Building #{region} definition module:"
files = files.collect { |f| "#{DATA_PATH}/#{f}" }
files.uniq!
module_src, test_src = parse_holiday_defs(region, files)
File.open("lib/holidays/#{region.downcase.to_s}.rb","w") do |file|
file.puts module_src
end
unless test_src.empty?
File.open("test/defs/test_defs_#{region.downcase.to_s}.rb","w") do |file|
file.puts test_src
end
end
puts "Done.\n\n"
end
end
desc 'Build the definition manifest.'
task :manifest do
File.open("lib/holidays/MANIFEST","w") do |file|
file.puts <<-EOH
==== Regional definitions
The following definition files are included in this installation:
EOH
FileList.new('lib/holidays/*.rb').each do |str|
file.puts('* ' + str.gsub(/^lib\/|\.rb$/, ''))
end
end
end
end