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