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
|
# File 'lib/gemstub.rb', line 53
def gem_spec(&block)
@gem_spec = Gem::Specification.new do |s|
s.name = File.basename(FileUtils.pwd)
s.version = "0.0.1"
s.summary = s.name
s.author = (ENV["USERNAME"] || ENV["USER"])
s.description = "#{s.name} was developed by: #{s.author}"
s.email = ""
s.homepage = ""
s.files = FileList['lib/**/*.*', 'README', 'LICENSE', 'bin/**/*.*']
s.require_paths = ['lib']
s.bindir = 'bin'
s. = ['README', 'LICENSE']
s.has_rdoc = true
yield s
end
Rake::GemPackageTask.new(@gem_spec) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
rm_f FileList['pkg/**/*.*']
end
desc 'regenerate the gemspec'
task :gemspec => [:readme] do
@gem_spec.version = "#{@gem_spec.version}.#{Time.now.strftime('%Y%m%d%H%M%S')}"
File.open(File.join("#{@gem_spec.name}.gemspec"), 'w') {|f| f.puts @gem_spec.to_ruby}
end
desc "Install the gem"
task :install => [:readme, :package] do |t|
sudo = ENV['SUDOLESS'] == 'true' || RUBY_PLATFORM =~ /win32|cygwin/ ? '' : 'sudo'
puts `#{sudo} gem install #{File.join("pkg", @gem_spec.name)}-#{@gem_spec.version}.gem --no-update-sources --no-ri --no-rdoc`
end
desc "Release the gem"
task :release => :install do |t|
gem_pkg = File.join("pkg", "#{@gem_spec.name}-#{@gem_spec.version}.gem")
system "gem push #{gem_pkg}"
begin
ac_path = File.join(ENV["HOME"], ".rubyforge", "auto-config.yml")
if File.exists?(ac_path)
fixed = File.open(ac_path).read.gsub(" ~: {}\n\n", '')
fixed.gsub!(/ !ruby\/object:Gem::Version \? \n.+\n.+\n\n/, '')
puts "Fixing #{ac_path}..."
File.open(ac_path, "w") {|f| f.puts fixed}
end
begin
rf = RubyForge.new
rf.configure
rf.login
rf.add_release(@gem_spec.rubyforge_project, @gem_spec.name, @gem_spec.version, gem_pkg)
rescue Exception => e
if e.message.match("Invalid package_id") || e.message.match("no <package_id> configured for")
puts "You need to create the package!"
rf.create_package(@gem_spec.rubyforge_project, @gem_spec.name)
rf.add_release(@gem_spec.rubyforge_project, @gem_spec.name, @gem_spec.version, gem_pkg)
else
raise e
end
end
rescue Exception => e
if e.message == "You have already released this version."
puts e
else
raise e
end
end
end
task :readme do
txt = File.read(File.join(FileUtils.pwd, 'README.textile'))
plain = File.join(FileUtils.pwd, 'README')
txt.scan(/[\s]@(\S+)@[\s|\.]/).flatten.each do |word|
txt.gsub!("@#{word}@", "<tt>#{word}</tt>")
end
['h1', 'h2', 'h3', 'h4'].each_with_index do |h, i|
txt.scan(/(#{h}.\s)/).flatten.each do |word|
eq = '=' * (i + 1)
txt.gsub!(word, eq)
end
end
['<pre><code>', '</code></pre>'].each do |h|
txt.scan(/(#{h}.*$)/).flatten.each do |word|
txt.gsub!(word, '')
end
end
txt.gsub!("\n\n\n", "\n\n")
File.open(plain, 'w') {|f| f.write txt}
end
end
|