2012-04-27 12:46:28 -04:00
|
|
|
require "rake/clean"
|
2012-05-07 14:44:42 -04:00
|
|
|
require "rake/testtask"
|
2014-05-30 00:56:23 -04:00
|
|
|
require "bundler/gem_tasks"
|
2012-04-27 12:46:28 -04:00
|
|
|
|
2012-04-27 13:20:38 -04:00
|
|
|
task :default => :test
|
|
|
|
|
2017-05-03 10:52:51 -04:00
|
|
|
# FIXME: Redefining :test task to run test/options_test.rb in isolated process since it depends on whether Rails is loaded or not.
|
2017-03-28 04:40:55 -04:00
|
|
|
# Remove this task when we finished changing escape_html option to be true by default.
|
2017-05-03 10:52:51 -04:00
|
|
|
isolated_test = Rake::TestTask.new do |t|
|
|
|
|
t.libs << 'test'
|
|
|
|
t.test_files = %w[test/options_test.rb]
|
|
|
|
t.warning = true
|
|
|
|
t.verbose = true
|
|
|
|
end
|
|
|
|
Rake::TestTask.new do |t|
|
|
|
|
t.libs << 'test'
|
|
|
|
t.test_files = Dir['test/*_test.rb'] + Dir['test/haml-spec/*_test.rb'] - isolated_test.file_list
|
|
|
|
t.warning = true
|
|
|
|
t.verbose = true
|
2017-03-28 04:40:55 -04:00
|
|
|
end
|
|
|
|
|
2012-08-19 11:22:09 -04:00
|
|
|
CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
|
2010-02-28 19:50:33 -05:00
|
|
|
|
2014-10-03 02:58:43 -04:00
|
|
|
desc "Benchmark Haml against ERB. TIMES=n sets the number of runs, default is 1000."
|
2006-12-15 23:21:34 -05:00
|
|
|
task :benchmark do
|
2012-06-03 12:58:23 -04:00
|
|
|
sh "ruby benchmark.rb #{ENV['TIMES']}"
|
2006-11-28 21:16:51 -05:00
|
|
|
end
|
|
|
|
|
2012-05-22 15:03:27 -04:00
|
|
|
task :set_coverage_env do
|
|
|
|
ENV["COVERAGE"] = "true"
|
|
|
|
end
|
|
|
|
|
2013-05-23 01:01:54 -04:00
|
|
|
desc "Run Simplecov"
|
2012-05-22 15:03:27 -04:00
|
|
|
task :coverage => [:set_coverage_env, :test]
|
|
|
|
|
2010-01-16 18:57:12 -05:00
|
|
|
task :submodules do
|
|
|
|
if File.exist?(File.dirname(__FILE__) + "/.git")
|
|
|
|
sh %{git submodule sync}
|
2010-10-03 20:04:11 -04:00
|
|
|
sh %{git submodule update --init --recursive}
|
2010-01-16 18:57:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-01 12:06:39 -05:00
|
|
|
namespace :doc do
|
|
|
|
task :sass do
|
|
|
|
require 'sass'
|
|
|
|
Dir["yard/default/**/*.sass"].each do |sass|
|
|
|
|
File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
|
|
|
|
f.write(Sass::Engine.new(File.read(sass)).render)
|
2014-03-25 18:23:14 -04:00
|
|
|
end
|
|
|
|
end
|
2009-11-23 17:01:16 -05:00
|
|
|
end
|
|
|
|
|
2014-12-01 12:06:39 -05:00
|
|
|
desc "List all undocumented methods and classes."
|
|
|
|
task :undocumented do
|
|
|
|
command = 'yard --list --query '
|
|
|
|
command << '"object.docstring.blank? && '
|
|
|
|
command << '!(object.type == :method && object.is_alias?)"'
|
|
|
|
sh command
|
|
|
|
end
|
|
|
|
end
|
2010-04-20 02:25:44 -04:00
|
|
|
|
2014-12-01 12:06:39 -05:00
|
|
|
desc "Generate documentation"
|
|
|
|
task(:doc => 'doc:sass') {sh "yard"}
|
2009-03-30 04:27:08 -04:00
|
|
|
|
2014-12-01 12:06:39 -05:00
|
|
|
desc "Generate documentation incrementally"
|
|
|
|
task(:redoc) {sh "yard -c"}
|
2006-10-14 19:50:07 -04:00
|
|
|
|
2014-12-01 12:06:39 -05:00
|
|
|
desc <<END
|
2012-04-27 13:20:38 -04:00
|
|
|
Profile Haml.
|
2008-05-15 18:43:32 -04:00
|
|
|
TIMES=n sets the number of runs. Defaults to 1000.
|
2010-08-22 19:04:02 -04:00
|
|
|
FILE=str sets the file to profile. Defaults to 'standard'
|
2008-05-15 18:43:32 -04:00
|
|
|
OUTPUT=str sets the ruby-prof output format.
|
|
|
|
Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
|
2008-05-15 18:02:45 -04:00
|
|
|
END
|
2012-04-27 13:20:38 -04:00
|
|
|
task :profile do
|
|
|
|
times = (ENV['TIMES'] || '1000').to_i
|
2013-10-14 11:14:33 -04:00
|
|
|
file = ENV['FILE'] || 'test/templates/standard.haml'
|
2008-05-15 18:43:32 -04:00
|
|
|
|
2012-04-27 13:20:38 -04:00
|
|
|
require 'bundler/setup'
|
|
|
|
require 'ruby-prof'
|
|
|
|
require 'haml'
|
2013-10-14 11:14:33 -04:00
|
|
|
file = File.read(File.expand_path("../#{file}", __FILE__))
|
2012-04-27 13:20:38 -04:00
|
|
|
obj = Object.new
|
2017-02-01 22:36:07 -05:00
|
|
|
Haml::Engine.new(file).def_method(obj, :render)
|
2012-04-27 13:20:38 -04:00
|
|
|
result = RubyProf.profile { times.times { obj.render } }
|
2006-12-15 23:21:34 -05:00
|
|
|
|
2012-04-27 13:20:38 -04:00
|
|
|
RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
|
2010-03-02 18:50:42 -05:00
|
|
|
end
|
|
|
|
|
2011-09-21 20:40:33 -04:00
|
|
|
def gemfiles
|
2012-04-27 13:20:38 -04:00
|
|
|
@gemfiles ||= begin
|
|
|
|
Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].
|
|
|
|
reject {|f| f =~ /\.lock$/}.
|
2013-03-24 19:24:36 -04:00
|
|
|
reject {|f| RUBY_VERSION < '1.9.3' && f =~ /Gemfile.rails-(\d+).\d+.x/ && $1.to_i > 3}
|
2012-04-27 13:20:38 -04:00
|
|
|
end
|
2011-09-21 20:40:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_each_gemfile
|
|
|
|
gemfiles.each do |gemfile|
|
2014-11-26 14:55:49 -05:00
|
|
|
Bundler.with_clean_env do
|
|
|
|
puts "Using gemfile: #{gemfile}"
|
|
|
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
|
|
yield
|
|
|
|
end
|
2011-09-21 20:40:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :test do
|
|
|
|
namespace :bundles do
|
|
|
|
desc "Install all dependencies necessary to test Haml."
|
|
|
|
task :install do
|
2012-04-26 16:44:48 -04:00
|
|
|
with_each_gemfile {sh "bundle"}
|
2011-09-21 20:40:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Update all dependencies for testing Haml."
|
|
|
|
task :update do
|
|
|
|
with_each_gemfile {sh "bundle update"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Test all supported versions of rails. This takes a while."
|
|
|
|
task :rails_compatibility => 'test:bundles:install' do
|
|
|
|
with_each_gemfile {sh "bundle exec rake test"}
|
2009-02-10 04:39:18 -05:00
|
|
|
end
|
2012-05-30 11:10:47 -04:00
|
|
|
task :rc => :rails_compatibility
|
2009-02-24 22:55:06 -05:00
|
|
|
end
|