w2tags 0.9.3 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/COPYING +340 -340
  2. data/LICENSE +6 -6
  3. data/MIT-LICENSE +18 -18
  4. data/Manifest.txt +28 -25
  5. data/README.rdoc +27 -21
  6. data/Rakefile +1 -1
  7. data/VERSION +1 -1
  8. data/bin/w2tags +173 -143
  9. data/doc/History.rdoc +88 -0
  10. data/hot/erb.hot +18 -156
  11. data/hot/erb_base.hot +164 -0
  12. data/hot/html.hot +30 -31
  13. data/hot/rails/scaffold.hot +15 -15
  14. data/hot/vm.hot +8 -8
  15. data/hot/vm2.hot +34 -34
  16. data/hot/vm_crud.hot +34 -34
  17. data/hot/vm_popup.hot +74 -74
  18. data/lib/tags2w.rb +263 -0
  19. data/lib/w2tags/block/block_hot.rb +37 -0
  20. data/lib/w2tags/block/plain_text.rb +57 -57
  21. data/lib/w2tags/block/remark.rb +37 -37
  22. data/lib/w2tags/block/sass.rb +68 -66
  23. data/lib/w2tags/merb_hook.rb +15 -15
  24. data/lib/w2tags/parser.rb +17 -8
  25. data/lib/w2tags/rails_hook.rb +15 -15
  26. data/lib/w2tags/sinatra_hook.rb +74 -50
  27. data/lib/w2tags.rb +100 -100
  28. data/plugins/{/w2tags/ → w2tags}/README +2 -2
  29. data/plugins/{/w2tags//generators//w2scaffold/ → w2tags/generators/w2scaffold}/USAGE +29 -29
  30. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/controller.rb +85 -85
  31. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/functional_test.rb +45 -45
  32. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/helper.rb +2 -2
  33. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/helper_test.rb +4 -4
  34. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/layout.html.erb +17 -17
  35. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/style.css +54 -54
  36. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_edit.html.erb +17 -17
  37. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_edit.html.w2erb +16 -16
  38. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_index.html.erb +23 -23
  39. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_index.html.w2erb +13 -13
  40. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_new.html.erb +16 -16
  41. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_new.html.w2erb +15 -15
  42. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_show.html.erb +9 -9
  43. data/plugins/{/w2tags//generators//w2scaffold//templates/ → w2tags/generators/w2scaffold/templates}/view_show.html.w2erb +8 -8
  44. data/plugins/{/w2tags//generators//w2scaffold/ → w2tags/generators/w2scaffold}/w2scaffold_generator.rb +106 -106
  45. data/plugins/{/w2tags/ → w2tags}/install.rb +0 -0
  46. data/tasks/ann.rake +81 -81
  47. data/tasks/bones.rake +21 -21
  48. data/tasks/gem.rake +126 -126
  49. data/tasks/git.rake +41 -41
  50. data/tasks/manifest.rake +49 -49
  51. data/tasks/notes.rake +28 -28
  52. data/tasks/post_load.rake +39 -39
  53. data/tasks/rdoc.rake +51 -51
  54. data/tasks/rubyforge.rake +57 -57
  55. data/tasks/setup.rb +268 -268
  56. data/tasks/spec.rake +55 -55
  57. data/tasks/svn.rake +48 -48
  58. data/tasks/test.rake +38 -38
  59. data/test/vars.hot +30 -30
  60. data/test/w2tags_basic_usability.rb +187 -187
  61. data/test/w2tags_enlightning.rb +42 -42
  62. data/test/w2tags_hot.rb +85 -85
  63. data/test/w2tags_hot_var.rb +115 -115
  64. metadata +28 -30
data/tasks/rubyforge.rake CHANGED
@@ -1,57 +1,57 @@
1
-
2
- if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
3
-
4
- require 'rubyforge'
5
- require 'rake/contrib/sshpublisher'
6
-
7
- namespace :gem do
8
- desc 'Package and upload to RubyForge'
9
- task :release => [:clobber, 'gem:package'] do |t|
10
- v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
- abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
- pkg = "pkg/#{PROJ.gem._spec.full_name}"
13
-
14
- if $DEBUG then
15
- puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
16
- puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
17
- end
18
-
19
- rf = RubyForge.new
20
- rf.configure rescue nil
21
- puts 'Logging in'
22
- rf.login
23
-
24
- c = rf.userconfig
25
- c['release_notes'] = PROJ.description if PROJ.description
26
- c['release_changes'] = PROJ.changes if PROJ.changes
27
- c['preformatted'] = true
28
-
29
- files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
- (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
- "#{pkg}.gem"].compact
32
-
33
- puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
- rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
35
- end
36
- end # namespace :gem
37
-
38
-
39
- namespace :doc do
40
- desc "Publish RDoc to RubyForge"
41
- task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
- config = YAML.load(
43
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
- )
45
-
46
- host = "#{config['username']}@rubyforge.org"
47
- remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
48
- remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
49
- local_dir = PROJ.rdoc.dir
50
-
51
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
- end
53
- end # namespace :doc
54
-
55
- end # if HAVE_RUBYFORGE
56
-
57
- # EOF
1
+
2
+ if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
3
+
4
+ require 'rubyforge'
5
+ require 'rake/contrib/sshpublisher'
6
+
7
+ namespace :gem do
8
+ desc 'Package and upload to RubyForge'
9
+ task :release => [:clobber, 'gem:package'] do |t|
10
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
+ pkg = "pkg/#{PROJ.gem._spec.full_name}"
13
+
14
+ if $DEBUG then
15
+ puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
16
+ puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
17
+ end
18
+
19
+ rf = RubyForge.new
20
+ rf.configure rescue nil
21
+ puts 'Logging in'
22
+ rf.login
23
+
24
+ c = rf.userconfig
25
+ c['release_notes'] = PROJ.description if PROJ.description
26
+ c['release_changes'] = PROJ.changes if PROJ.changes
27
+ c['preformatted'] = true
28
+
29
+ files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
+ (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
+ "#{pkg}.gem"].compact
32
+
33
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
+ rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
35
+ end
36
+ end # namespace :gem
37
+
38
+
39
+ namespace :doc do
40
+ desc "Publish RDoc to RubyForge"
41
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
+ config = YAML.load(
43
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
+ )
45
+
46
+ host = "#{config['username']}@rubyforge.org"
47
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
48
+ remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
49
+ local_dir = PROJ.rdoc.dir
50
+
51
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
+ end
53
+ end # namespace :doc
54
+
55
+ end # if HAVE_RUBYFORGE
56
+
57
+ # EOF
data/tasks/setup.rb CHANGED
@@ -1,268 +1,268 @@
1
- # $Id$
2
-
3
- require 'rubygems'
4
- require 'rake'
5
- require 'rake/clean'
6
- require 'fileutils'
7
- require 'ostruct'
8
-
9
- class OpenStruct; undef :gem; end
10
-
11
- PROJ = OpenStruct.new(
12
- # Project Defaults
13
- :name => 'w2tags',
14
- :summary => 'Its Way to Tags',
15
- :description => 'w2tags is the way to tags, a short cut / macros. when it do it use some patern define in files (HOT file) to produce tags from minimal code to become full fledge tags',
16
- :changes => nil,
17
- :authors => 'Widi Harsojo',
18
- :email => 'wharsojo@gmail.com',
19
- :url => "\000",
20
- :version => ENV['VERSION'] || '0.9.3',
21
- :exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
22
- :release_name => ENV['RELEASE'],
23
-
24
- # System Defaults
25
- :ruby_opts => %w(-w),
26
- :libs => [],
27
- :manifest_file => 'Manifest.txt',
28
- :history_file => 'doc/History.rdoc',
29
- :readme_file => 'README.rdoc',
30
-
31
- # Announce
32
- :ann => OpenStruct.new(
33
- :file => 'announcement.txt',
34
- :text => nil,
35
- :paragraphs => [],
36
- :email => {
37
- :from => nil,
38
- :to => %w(ruby-talk@ruby-lang.org),
39
- :server => 'localhost',
40
- :port => 25,
41
- :domain => ENV['HOSTNAME'],
42
- :acct => nil,
43
- :passwd => nil,
44
- :authtype => :plain
45
- }
46
- ),
47
-
48
- # Gem Packaging
49
- :gem => OpenStruct.new(
50
- :dependencies => [],
51
- :executables => nil,
52
- :extensions => FileList['ext/**/extconf.rb'],
53
- :files => nil,
54
- :need_tar => false,
55
- :need_zip => false,
56
- :extras => {}
57
- ),
58
-
59
- # File Annotations
60
- :notes => OpenStruct.new(
61
- :exclude => %w(^tasks/setup\.rb$),
62
- :extensions => %w(.txt .rb .erb) << '',
63
- :tags => %w(FIXME OPTIMIZE TODO)
64
- ),
65
-
66
- # Rcov
67
- :rcov => OpenStruct.new(
68
- :dir => 'coverage',
69
- :opts => %w[--sort coverage -T],
70
- :threshold => 90.0,
71
- :threshold_exact => false
72
- ),
73
-
74
- # Rdoc
75
- :rdoc => OpenStruct.new(
76
- :opts => [],
77
- :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$ MIT-LICENSE COPYING),
78
- :exclude => %w(extconf\.rb$),
79
- :main => nil,
80
- :dir => 'doc',
81
- :remote_dir => nil
82
- ),
83
-
84
- # Rubyforge
85
- :rubyforge => OpenStruct.new(
86
- :name => "\000"
87
- ),
88
-
89
- # Rspec
90
- :spec => OpenStruct.new(
91
- :files => FileList['spec/**/*_spec.rb'],
92
- :opts => []
93
- ),
94
-
95
- # Subversion Repository
96
- :svn => OpenStruct.new(
97
- :root => nil,
98
- :path => '',
99
- :trunk => 'trunk',
100
- :tags => 'tags',
101
- :branches => 'branches'
102
- ),
103
-
104
- # Test::Unit
105
- :test => OpenStruct.new(
106
- :files => FileList['test/**/test_*.rb'],
107
- :file => 'test/all.rb',
108
- :opts => []
109
- )
110
- )
111
-
112
- # Load the other rake files in the tasks folder
113
- rakefiles = Dir.glob('tasks/*.rake').sort
114
- rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
115
- import(*rakefiles)
116
-
117
- # Setup the project libraries
118
- %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
119
-
120
- # Setup some constants
121
- WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
122
-
123
- DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
124
-
125
- def quiet( &block )
126
- io = [STDOUT.dup, STDERR.dup]
127
- STDOUT.reopen DEV_NULL
128
- STDERR.reopen DEV_NULL
129
- block.call
130
- ensure
131
- STDOUT.reopen io.first
132
- STDERR.reopen io.last
133
- $stdout, $stderr = STDOUT, STDERR
134
- end
135
-
136
- DIFF = if WIN32 then 'diff.exe'
137
- else
138
- if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
139
- else 'diff' end
140
- end unless defined? DIFF
141
-
142
- SUDO = if WIN32 then ''
143
- else
144
- if quiet {system 'which sudo'} then 'sudo'
145
- else '' end
146
- end
147
-
148
- RCOV = WIN32 ? 'rcov.bat' : 'rcov'
149
- RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
150
- GEM = WIN32 ? 'gem.bat' : 'gem'
151
-
152
- %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
153
- begin
154
- require lib
155
- Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
156
- rescue LoadError
157
- Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
158
- end
159
- end
160
- HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
161
- system("svn --version 2>&1 > #{DEV_NULL}"))
162
- HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
163
- system("git --version 2>&1 > #{DEV_NULL}"))
164
-
165
- # Reads a file at +path+ and spits out an array of the +paragraphs+
166
- # specified.
167
- #
168
- # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
169
- # summary, *description = paragraphs_of('README.txt', 3, 3..8)
170
- #
171
- def paragraphs_of( path, *paragraphs )
172
- title = String === paragraphs.first ? paragraphs.shift : nil
173
- ary = File.read(path).delete("\r").split(/\n\n+/)
174
-
175
- result = if title
176
- tmp, matching = [], false
177
- rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
178
- paragraphs << (0..-1) if paragraphs.empty?
179
-
180
- ary.each do |val|
181
- if val =~ rgxp
182
- break if matching
183
- matching = true
184
- rgxp = %r/^=+/i
185
- elsif matching
186
- tmp << val
187
- end
188
- end
189
- tmp
190
- else ary end
191
-
192
- result.values_at(*paragraphs)
193
- end
194
-
195
- # Adds the given gem _name_ to the current project's dependency list. An
196
- # optional gem _version_ can be given. If omitted, the newest gem version
197
- # will be used.
198
- #
199
- def depend_on( name, version = nil )
200
- spec = Gem.source_index.find_name(name).last
201
- version = spec.version.to_s if version.nil? and !spec.nil?
202
-
203
- PROJ.gem.dependencies << case version
204
- when nil; [name]
205
- when %r/^\d/; [name, ">= #{version}"]
206
- else [name, version] end
207
- end
208
-
209
- # Adds the given arguments to the include path if they are not already there
210
- #
211
- def ensure_in_path( *args )
212
- args.each do |path|
213
- path = File.expand_path(path)
214
- $:.unshift(path) if test(?d, path) and not $:.include?(path)
215
- end
216
- end
217
-
218
- # Find a rake task using the task name and remove any description text. This
219
- # will prevent the task from being displayed in the list of available tasks.
220
- #
221
- def remove_desc_for_task( names )
222
- Array(names).each do |task_name|
223
- task = Rake.application.tasks.find {|t| t.name == task_name}
224
- next if task.nil?
225
- task.instance_variable_set :@comment, nil
226
- end
227
- end
228
-
229
- # Change working directories to _dir_, call the _block_ of code, and then
230
- # change back to the original working directory (the current directory when
231
- # this method was called).
232
- #
233
- def in_directory( dir, &block )
234
- curdir = pwd
235
- begin
236
- cd dir
237
- return block.call
238
- ensure
239
- cd curdir
240
- end
241
- end
242
-
243
- # Scans the current working directory and creates a list of files that are
244
- # candidates to be in the manifest.
245
- #
246
- def manifest_files
247
- files = []
248
- exclude = Regexp.new(PROJ.exclude.join('|'))
249
- Find.find '.' do |path|
250
- path.sub! %r/^(\.\/|\/)/o, ''
251
- next unless test ?f, path
252
- next if path =~ exclude
253
- files << path
254
- end
255
- files.sort!
256
- end
257
-
258
- # We need a "valid" method thtat determines if a string is suitable for use
259
- # in the gem specification.
260
- #
261
- class Object
262
- def valid?
263
- return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
264
- return false
265
- end
266
- end
267
-
268
- # EOF
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ class OpenStruct; undef :gem; end
10
+
11
+ PROJ = OpenStruct.new(
12
+ # Project Defaults
13
+ :name => 'w2tags',
14
+ :summary => 'Its Way to Tags',
15
+ :description => 'w2tags is the way to tags, a short cut / macros. when it do it use some patern define in files (HOT file) to produce tags from minimal code to become full fledge tags',
16
+ :changes => nil,
17
+ :authors => 'Widi Harsojo',
18
+ :email => 'wharsojo@gmail.com',
19
+ :url => "\000",
20
+ :version => ENV['VERSION'] || '0.9.5',
21
+ :exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
22
+ :release_name => ENV['RELEASE'],
23
+
24
+ # System Defaults
25
+ :ruby_opts => %w(-w),
26
+ :libs => [],
27
+ :manifest_file => 'Manifest.txt',
28
+ :history_file => 'doc/History.rdoc',
29
+ :readme_file => 'README.rdoc',
30
+
31
+ # Announce
32
+ :ann => OpenStruct.new(
33
+ :file => 'announcement.txt',
34
+ :text => nil,
35
+ :paragraphs => [],
36
+ :email => {
37
+ :from => nil,
38
+ :to => %w(ruby-talk@ruby-lang.org),
39
+ :server => 'localhost',
40
+ :port => 25,
41
+ :domain => ENV['HOSTNAME'],
42
+ :acct => nil,
43
+ :passwd => nil,
44
+ :authtype => :plain
45
+ }
46
+ ),
47
+
48
+ # Gem Packaging
49
+ :gem => OpenStruct.new(
50
+ :dependencies => [],
51
+ :executables => nil,
52
+ :extensions => FileList['ext/**/extconf.rb'],
53
+ :files => nil,
54
+ :need_tar => false,
55
+ :need_zip => false,
56
+ :extras => {}
57
+ ),
58
+
59
+ # File Annotations
60
+ :notes => OpenStruct.new(
61
+ :exclude => %w(^tasks/setup\.rb$),
62
+ :extensions => %w(.txt .rb .erb) << '',
63
+ :tags => %w(FIXME OPTIMIZE TODO)
64
+ ),
65
+
66
+ # Rcov
67
+ :rcov => OpenStruct.new(
68
+ :dir => 'coverage',
69
+ :opts => %w[--sort coverage -T],
70
+ :threshold => 90.0,
71
+ :threshold_exact => false
72
+ ),
73
+
74
+ # Rdoc
75
+ :rdoc => OpenStruct.new(
76
+ :opts => [],
77
+ :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$ MIT-LICENSE COPYING),
78
+ :exclude => %w(extconf\.rb$),
79
+ :main => nil,
80
+ :dir => 'doc',
81
+ :remote_dir => nil
82
+ ),
83
+
84
+ # Rubyforge
85
+ :rubyforge => OpenStruct.new(
86
+ :name => "\000"
87
+ ),
88
+
89
+ # Rspec
90
+ :spec => OpenStruct.new(
91
+ :files => FileList['spec/**/*_spec.rb'],
92
+ :opts => []
93
+ ),
94
+
95
+ # Subversion Repository
96
+ :svn => OpenStruct.new(
97
+ :root => nil,
98
+ :path => '',
99
+ :trunk => 'trunk',
100
+ :tags => 'tags',
101
+ :branches => 'branches'
102
+ ),
103
+
104
+ # Test::Unit
105
+ :test => OpenStruct.new(
106
+ :files => FileList['test/**/test_*.rb'],
107
+ :file => 'test/all.rb',
108
+ :opts => []
109
+ )
110
+ )
111
+
112
+ # Load the other rake files in the tasks folder
113
+ rakefiles = Dir.glob('tasks/*.rake').sort
114
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
115
+ import(*rakefiles)
116
+
117
+ # Setup the project libraries
118
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
119
+
120
+ # Setup some constants
121
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
122
+
123
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
124
+
125
+ def quiet( &block )
126
+ io = [STDOUT.dup, STDERR.dup]
127
+ STDOUT.reopen DEV_NULL
128
+ STDERR.reopen DEV_NULL
129
+ block.call
130
+ ensure
131
+ STDOUT.reopen io.first
132
+ STDERR.reopen io.last
133
+ $stdout, $stderr = STDOUT, STDERR
134
+ end
135
+
136
+ DIFF = if WIN32 then 'diff.exe'
137
+ else
138
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
139
+ else 'diff' end
140
+ end unless defined? DIFF
141
+
142
+ SUDO = if WIN32 then ''
143
+ else
144
+ if quiet {system 'which sudo'} then 'sudo'
145
+ else '' end
146
+ end
147
+
148
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
149
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
150
+ GEM = WIN32 ? 'gem.bat' : 'gem'
151
+
152
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
153
+ begin
154
+ require lib
155
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
156
+ rescue LoadError
157
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
158
+ end
159
+ end
160
+ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
161
+ system("svn --version 2>&1 > #{DEV_NULL}"))
162
+ HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
163
+ system("git --version 2>&1 > #{DEV_NULL}"))
164
+
165
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
166
+ # specified.
167
+ #
168
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
169
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
170
+ #
171
+ def paragraphs_of( path, *paragraphs )
172
+ title = String === paragraphs.first ? paragraphs.shift : nil
173
+ ary = File.read(path).delete("\r").split(/\n\n+/)
174
+
175
+ result = if title
176
+ tmp, matching = [], false
177
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
178
+ paragraphs << (0..-1) if paragraphs.empty?
179
+
180
+ ary.each do |val|
181
+ if val =~ rgxp
182
+ break if matching
183
+ matching = true
184
+ rgxp = %r/^=+/i
185
+ elsif matching
186
+ tmp << val
187
+ end
188
+ end
189
+ tmp
190
+ else ary end
191
+
192
+ result.values_at(*paragraphs)
193
+ end
194
+
195
+ # Adds the given gem _name_ to the current project's dependency list. An
196
+ # optional gem _version_ can be given. If omitted, the newest gem version
197
+ # will be used.
198
+ #
199
+ def depend_on( name, version = nil )
200
+ spec = Gem.source_index.find_name(name).last
201
+ version = spec.version.to_s if version.nil? and !spec.nil?
202
+
203
+ PROJ.gem.dependencies << case version
204
+ when nil; [name]
205
+ when %r/^\d/; [name, ">= #{version}"]
206
+ else [name, version] end
207
+ end
208
+
209
+ # Adds the given arguments to the include path if they are not already there
210
+ #
211
+ def ensure_in_path( *args )
212
+ args.each do |path|
213
+ path = File.expand_path(path)
214
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
215
+ end
216
+ end
217
+
218
+ # Find a rake task using the task name and remove any description text. This
219
+ # will prevent the task from being displayed in the list of available tasks.
220
+ #
221
+ def remove_desc_for_task( names )
222
+ Array(names).each do |task_name|
223
+ task = Rake.application.tasks.find {|t| t.name == task_name}
224
+ next if task.nil?
225
+ task.instance_variable_set :@comment, nil
226
+ end
227
+ end
228
+
229
+ # Change working directories to _dir_, call the _block_ of code, and then
230
+ # change back to the original working directory (the current directory when
231
+ # this method was called).
232
+ #
233
+ def in_directory( dir, &block )
234
+ curdir = pwd
235
+ begin
236
+ cd dir
237
+ return block.call
238
+ ensure
239
+ cd curdir
240
+ end
241
+ end
242
+
243
+ # Scans the current working directory and creates a list of files that are
244
+ # candidates to be in the manifest.
245
+ #
246
+ def manifest_files
247
+ files = []
248
+ exclude = Regexp.new(PROJ.exclude.join('|'))
249
+ Find.find '.' do |path|
250
+ path.sub! %r/^(\.\/|\/)/o, ''
251
+ next unless test ?f, path
252
+ next if path =~ exclude
253
+ files << path
254
+ end
255
+ files.sort!
256
+ end
257
+
258
+ # We need a "valid" method thtat determines if a string is suitable for use
259
+ # in the gem specification.
260
+ #
261
+ class Object
262
+ def valid?
263
+ return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
264
+ return false
265
+ end
266
+ end
267
+
268
+ # EOF