#!/usr/bin/env rake
# -*- Ruby -*-
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'

# ------- Default Package ----------
PACKAGE_VERSION = open(File.join(File.dirname(__FILE__), 'VERSION')) do 
  |f| f.readlines[0].chomp
end

FILES = FileList[
  'AUTHORS',
  'COPYING',
  'ChangeLog',
  'NEWS',
  'README',
  'Rakefile',
  'VERSION',
  'lib/*.rb',
  'test/*.rb'
]                        

desc "Test everything."
test_task = task :test => :lib do 
  Rake::TestTask.new(:test) do |t|
    t.libs << './lib'
    t.pattern = 'test/test-*.rb'
    t.verbose = true
  end
end

desc "Test everything - same as test."
task :check => :test

desc "Create a GNU-style ChangeLog via svn2cl"
task :ChangeLog do
  system("svn2cl")
end

# Base GEM Specification
default_spec = Gem::Specification.new do |spec|
  spec.name = "columnize"
  
  spec.homepage = "http://rubyforge.org/projects/rocky-hacks/columnize"
  spec.summary = "Read file with caching"
  spec.description = <<-EOF
Return a list of strings as a set of arranged in columns.

For example, for a line width of 4 characters (arranged vertically):
    ['1', '2,', '3', '4'] => '1  3\n2  4\n'

or arranged horizontally:
    ['1', '2,', '3', '4'] => '1  2\n3  4\n'

Each column is only as wide as necessary.  By default, columns are
separated by two spaces - one was not legible enough. Set "colsep"
to adjust the string separate columns. Set `displaywidth' to set
the line width.

Normally, consecutive items go down from the top to bottom from
the left-most column to the right-most. If +arrange_vertical+ is
set false, consecutive items will go across, left to right, top to
bottom.
EOF

  spec.version = PACKAGE_VERSION

  spec.author = "R. Bernstein"
  spec.email = "rockyb@rubyforge.net"
  spec.platform = Gem::Platform::RUBY
  spec.require_path = "lib"
  spec.files = FILES.to_a  

  spec.required_ruby_version = '>= 1.8.2'
  spec.date = Time.now
  spec.rubyforge_project = 'rocky-hacks'
  
  # rdoc
  spec.has_rdoc = true
  spec.extra_rdoc_files = ['README', 'lib/columnize.rb']
end

# Rake task to build the default package
  Rake::GemPackageTask.new(default_spec) do |pkg|
  pkg.need_tar = true
end

task :default => [:test]

desc "Publish columnize to RubyForge."
task :publish do 
  require 'rake/contrib/sshpublisher'
  
  # Get ruby-debug path
  ruby_debug_path = File.expand_path(File.dirname(__FILE__))

  publisher = Rake::SshDirPublisher.new("rockyb@rubyforge.org",
        "/var/www/gforge-projects/rocky-hacks/columnize", ruby_debug_path)
end

desc "Remove built files"
task :clean => [:clobber_package, :clobber_rdoc]

# ---------  RDoc Documentation ------
desc "Generate rdoc documentation"
Rake::RDocTask.new("rdoc") do |rdoc|
  rdoc.rdoc_dir = 'doc'
  rdoc.title    = "columnize"
  # Show source inline with line numbers
  rdoc.options << "--inline-source" << "--line-numbers"
  # Make the readme file the start page for the generated html
  rdoc.options << '--main' << 'README'
  rdoc.rdoc_files.include('lib/*.rb', 'README', 'COPYING')
end

