2008-11-08 18:59:05 +00:00
|
|
|
#!/usr/bin/env rake
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
|
|
require 'rake'
|
2011-01-21 19:41:16 -08:00
|
|
|
require 'rspec'
|
|
|
|
|
require 'rspec/core/rake_task'
|
2008-11-09 00:27:36 +00:00
|
|
|
require 'rake/packagetask'
|
2008-11-08 18:59:05 +00:00
|
|
|
require 'rake/gempackagetask'
|
2008-11-09 00:27:36 +00:00
|
|
|
require 'rubygems/installer'
|
|
|
|
|
require 'rubygems/uninstaller'
|
2008-11-08 18:59:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
######################################################################
|
2008-11-09 00:27:36 +00:00
|
|
|
### P A T H S A N D F I L E S
|
2008-11-08 18:59:05 +00:00
|
|
|
######################################################################
|
|
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
|
|
|
|
|
|
|
|
|
|
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
|
|
|
|
|
|
2008-11-08 18:59:05 +00:00
|
|
|
SPECDIR = BASEDIR + 'spec'
|
2011-01-21 19:41:16 -08:00
|
|
|
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
LIBDIR = BASEDIR + 'lib'
|
2011-01-21 19:41:16 -08:00
|
|
|
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')
|
2008-11-09 00:27:36 +00:00
|
|
|
|
|
|
|
|
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
|
|
|
|
|
|
|
|
|
|
|
2008-11-08 18:59:05 +00:00
|
|
|
######################################################################
|
|
|
|
|
### H E L P E R S
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
|
|
### Given a +file+ path, find the first captured match of +pattern+,
|
|
|
|
|
### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.)
|
|
|
|
|
###
|
|
|
|
|
def find_pattern( file, pattern )
|
|
|
|
|
ver = nil
|
|
|
|
|
File.open( file ) do |f|
|
|
|
|
|
ver = f.each do |line|
|
|
|
|
|
break $1 if line =~ pattern
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return ver.is_a?( String ) ? ver : 'UNKNOWN'
|
|
|
|
|
end
|
|
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
|
2008-11-08 18:59:05 +00:00
|
|
|
######################################################################
|
|
|
|
|
### P A C K A G E C O N S T A N T S
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
|
|
PKG_NAME = 'chunker'
|
2011-01-21 19:41:16 -08:00
|
|
|
PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )
|
|
|
|
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
2008-11-08 18:59:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
### T A S K S
|
|
|
|
|
######################################################################
|
|
|
|
|
|
2011-01-21 19:41:16 -08:00
|
|
|
task :test => 'test:spec'
|
|
|
|
|
task :default => :test
|
|
|
|
|
# task :default => [ :test, :package ]
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2011-01-21 19:41:16 -08:00
|
|
|
namespace :test do
|
|
|
|
|
desc 'Generate verbose and pretty output'
|
|
|
|
|
RSpec::Core::RakeTask.new( :spec ) do |task|
|
|
|
|
|
task.pattern = SPEC_FILES
|
|
|
|
|
task.rspec_opts = ['-b', '-fd', '-c']
|
|
|
|
|
end
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2011-01-21 19:41:16 -08:00
|
|
|
desc 'Generate quiet non-colored plain-text output'
|
|
|
|
|
RSpec::Core::RakeTask.new( :quiet ) do |task|
|
|
|
|
|
task.pattern = SPEC_FILES
|
|
|
|
|
task.rspec_opts = ['-f', 'p']
|
|
|
|
|
end
|
2008-11-08 18:59:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
### Task: generate ctags
|
|
|
|
|
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
|
|
|
|
|
###
|
|
|
|
|
desc "Generate a ctags 'tags' file from Chunker source"
|
|
|
|
|
task :ctags do
|
|
|
|
|
sh "ctags -R #{LIBDIR}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Task: Create gem from source
|
|
|
|
|
###
|
|
|
|
|
gem = Gem::Specification.new do |gem|
|
2008-11-09 00:27:36 +00:00
|
|
|
gem.summary = "A convenience library for parsing __END__ tokens consistently."
|
|
|
|
|
gem.name = PKG_NAME
|
2011-01-21 19:41:16 -08:00
|
|
|
gem.version = PKG_VERSION
|
2008-11-09 00:27:36 +00:00
|
|
|
gem.author = 'Mahlon E. Smith'
|
|
|
|
|
gem.email = 'mahlon@martini.nu'
|
2009-06-04 17:28:02 +00:00
|
|
|
gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker'
|
2008-11-09 00:27:36 +00:00
|
|
|
gem.has_rdoc = true
|
|
|
|
|
|
|
|
|
|
gem.files = RELEASE_FILES.
|
|
|
|
|
collect {|f| f.relative_path_from(BASEDIR).to_s }
|
|
|
|
|
gem.test_files = SPEC_FILES.
|
|
|
|
|
collect {|f| f.relative_path_from(BASEDIR).to_s }
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
gem.description = <<-EOF
|
|
|
|
|
Ruby provides an automatic constant called DATA, which is an IO object
|
|
|
|
|
that references all text in the current file under an __END__ token.
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
I find it convenient to use the __END__ area to store all sorts of
|
|
|
|
|
stuff, rather than have to worry about distributing separate files.
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
The DATA constant is determined from whatever ruby believes $0 to be.
|
|
|
|
|
It doesn't work inside of other required libraries, so you'll see stuff
|
|
|
|
|
like this all the time:
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
It works, but it's more work than I want to do.
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
Chunker solves this by parsing __END__ tokens for you, and making it
|
|
|
|
|
available in the form of a 'DATA_END' constant. It installs this
|
|
|
|
|
constant into the class that includes Chunker, so you can use it again
|
|
|
|
|
and again, assuming you use a different file for each class.
|
2008-11-08 18:59:05 +00:00
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
It also automatically parses out other things that look like tokens, so
|
|
|
|
|
you can easily have multiple, distinct documents all embedded into the
|
|
|
|
|
__END__ block.
|
|
|
|
|
EOF
|
2008-11-08 18:59:05 +00:00
|
|
|
end
|
|
|
|
|
|
2008-11-09 00:27:36 +00:00
|
|
|
Rake::GemPackageTask.new( gem ) do |pkg|
|
|
|
|
|
pkg.need_zip = true
|
|
|
|
|
pkg.need_tar = true
|
|
|
|
|
pkg.need_tar_bz2 = true
|
2008-11-08 18:59:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Task: install
|
2008-11-09 00:27:36 +00:00
|
|
|
###
|
|
|
|
|
task :install_gem => [ :package ] do
|
|
|
|
|
$stderr.puts
|
|
|
|
|
installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" )
|
2008-11-08 18:59:05 +00:00
|
|
|
installer.install
|
|
|
|
|
end
|
2008-11-09 00:27:36 +00:00
|
|
|
task :install => [ :install_gem ]
|
|
|
|
|
|
2008-11-08 18:59:05 +00:00
|
|
|
|
|
|
|
|
### Task: uninstall
|
2008-11-09 00:27:36 +00:00
|
|
|
###
|
|
|
|
|
task :uninstall_gem do
|
|
|
|
|
uninstaller = Gem::Uninstaller.new( PKG_NAME )
|
2008-11-08 18:59:05 +00:00
|
|
|
uninstaller.uninstall
|
|
|
|
|
end
|
2008-11-09 00:27:36 +00:00
|
|
|
task :uninstall => [ :uninstall_gem ]
|
2008-11-08 18:59:05 +00:00
|
|
|
|