2012-12-12 04:22:30 -05:00
|
|
|
# encoding: utf-8
|
2011-05-23 04:07:54 -04:00
|
|
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'bundler'
|
|
|
|
Bundler::GemHelper.install_tasks
|
|
|
|
rescue LoadError => e
|
|
|
|
$stderr.puts e
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "run specs"
|
|
|
|
task(:spec) { ruby '-S rspec spec' }
|
|
|
|
|
2017-04-09 03:00:24 -04:00
|
|
|
namespace :doc do
|
|
|
|
task :readmes do
|
|
|
|
Dir.glob 'lib/rack/protection/*.rb' do |file|
|
|
|
|
excluded_files = %w[lib/rack/protection/base.rb lib/rack/protection/version.rb]
|
|
|
|
next if excluded_files.include?(file)
|
|
|
|
doc = File.read(file)[/^ module Protection(\n)+( #[^\n]*\n)*/m].scan(/^ *#(?!#) ?(.*)\n/).join("\n")
|
|
|
|
file = "doc/#{file[4..-4].tr("/_", "-")}.rdoc"
|
|
|
|
Dir.mkdir "doc" unless File.directory? "doc"
|
|
|
|
puts "writing #{file}"
|
|
|
|
File.open(file, "w") { |f| f << doc }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-07 19:59:12 -04:00
|
|
|
task :index do
|
|
|
|
doc = File.read("README.md")
|
|
|
|
file = "doc/rack-protection-readme.md"
|
|
|
|
Dir.mkdir "doc" unless File.directory? "doc"
|
|
|
|
puts "writing #{file}"
|
|
|
|
File.open(file, "w") { |f| f << doc }
|
|
|
|
end
|
|
|
|
|
|
|
|
task :all => [:readmes, :index]
|
2017-04-09 03:00:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "generate documentation"
|
|
|
|
task :doc => 'doc:all'
|
|
|
|
|
2011-05-23 04:07:54 -04:00
|
|
|
desc "generate gemspec"
|
|
|
|
task 'rack-protection.gemspec' do
|
|
|
|
require 'rack/protection/version'
|
2013-02-28 23:55:54 -05:00
|
|
|
content = File.binread 'rack-protection.gemspec'
|
2011-05-23 04:07:54 -04:00
|
|
|
|
2012-12-12 04:22:30 -05:00
|
|
|
# fetch data
|
2011-05-23 04:07:54 -04:00
|
|
|
fields = {
|
2013-02-28 23:55:54 -05:00
|
|
|
:authors => `git shortlog -sn`.force_encoding('utf-8').scan(/[^\d\s].*/),
|
2016-07-25 03:57:04 -04:00
|
|
|
:email => ["mail@zzak.io", "konstantin.haase@gmail.com"],
|
|
|
|
:files => %w(License README.md Rakefile Gemfile rack-protection.gemspec) + Dir['lib/**/*']
|
2011-05-23 04:07:54 -04:00
|
|
|
}
|
|
|
|
|
2012-12-12 04:22:30 -05:00
|
|
|
# insert data
|
2011-05-23 04:07:54 -04:00
|
|
|
fields.each do |field, values|
|
|
|
|
updated = " s.#{field} = ["
|
|
|
|
updated << values.map { |v| "\n %p" % v }.join(',')
|
|
|
|
updated << "\n ]"
|
|
|
|
content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated)
|
|
|
|
end
|
|
|
|
|
2012-12-12 04:22:30 -05:00
|
|
|
# set version
|
2011-05-23 04:07:54 -04:00
|
|
|
content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""
|
2012-12-12 04:22:30 -05:00
|
|
|
|
|
|
|
# escape unicode
|
|
|
|
content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
|
|
|
|
|
2011-05-23 04:07:54 -04:00
|
|
|
File.open('rack-protection.gemspec', 'w') { |f| f << content }
|
|
|
|
end
|
|
|
|
|
|
|
|
task :gemspec => 'rack-protection.gemspec'
|
|
|
|
task :default => :spec
|
|
|
|
task :test => :spec
|