Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 12864 Bytes
1 | require 'rubygems' |
2 | require 'rake' |
3 | |
4 | # ----- Utility Functions ----- |
5 | |
6 | def scope(path) |
7 | File.join(File.dirname(__FILE__), path) |
8 | end |
9 | |
10 | # ----- Benchmarking ----- |
11 | |
12 | desc <<END |
13 | Benchmark haml against ERb. |
14 | TIMES=n sets the number of runs. Defaults to 1000. |
15 | END |
16 | task :benchmark do |
17 | sh "ruby test/benchmark.rb #{ENV['TIMES']}" |
18 | end |
19 | |
20 | # ----- Default: Testing ------ |
21 | |
22 | if ENV["RUN_CODE_RUN"] == "true" |
23 | task :default => :"test:rails_compatibility" |
24 | else |
25 | task :default => :test |
26 | end |
27 | |
28 | require 'rake/testtask' |
29 | |
30 | Rake::TestTask.new do |t| |
31 | t.libs << 'lib' |
32 | test_files = FileList[scope('test/**/*_test.rb')] |
33 | test_files.exclude(scope('test/rails/*')) |
34 | test_files.exclude(scope('test/plugins/*')) |
35 | test_files.exclude(scope('test/haml/spec/*')) |
36 | t.test_files = test_files |
37 | t.verbose = true |
38 | end |
39 | Rake::Task[:test].send(:add_comment, <<END) |
40 | To run with an alternate version of Rails, make test/rails a symlink to that version. |
41 | END |
42 | |
43 | # ----- Packaging ----- |
44 | |
45 | require 'rake/gempackagetask' |
46 | load scope('haml.gemspec') |
47 | |
48 | Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg| |
49 | if Rake.application.top_level_tasks.include?('release') |
50 | pkg.need_tar_gz = true |
51 | pkg.need_tar_bz2 = true |
52 | pkg.need_zip = true |
53 | end |
54 | end |
55 | |
56 | task :revision_file do |
57 | require 'lib/haml' |
58 | |
59 | release = Rake.application.top_level_tasks.include?('release') || File.exist?(scope('EDGE_GEM_VERSION')) |
60 | if Haml.version[:rev] && !release |
61 | File.open(scope('REVISION'), 'w') { |f| f.puts Haml.version[:rev] } |
62 | elsif release |
63 | File.open(scope('REVISION'), 'w') { |f| f.puts "(release)" } |
64 | else |
65 | File.open(scope('REVISION'), 'w') { |f| f.puts "(unknown)" } |
66 | end |
67 | end |
68 | Rake::Task[:package].prerequisites.insert(0, :revision_file) |
69 | |
70 | # We also need to get rid of this file after packaging. |
71 | at_exit { File.delete(scope('REVISION')) rescue nil } |
72 | |
73 | desc "Install Haml as a gem." |
74 | task :install => [:package] do |
75 | sudo = RUBY_PLATFORM =~ /win32|mingw/ ? '' : 'sudo' |
76 | gem = RUBY_PLATFORM =~ /java/ ? 'jgem' : 'gem' |
77 | sh %{#{sudo} #{gem} install --no-ri pkg/haml-#{File.read(scope('VERSION')).strip}} |
78 | end |
79 | |
80 | desc "Release a new Haml package to Rubyforge." |
81 | task :release => [:check_release, :release_elpa, :package] do |
82 | name = File.read(scope("VERSION_NAME")).strip |
83 | version = File.read(scope("VERSION")).strip |
84 | sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem} |
85 | sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz} |
86 | sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2} |
87 | sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip} |
88 | sh %{gem push pkg/haml-#{version}.gem} |
89 | end |
90 | |
91 | # Releases haml-mode.el and sass-mode.el to ELPA. |
92 | task :release_elpa do |
93 | require 'tlsmail' |
94 | require 'time' |
95 | require scope('lib/haml') |
96 | |
97 | version = Haml.version[:number] |
98 | |
99 | haml_unchanged = mode_unchanged?(:haml, version) |
100 | sass_unchanged = mode_unchanged?(:sass, version) |
101 | next if haml_unchanged && sass_unchanged |
102 | raise "haml-mode.el and sass-mode.el are out of sync." if haml_unchanged ^ sass_unchanged |
103 | |
104 | if sass_unchanged && File.read(scope("extra/sass-mode.el")). |
105 | include?(";; Package-Requires: ((haml-mode #{sass_unchanged.inspect}))") |
106 | raise "sass-mode.el doesn't require the same version of haml-mode." |
107 | end |
108 | |
109 | from = `git config user.email`.strip |
110 | raise "Don't know how to send emails except via Gmail" unless from =~ /@gmail.com$/ |
111 | |
112 | to = "elpa@tromey.com" |
113 | Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) |
114 | Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', from, read_password("GMail Password"), :login) do |smtp| |
115 | smtp.send_message(<<CONTENT, from, to) |
116 | From: Nathan Weizenbaum <#{from}> |
117 | To: #{to} |
118 | Subject: Submitting haml-mode and sass-mode #{version} |
119 | Date: #{Time.now.rfc2822} |
120 | |
121 | haml-mode and sass-mode #{version} are packaged and ready to be included in ELPA. |
122 | They can be downloaded from: |
123 | |
124 | http://github.com/nex3/haml/raw/#{Haml.version[:rev]}/extra/haml-mode.el |
125 | http://github.com/nex3/haml/raw/#{Haml.version[:rev]}/extra/sass-mode.el |
126 | CONTENT |
127 | end |
128 | end |
129 | |
130 | # Ensures that the version have been updated for a new release. |
131 | task :check_release do |
132 | version = File.read(scope("VERSION")).strip |
133 | raise "There have been changes since current version (#{version})" if changed_since?(version) |
134 | raise "VERSION_NAME must not be 'Bleeding Edge'" if File.read(scope("VERSION_NAME")) == "Bleeding Edge" |
135 | end |
136 | |
137 | # Reads a password from the command line. |
138 | # |
139 | # @param name [String] The prompt to use to read the password |
140 | def read_password(prompt) |
141 | require 'readline' |
142 | system "stty -echo" |
143 | Readline.readline("#{prompt}: ").strip |
144 | ensure |
145 | system "stty echo" |
146 | puts |
147 | end |
148 | |
149 | # Returns whether or not the repository, or specific files, |
150 | # has/have changed since a given revision. |
151 | # |
152 | # @param rev [String] The revision to check against |
153 | # @param files [Array<String>] The files to check. |
154 | # If this is empty, checks the entire repository |
155 | def changed_since?(rev, *files) |
156 | IO.popen("git diff --exit-code #{rev} #{files.join(' ')}") {} |
157 | return !$?.success? |
158 | end |
159 | |
160 | # Returns whether or not the given Emacs mode file (haml or sass) |
161 | # has changed since the given version. |
162 | # |
163 | # @param mode [String, Symbol] The name of the mode |
164 | # @param version [String] The version number |
165 | # @return [String, nil] The version number if the version has changed |
166 | def mode_unchanged?(mode, version) |
167 | mode_version = File.read(scope("extra/#{mode}-mode.el")).scan(/^;; Version: (.*)$/).first.first |
168 | return false if mode_version == version |
169 | return mode_version unless changed_since?(mode_version, "extra/#{mode}-mode.el") |
170 | raise "#{mode}-mode.el version is #{version.inspect}, but it has changed as of #{version.inspect}" |
171 | return false |
172 | end |
173 | |
174 | task :release_edge do |
175 | ensure_git_cleanup do |
176 | puts "#{'=' * 50} Running rake release_edge" |
177 | |
178 | sh %{git checkout edge-gem} |
179 | sh %{git reset --hard origin/edge-gem} |
180 | sh %{git merge origin/master} |
181 | |
182 | # Get the current master branch version |
183 | version = File.read(scope('VERSION')).strip.split('.').map {|n| n.to_i} |
184 | unless version[1] % 2 == 1 && version[2] == 0 |
185 | raise "#{version.join('.')} is not a development version" |
186 | end |
187 | |
188 | # Bump the edge gem version |
189 | edge_version = File.read(scope('EDGE_GEM_VERSION')).strip.split('.').map {|n| n.to_i} |
190 | if edge_version[0..1] != version[0..1] |
191 | # A new master branch version was released, reset the edge gem version |
192 | edge_version[0..1] = version[0..1] |
193 | edge_version[2] = 0 |
194 | else |
195 | # Just bump the teeny version |
196 | edge_version[2] += 1 |
197 | end |
198 | edge_version = edge_version.join('.') |
199 | File.open(scope('EDGE_GEM_VERSION'), 'w') {|f| f.puts(edge_version)} |
200 | sh %{git commit -m "Bump edge gem version to #{edge_version}." EDGE_GEM_VERSION} |
201 | sh %{git push origin edge-gem} |
202 | |
203 | # Package the edge gem with the proper version |
204 | File.open(scope('VERSION'), 'w') {|f| f.puts(edge_version)} |
205 | sh %{rake package} |
206 | sh %{git checkout VERSION} |
207 | |
208 | sh %{rubyforge login} |
209 | sh %{rubyforge add_release haml haml-edge "Bleeding Edge (v#{edge_version})" pkg/haml-edge-#{edge_version}.gem} |
210 | end |
211 | end |
212 | |
213 | task :watch_for_update do |
214 | sh %{ruby extra/update_watch.rb} |
215 | end |
216 | |
217 | # ----- Documentation ----- |
218 | |
219 | task :rdoc do |
220 | puts '=' * 100, <<END, '=' * 100 |
221 | Haml uses the YARD documentation system (http://github.com/lsegal/yard). |
222 | Install the yard gem and then run "rake doc". |
223 | END |
224 | end |
225 | |
226 | begin |
227 | require 'yard' |
228 | |
229 | namespace :doc do |
230 | task :sass do |
231 | require scope('lib/sass') |
232 | Dir[scope("yard/default/**/*.sass")].each do |sass| |
233 | File.open(sass.gsub(/sass$/, 'css'), 'w') do |f| |
234 | f.write(Sass::Engine.new(File.read(sass)).render) |
235 | end |
236 | end |
237 | end |
238 | |
239 | desc "List all undocumented methods and classes." |
240 | task :undocumented do |
241 | opts = ENV["YARD_OPTS"] || "" |
242 | ENV["YARD_OPTS"] = opts.dup + <<OPTS |
243 | --list --query " |
244 | object.docstring.blank? && |
245 | !(object.type == :method && object.is_alias?)" |
246 | OPTS |
247 | Rake::Task['yard'].execute |
248 | end |
249 | end |
250 | |
251 | YARD::Rake::YardocTask.new do |t| |
252 | t.files = FileList.new(scope('lib/**/*.rb')) do |list| |
253 | list.exclude('lib/haml/template/*.rb') |
254 | list.exclude('lib/haml/railtie.rb') |
255 | list.exclude('lib/haml/helpers/action_view_mods.rb') |
256 | list.exclude('lib/haml/helpers/xss_mods.rb') |
257 | list.exclude('lib/sass/plugin/merb.rb') |
258 | list.exclude('lib/sass/plugin/rails.rb') |
259 | end.to_a |
260 | t.options << '--incremental' if Rake.application.top_level_tasks.include?('redoc') |
261 | t.options += FileList.new(scope('yard/*.rb')).to_a.map {|f| ['-e', f]}.flatten |
262 | files = FileList.new(scope('doc-src/*')).to_a.sort_by {|s| s.size} + %w[MIT-LICENSE VERSION] |
263 | t.options << '--files' << files.join(',') |
264 | t.options << '--template-path' << scope('yard') |
265 | t.options << '--title' << ENV["YARD_TITLE"] if ENV["YARD_TITLE"] |
266 | |
267 | t.before = lambda do |
268 | if ENV["YARD_OPTS"] |
269 | require 'shellwords' |
270 | t.options.concat(Shellwords.shellwords(ENV["YARD_OPTS"])) |
271 | end |
272 | end |
273 | end |
274 | Rake::Task['yard'].prerequisites.insert(0, 'doc:sass') |
275 | Rake::Task['yard'].instance_variable_set('@comment', nil) |
276 | |
277 | desc "Generate Documentation" |
278 | task :doc => :yard |
279 | task :redoc => :yard |
280 | rescue LoadError |
281 | desc "Generate Documentation" |
282 | task :doc => :rdoc |
283 | task :yard => :rdoc |
284 | end |
285 | |
286 | task :pages do |
287 | ensure_git_cleanup do |
288 | puts "#{'=' * 50} Running rake pages PROJ=#{ENV["PROJ"].inspect}" |
289 | raise 'No ENV["PROJ"]!' unless proj = ENV["PROJ"] |
290 | sh %{git checkout #{proj}-pages} |
291 | sh %{git reset --hard origin/#{proj}-pages} |
292 | |
293 | sh %{rake build --trace} |
294 | sh %{rsync -av --delete site/ /var/www/#{proj}-pages} |
295 | end |
296 | end |
297 | |
298 | # ----- Coverage ----- |
299 | |
300 | begin |
301 | require 'rcov/rcovtask' |
302 | |
303 | Rcov::RcovTask.new do |t| |
304 | t.test_files = FileList[scope('test/**/*_test.rb')] |
305 | t.rcov_opts << '-x' << '"^\/"' |
306 | if ENV['NON_NATIVE'] |
307 | t.rcov_opts << "--no-rcovrt" |
308 | end |
309 | t.verbose = true |
310 | end |
311 | rescue LoadError; end |
312 | |
313 | # ----- Profiling ----- |
314 | |
315 | begin |
316 | require 'ruby-prof' |
317 | |
318 | desc <<END |
319 | Run a profile of haml. |
320 | ENGINE=str sets the engine to be profiled. Defaults to Haml. |
321 | TIMES=n sets the number of runs. Defaults to 1000. |
322 | FILE=str sets the file to profile. |
323 | Defaults to 'standard' for Haml and 'complex' for Sass. |
324 | OUTPUT=str sets the ruby-prof output format. |
325 | Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat. |
326 | END |
327 | task :profile do |
328 | engine = (ENV['ENGINE'] || 'haml').downcase |
329 | times = (ENV['TIMES'] || '1000').to_i |
330 | file = ENV['FILE'] |
331 | |
332 | if engine == 'sass' |
333 | require 'lib/sass' |
334 | |
335 | file = File.read(scope("test/sass/templates/#{file || 'complex'}.sass")) |
336 | result = RubyProf.profile { times.times { Sass::Engine.new(file).render } } |
337 | else |
338 | require 'lib/haml' |
339 | |
340 | file = File.read(scope("test/haml/templates/#{file || 'standard'}.haml")) |
341 | obj = Object.new |
342 | Haml::Engine.new(file).def_method(obj, :render) |
343 | result = RubyProf.profile { times.times { obj.render } } |
344 | end |
345 | |
346 | RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print |
347 | end |
348 | rescue LoadError; end |
349 | |
350 | # ----- Testing Multiple Rails Versions ----- |
351 | |
352 | rails_versions = [ |
353 | "v2.3.5", |
354 | "v2.2.3", |
355 | "v2.1.2", |
356 | ] |
357 | rails_versions << "v2.0.5" if RUBY_VERSION =~ /^1\.8/ |
358 | |
359 | def test_rails_version(version) |
360 | Dir.chdir "test/rails" do |
361 | `git checkout #{version}` |
362 | end |
363 | puts "Testing Rails #{version}" |
364 | Rake::Task['test'].reenable |
365 | Rake::Task['test'].execute |
366 | end |
367 | |
368 | namespace :test do |
369 | desc "Test all supported versions of rails. This takes a while." |
370 | task :rails_compatibility do |
371 | `rm -rf test/rails` |
372 | puts "Checking out rails. Please wait." |
373 | system("git clone git://github.com/rails/rails.git test/rails") rescue nil |
374 | begin |
375 | rails_versions.each {|version| test_rails_version version} |
376 | |
377 | puts "Checking out rails_xss. Please wait." |
378 | system("git clone git://github.com/NZKoz/rails_xss.git test/plugins/rails_xss") |
379 | test_rails_version(rails_versions.find {|s| s =~ /^v2\.3/}) |
380 | ensure |
381 | `rm -rf test/rails` |
382 | `rm -rf test/plugins` |
383 | end |
384 | end |
385 | end |
386 | |
387 | # ----- Handling Updates ----- |
388 | |
389 | def ensure_git_cleanup |
390 | yield |
391 | ensure |
392 | sh %{git reset --hard HEAD} |
393 | sh %{git clean -xdf} |
394 | sh %{git checkout master} |
395 | end |
396 | |
397 | task :handle_update do |
398 | unless ENV["REF"] =~ %r{^refs/heads/(master|(?:haml|sass)-pages)$} |
399 | puts "#{'=' * 20} Ignoring rake handle_update REF=#{ENV["REF"].inspect}" |
400 | next |
401 | end |
402 | branch = $1 |
403 | |
404 | puts |
405 | puts |
406 | puts '=' * 150 |
407 | puts "Running rake handle_update REF=#{ENV["REF"].inspect}" |
408 | |
409 | sh %{git checkout master} |
410 | sh %{git fetch origin} |
411 | sh %{git reset --hard origin/master} |
412 | |
413 | if branch == "master" |
414 | sh %{rake release_edge --trace} |
415 | sh %{rake pages --trace PROJ=haml} |
416 | sh %{rake pages --trace PROJ=sass} |
417 | elsif branch =~ /^(haml|sass)-pages$/ |
418 | sh %{rake pages --trace PROJ=#{$1}} |
419 | end |
420 | |
421 | puts 'Done running handle_update' |
422 | puts '=' * 150 |
423 | end |