/scalate-jruby/src/main/resources/haml-3.0.25/Rakefile

http://github.com/scalate/scalate · Rakefile · 436 lines · 392 code · 21 blank · 23 comment · 11 complexity · be88349f6b50117341790fae79d517c7 MD5 · raw file

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