5 require 'rake/rdoctask'
11 SRC_FILES = FileList["#{SRC_DIR}/*"]
12 KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
14 today = Time.now.strftime("%Y-%m-%d")
15 TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
16 ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
18 CLOBBER.include(DIST_DIR)
21 # Remove solution info from source
25 def Koans.remove_solution(line)
26 line = line.gsub(/\b____\([^\)]+\)/, "____")
27 line = line.gsub(/\b___\([^\)]+\)/, "___")
28 line = line.gsub(/\b__\([^\)]+\)/, "__")
29 line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
30 line = line.gsub(%r(/\#\{__\}/), "/__/")
31 line = line.gsub(/\s*#\s*__\s*$/, '')
35 def Koans.make_koan_file(infile, outfile)
36 if infile =~ /edgecase/
38 elsif infile =~ /autotest/
42 open(outfile, "w") do |outs|
45 state = :skip if line =~ /^ *#--/
48 outs.puts remove_solution(line)
52 state = :copy if line =~ /^ *#\+\+/
60 task :default => :walk_the_path
62 task :walk_the_path do
64 ruby 'path_to_enlightenment.rb'
67 Rake::RDocTask.new do |rd|
68 rd.main = "README.rdoc"
69 rd.rdoc_files.include("README.rdoc", "koans/*.rb")
75 file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
76 sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
79 file TAR_FILE => KOAN_FILES + [DIST_DIR] do
80 sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
83 desc "Create packaged files for distribution"
84 task :package => [TAR_FILE, ZIP_FILE]
86 desc "Upload the package files to the web server"
87 task :upload => [TAR_FILE, ZIP_FILE] do
88 sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
89 sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
92 desc "Generate the Koans from the source files from scratch."
93 task :regen => [:clobber_koans, :gen]
95 desc "Generate the Koans from the changed source files."
96 task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
97 task :clobber_koans do
101 file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
102 cp "README.rdoc", t.name
105 SRC_FILES.each do |koan_src|
106 file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
107 Koans.make_koan_file koan_src, t.name