author | mahlon |
Thu, 04 Jun 2009 17:28:02 +0000 | |
branch | ruby-modules |
changeset 3 | 233041485364 |
parent 2 | e5c705047540 |
child 4 | 01a3332bfe0a |
permissions | -rw-r--r-- |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
1 |
#!/usr/bin/env rake |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
2 |
# |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
3 |
# Chunker Rakefile |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
4 |
# |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
5 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
6 |
require 'rubygems' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
7 |
require 'pathname' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
8 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
9 |
require 'rake' |
3 | 10 |
require 'spec' |
11 |
require 'rake/testtask' |
|
2 | 12 |
require 'rake/packagetask' |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
13 |
require 'rake/gempackagetask' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
14 |
require 'spec/rake/spectask' |
2 | 15 |
require 'rubygems/installer' |
16 |
require 'rubygems/uninstaller' |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
17 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
18 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
19 |
###################################################################### |
2 | 20 |
### P A T H S A N D F I L E S |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
21 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
22 |
|
2 | 23 |
BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd ) |
24 |
||
25 |
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f } |
|
26 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
27 |
SPECDIR = BASEDIR + 'spec' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
28 |
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ } |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
29 |
|
2 | 30 |
LIBDIR = BASEDIR + 'lib' |
31 |
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb').reject {|i| i =~ /\.svn/ } |
|
32 |
||
33 |
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES |
|
34 |
||
35 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
36 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
37 |
### H E L P E R S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
38 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
39 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
40 |
### Given a +file+ path, find the first captured match of +pattern+, |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
41 |
### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
42 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
43 |
def find_pattern( file, pattern ) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
44 |
ver = nil |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
45 |
File.open( file ) do |f| |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
46 |
ver = f.each do |line| |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
47 |
break $1 if line =~ pattern |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
48 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
49 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
50 |
return ver.is_a?( String ) ? ver : 'UNKNOWN' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
51 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
52 |
|
2 | 53 |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
54 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
55 |
### P A C K A G E C O N S T A N T S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
56 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
57 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
58 |
PKG_NAME = 'chunker' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
59 |
PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ ) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
60 |
PKG_REVISION = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ ) |
2 | 61 |
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}.#{PKG_REVISION}" |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
62 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
63 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
64 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
65 |
### T A S K S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
66 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
67 |
|
2 | 68 |
task :default => [ :test, :package ] |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
69 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
70 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
71 |
### Task: run rspec tests |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
72 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
73 |
desc "Run tests" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
74 |
Spec::Rake::SpecTask.new('test') do |task| |
2 | 75 |
task.spec_files = SPEC_FILES |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
76 |
task.spec_opts = %w{ -c -fs } |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
77 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
78 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
79 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
80 |
### Task: generate ctags |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
81 |
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
82 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
83 |
desc "Generate a ctags 'tags' file from Chunker source" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
84 |
task :ctags do |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
85 |
sh "ctags -R #{LIBDIR}" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
86 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
87 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
88 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
89 |
### Task: Create gem from source |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
90 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
91 |
gem = Gem::Specification.new do |gem| |
2 | 92 |
pkg_build = PKG_REVISION || 0 |
93 |
||
94 |
gem.summary = "A convenience library for parsing __END__ tokens consistently." |
|
95 |
gem.name = PKG_NAME |
|
96 |
gem.version = "%s.%s" % [ PKG_VERSION, pkg_build ] |
|
97 |
gem.author = 'Mahlon E. Smith' |
|
98 |
gem.email = 'mahlon@martini.nu' |
|
3 | 99 |
gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker' |
2 | 100 |
gem.rubyforge_project = 'mahlon' |
101 |
gem.has_rdoc = true |
|
102 |
||
103 |
gem.files = RELEASE_FILES. |
|
104 |
collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
105 |
gem.test_files = SPEC_FILES. |
|
106 |
collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
107 |
||
108 |
gem.description = <<-EOF |
|
109 |
Ruby provides an automatic constant called DATA, which is an IO object |
|
110 |
that references all text in the current file under an __END__ token. |
|
111 |
||
112 |
I find it convenient to use the __END__ area to store all sorts of |
|
113 |
stuff, rather than have to worry about distributing separate files. |
|
114 |
||
115 |
The DATA constant is determined from whatever ruby believes $0 to be. |
|
116 |
It doesn't work inside of other required libraries, so you'll see stuff |
|
117 |
like this all the time: |
|
118 |
||
119 |
END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last |
|
120 |
||
121 |
It works, but it's more work than I want to do. |
|
122 |
||
123 |
Chunker solves this by parsing __END__ tokens for you, and making it |
|
124 |
available in the form of a 'DATA_END' constant. It installs this |
|
125 |
constant into the class that includes Chunker, so you can use it again |
|
126 |
and again, assuming you use a different file for each class. |
|
127 |
||
128 |
It also automatically parses out other things that look like tokens, so |
|
129 |
you can easily have multiple, distinct documents all embedded into the |
|
130 |
__END__ block. |
|
131 |
EOF |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
132 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
133 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
134 |
Rake::GemPackageTask.new( gem ) do |pkg| |
2 | 135 |
pkg.need_zip = true |
136 |
pkg.need_tar = true |
|
137 |
pkg.need_tar_bz2 = true |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
138 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
139 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
140 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
141 |
### Task: install |
2 | 142 |
### |
143 |
task :install_gem => [ :package ] do |
|
144 |
$stderr.puts |
|
145 |
installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" ) |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
146 |
installer.install |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
147 |
end |
2 | 148 |
task :install => [ :install_gem ] |
149 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
150 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
151 |
### Task: uninstall |
2 | 152 |
### |
153 |
task :uninstall_gem do |
|
154 |
uninstaller = Gem::Uninstaller.new( PKG_NAME ) |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
155 |
uninstaller.uninstall |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
156 |
end |
2 | 157 |
task :uninstall => [ :uninstall_gem ] |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
158 |