require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'yard' require 'benchmark' task default: [:install, :spec] # Useful for hooking up with SublimeText. # e.g. rake sample[basic.rb] task :run,[:file] => :install do |t, args| args.with_defaults(file: 'basic.rb') Dir.chdir('samples') do puts "Running samples/#{args[:file]}" load args[:file] end end RSpec::Core::RakeTask.new(:spec) task doc: [:yarddoc, :apply_google_analytics] YARD::Rake::YardocTask.new(:yarddoc) do |t| t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional #t.options = ['--any', '--extra', '--opts'] # optional end task benchmark: [:install] do Squib::logger.level = Logger::ERROR #silence warnings Dir.chdir('benchmarks') do Benchmark.bm(15) do |bm| Dir['*.rb'].each do | script | GC.start bm.report(script) { load script } end end end end task :apply_google_analytics do # The string to replace in the html document. This is chosen to be the end # body tag. So the script can be injected as the last thing in the # document body. string_to_replace = "" # This is the string to replace with. It include the google analytics script # as well as the end tag. string_to_replace_with = <<-EOF EOF files = Dir.glob("doc/**/*.html") files.each do |html_file| puts "Processing file: #{html_file}" contents = "" # Read the file contents file = File.open(html_file) file.each { |line| contents << line } file.close # If the file already has google analytics tracking info, skip it. if contents.include?(string_to_replace_with) puts "Skipped..." next end # Apply google analytics tracking info to the html file contents.gsub!(string_to_replace, string_to_replace_with) # Write the contents with the google analytics info to the file file = File.open(html_file, "w") file.write(contents) file.close end end