typo 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/admin/comments_controller.rb +1 -1
- data/app/controllers/admin/content_controller.rb +1 -3
- data/app/controllers/admin/feedback_controller.rb +36 -31
- data/app/controllers/admin/sidebar_controller.rb +13 -2
- data/app/controllers/admin/users_controller.rb +2 -1
- data/app/controllers/articles_controller.rb +10 -19
- data/app/controllers/xml_controller.rb +2 -2
- data/app/helpers/admin/base_helper.rb +7 -3
- data/app/helpers/application_helper.rb +2 -2
- data/app/helpers/articles_helper.rb +5 -4
- data/app/models/article.rb +16 -10
- data/app/models/blog.rb +4 -10
- data/app/models/comment.rb +17 -36
- data/app/models/content.rb +31 -53
- data/app/models/content_state/base.rb +46 -3
- data/app/models/content_state/draft.rb +2 -9
- data/app/models/content_state/ham.rb +31 -0
- data/app/models/content_state/just_marked_as_ham.rb +10 -0
- data/app/models/content_state/just_marked_as_spam.rb +23 -0
- data/app/models/content_state/just_presumed_ham.rb +37 -0
- data/app/models/content_state/just_published.rb +15 -8
- data/app/models/content_state/new.rb +3 -10
- data/app/models/content_state/presumed_ham.rb +27 -0
- data/app/models/content_state/presumed_spam.rb +31 -0
- data/app/models/content_state/publication_pending.rb +7 -9
- data/app/models/content_state/published.rb +10 -9
- data/app/models/content_state/spam.rb +23 -0
- data/app/models/content_state/unclassified.rb +29 -0
- data/app/models/content_state/withdrawn.rb +28 -0
- data/app/models/email_notifier.rb +0 -1
- data/app/models/feedback.rb +151 -0
- data/app/models/trackback.rb +22 -29
- data/app/views/admin/feedback/_item.rhtml +5 -5
- data/app/views/admin/feedback/list.rhtml +13 -11
- data/app/views/admin/general/index.rhtml +8 -4
- data/app/views/admin/users/show.rhtml +7 -1
- data/app/views/articles/read.rhtml +2 -2
- data/bin/typo +7 -6
- data/components/plugins/sidebars/recent_comments_controller.rb +1 -1
- data/config/environment.rb +2 -0
- data/db/migrate/046_fixup_forthcoming_publications.rb +1 -1
- data/db/migrate/048_remove_count_caching.rb +31 -0
- data/db/migrate/049_move_feedback_to_new_state_machine.rb +33 -0
- data/db/schema.mysql-v3.sql +3 -4
- data/db/schema.mysql.sql +3 -4
- data/db/schema.postgresql.sql +3 -4
- data/db/schema.rb +12 -17
- data/db/schema.sqlite.sql +3 -4
- data/db/schema.sqlserver.sql +3 -4
- data/db/schema_version +1 -1
- data/doc/Installer.txt +4 -0
- data/lib/jabber_notify.rb +6 -2
- data/lib/sidebars/plugin.rb +2 -1
- data/lib/tasks/release.rake +5 -4
- data/lib/typo_version.rb +1 -1
- data/public/stylesheets/administration.css +22 -2
- data/test/fixtures/blogs.yml +2 -0
- data/test/fixtures/contents.yml +7 -7
- data/test/functional/admin/users_controller_test.rb +3 -0
- data/test/functional/articles_controller_test.rb +16 -1
- data/test/mocks/test/xmlrpc_mock.rb +5 -4
- data/test/unit/article_test.rb +16 -4
- data/test/unit/comment_test.rb +57 -35
- data/test/unit/content_state/factory_test.rb +7 -6
- data/test/unit/ping_test.rb +14 -0
- data/test/unit/trackback_test.rb +16 -15
- metadata +26 -26
- data/config/database.yml-pgsql +0 -17
- data/config/database.yml.sqlite +0 -14
- data/config/mail.yml +0 -8
- data/config/mongrel.conf +0 -2
- data/db/converters/mt-import.rb +0 -72
- data/db/development_structure.sql +0 -691
- data/installer/rails-installer.rb +0 -527
- data/installer/rails-installer/commands.rb +0 -118
- data/installer/rails-installer/web-servers.rb +0 -110
- data/log/development.log-1 +0 -991
- data/log/development.log-2 +0 -422
- data/log/development.log-3 +0 -429
- data/log/development.log-4 +0 -174
- data/svk-commitP6cVv.tmp +0 -1
- data/vendor/ruby-mp3info/lib/mp3info.rb +0 -720
@@ -1,527 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'readline'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'yaml'
|
5
|
-
require 'digest/sha1'
|
6
|
-
|
7
|
-
require 'installer/rails-installer/web-servers'
|
8
|
-
require 'installer/rails-installer/commands'
|
9
|
-
|
10
|
-
class RailsInstaller
|
11
|
-
include FileUtils
|
12
|
-
attr_accessor :install_directory, :source_directory, :config
|
13
|
-
attr_accessor :message_proc
|
14
|
-
|
15
|
-
class InstallFailed < StandardError; end
|
16
|
-
|
17
|
-
@@rails_version = nil
|
18
|
-
|
19
|
-
def self.application_name(name)
|
20
|
-
@@app_name = name
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.support_location(location)
|
24
|
-
@@support_location = location
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.rails_version(svn_tag)
|
28
|
-
@@rails_version = svn_tag
|
29
|
-
end
|
30
|
-
|
31
|
-
def app_name
|
32
|
-
@@app_name
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(install_directory)
|
36
|
-
# use an absolute path, not a relative path.
|
37
|
-
if install_directory
|
38
|
-
@install_directory = File.expand_path(install_directory)
|
39
|
-
end
|
40
|
-
|
41
|
-
@config = read_yml(config_file) rescue nil
|
42
|
-
@config ||= Hash.new
|
43
|
-
end
|
44
|
-
|
45
|
-
# Display a status message
|
46
|
-
def message(string)
|
47
|
-
if message_proc
|
48
|
-
message_proc.call(string)
|
49
|
-
else
|
50
|
-
STDERR.puts string
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Install Application
|
55
|
-
def install(version=nil)
|
56
|
-
@source_directory = find_source_directory(@@app_name,version)
|
57
|
-
|
58
|
-
# Merge default configuration settings
|
59
|
-
@config = read_yml(backup_config_file).merge(config)
|
60
|
-
|
61
|
-
install_sequence
|
62
|
-
|
63
|
-
message ''
|
64
|
-
message "#{@@app_name.capitalize} is now running on http://#{`hostname`.chomp}:#{config['port-number']}"
|
65
|
-
message "Use '#{@@app_name} start #{install_directory}' to restart after boot."
|
66
|
-
message "Look in installer/*.conf.example to see how to integrate with your web server."
|
67
|
-
end
|
68
|
-
|
69
|
-
# The default install sequence. Override this if you need to add extra
|
70
|
-
# steps to the installer.
|
71
|
-
def install_sequence
|
72
|
-
stop
|
73
|
-
|
74
|
-
backup_database
|
75
|
-
install_pre_hook
|
76
|
-
pre_migrate_database
|
77
|
-
copy_files
|
78
|
-
freeze_rails
|
79
|
-
create_default_config_files
|
80
|
-
fix_permissions
|
81
|
-
create_directories
|
82
|
-
create_initial_database
|
83
|
-
set_initial_port_number
|
84
|
-
expand_template_files
|
85
|
-
|
86
|
-
migrate
|
87
|
-
install_post_hook
|
88
|
-
save
|
89
|
-
|
90
|
-
run_rails_tests
|
91
|
-
|
92
|
-
start
|
93
|
-
end
|
94
|
-
|
95
|
-
def install_pre_hook
|
96
|
-
end
|
97
|
-
|
98
|
-
def install_post_hook
|
99
|
-
end
|
100
|
-
|
101
|
-
# Start application in the background
|
102
|
-
def start(foreground = false)
|
103
|
-
server_class = RailsInstaller::WebServer.servers[config['web-server']]
|
104
|
-
if not server_class
|
105
|
-
message "** warning: web-server #{config['web-server']} unknown. Use 'web-server=external' to disable."
|
106
|
-
end
|
107
|
-
|
108
|
-
server_class.start(self,foreground)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Stop application
|
112
|
-
def stop
|
113
|
-
return unless File.directory?(install_directory)
|
114
|
-
|
115
|
-
server_class = RailsInstaller::WebServer.servers[config['web-server']]
|
116
|
-
if not server_class
|
117
|
-
message "** warning: web-server #{config['web-server']} unknown. Use 'web-server=external' to disable."
|
118
|
-
end
|
119
|
-
|
120
|
-
server_class.stop(self)
|
121
|
-
end
|
122
|
-
|
123
|
-
# private
|
124
|
-
|
125
|
-
# The name of the sqlite database file
|
126
|
-
def db_file
|
127
|
-
File.join(install_directory,'db','database.sqlite')
|
128
|
-
end
|
129
|
-
|
130
|
-
# Backup the database
|
131
|
-
def backup_database
|
132
|
-
return unless File.exists? db_file
|
133
|
-
|
134
|
-
return unless config['database'] == 'sqlite'
|
135
|
-
new_db_file = db_file+"-#{Time.now.strftime('%Y%m%d-%H%M')}.sql"
|
136
|
-
|
137
|
-
message "Backing up existing SQLite database into #{new_db_file}"
|
138
|
-
system("sqlite3 #{db_file} .dump > #{new_db_file}")
|
139
|
-
end
|
140
|
-
|
141
|
-
# Copy files from the source directory to the target directory.
|
142
|
-
def copy_files
|
143
|
-
message "Checking for existing #{@@app_name.capitalize} install in #{install_directory}"
|
144
|
-
files_yml = File.join(install_directory,'installer','files.yml')
|
145
|
-
old_files = read_yml(files_yml) rescue Hash.new
|
146
|
-
|
147
|
-
message "Reading files from #{source_directory}"
|
148
|
-
new_files = sha1_hash_directory_tree(source_directory)
|
149
|
-
new_files.delete('/config/database.yml') # Never copy this.
|
150
|
-
|
151
|
-
# Next, we compare the original install hash to the current hash. For each
|
152
|
-
# entry:
|
153
|
-
#
|
154
|
-
# - in new_file but not in old_files: copy
|
155
|
-
# - in old files but not in new_files: delete
|
156
|
-
# - in both, but hash different: copy
|
157
|
-
# - in both, hash same: don't copy
|
158
|
-
#
|
159
|
-
# We really should add a third hash (existing_files) and compare against that
|
160
|
-
# so we don't overwrite changed files.
|
161
|
-
|
162
|
-
added, changed, deleted, same = hash_diff(old_files, new_files)
|
163
|
-
|
164
|
-
if added.size > 0
|
165
|
-
message "Copying #{added.size} new files into #{install_directory}"
|
166
|
-
added.keys.sort.each do |file|
|
167
|
-
message " copying #{file}"
|
168
|
-
copy_one_file(file)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
if changed.size > 0
|
173
|
-
message "Updating #{changed.size} files in #{install_directory}"
|
174
|
-
changed.keys.sort.each do |file|
|
175
|
-
message " updating #{file}"
|
176
|
-
copy_one_file(file)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
if deleted.size > 0
|
181
|
-
message "Deleting #{deleted.size} files from #{install_directory}"
|
182
|
-
|
183
|
-
deleted.keys.sort.each do |file|
|
184
|
-
message " deleting #{file}"
|
185
|
-
rm(File.join(install_directory,file))
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
write_yml(files_yml,new_files)
|
190
|
-
end
|
191
|
-
|
192
|
-
# Copy one file from source_directory to install_directory, creating directories as needed.
|
193
|
-
def copy_one_file(filename)
|
194
|
-
source_name = File.join(source_directory,filename)
|
195
|
-
install_name = File.join(install_directory,filename)
|
196
|
-
dir_name = File.dirname(install_name)
|
197
|
-
|
198
|
-
mkdir_p(dir_name)
|
199
|
-
cp(source_name,install_name,:preserve => true)
|
200
|
-
end
|
201
|
-
|
202
|
-
# Compute the different between two hashes. Returns four hashes,
|
203
|
-
# one contains the keys that are in 'b' but not in 'a' (added entries),
|
204
|
-
# the next contains keys that are in 'a' and 'b', but have different values
|
205
|
-
# (changed). The third contains keys that are in 'b' but not 'a' (added).
|
206
|
-
# The final hash contains items that are the same in each.
|
207
|
-
def hash_diff(a, b)
|
208
|
-
added = {}
|
209
|
-
changed = {}
|
210
|
-
deleted = {}
|
211
|
-
same = {}
|
212
|
-
|
213
|
-
seen = {}
|
214
|
-
|
215
|
-
a.each_key do |k|
|
216
|
-
seen[k] = true
|
217
|
-
|
218
|
-
if b.has_key? k
|
219
|
-
if b[k] == a[k]
|
220
|
-
same[k] = true
|
221
|
-
else
|
222
|
-
changed[k] = true
|
223
|
-
end
|
224
|
-
else
|
225
|
-
deleted[k] = true
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
b.each_key do |k|
|
230
|
-
unless seen[k]
|
231
|
-
added[k] = true
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
[added, changed, deleted, same]
|
236
|
-
end
|
237
|
-
|
238
|
-
# Freeze to a specific version of Rails
|
239
|
-
def freeze_rails
|
240
|
-
return unless @@rails_version
|
241
|
-
version_file = File.join(install_directory,'vendor','rails-version')
|
242
|
-
vendor_rails = File.join(install_directory,'vendor','rails')
|
243
|
-
|
244
|
-
old_version = File.read(version_file).chomp rescue nil
|
245
|
-
|
246
|
-
if @@rails_version == old_version
|
247
|
-
return
|
248
|
-
elsif old_version != nil
|
249
|
-
rm_rf(vendor_rails)
|
250
|
-
end
|
251
|
-
|
252
|
-
mkdir_p(vendor_rails)
|
253
|
-
|
254
|
-
package_map = {
|
255
|
-
'rails' => File.join(vendor_rails,'railties'),
|
256
|
-
'actionmailer' => File.join(vendor_rails,'actionmailer'),
|
257
|
-
'actionpack' => File.join(vendor_rails,'actionpack'),
|
258
|
-
'actionwebservice' => File.join(vendor_rails,'actionwebservice'),
|
259
|
-
'activerecord' => File.join(vendor_rails,'activerecord'),
|
260
|
-
'activesupport' => File.join(vendor_rails,'activesupport'),
|
261
|
-
}
|
262
|
-
|
263
|
-
specs = Gem.source_index.find_name('rails',["= #{@@rails_version}"])
|
264
|
-
|
265
|
-
unless specs.to_a.size > 0
|
266
|
-
raise InstallFailed, "Can't locate Rails #{@@rails_version}!"
|
267
|
-
end
|
268
|
-
|
269
|
-
copy_gem(specs.first, package_map[specs.first.name])
|
270
|
-
|
271
|
-
specs.first.dependencies.each do |dep|
|
272
|
-
next unless package_map[dep.name]
|
273
|
-
|
274
|
-
dep_spec = Gem.source_index.find_name(dep.name,[dep.version_requirements.to_s])
|
275
|
-
if dep_spec.size == 0
|
276
|
-
raise InstallFailed, "Can't locate dependency #{dep.name} #{dep.version_requirements.to_s}"
|
277
|
-
end
|
278
|
-
|
279
|
-
copy_gem(dep_spec.first, package_map[dep.name])
|
280
|
-
end
|
281
|
-
|
282
|
-
File.open(version_file,'w') do |f|
|
283
|
-
f.puts @@rails_version
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
def copy_gem(spec, destination)
|
288
|
-
message("copying #{spec.name} #{spec.version} to #{destination}")
|
289
|
-
cp_r("#{spec.full_gem_path}/.",destination)
|
290
|
-
end
|
291
|
-
|
292
|
-
# Create all default config files
|
293
|
-
def create_default_config_files
|
294
|
-
create_default_database_yml
|
295
|
-
end
|
296
|
-
|
297
|
-
# Create the default database.yml
|
298
|
-
def create_default_database_yml
|
299
|
-
database_yml = File.join(install_directory,'config','database.yml')
|
300
|
-
|
301
|
-
if File.exist?(database_yml)
|
302
|
-
message "Preserving database.yml"
|
303
|
-
return
|
304
|
-
end
|
305
|
-
|
306
|
-
message "Creating default database configuration file"
|
307
|
-
cp("#{database_yml}.#{config['database']}",database_yml)
|
308
|
-
end
|
309
|
-
|
310
|
-
def fix_permissions
|
311
|
-
unless RUBY_PLATFORM =~ /mswin32/
|
312
|
-
message "Making scripts executable"
|
313
|
-
chmod 0555, File.join(install_directory,'public','dispatch.fcgi')
|
314
|
-
chmod 0555, File.join(install_directory,'public','dispatch.cgi')
|
315
|
-
chmod 0555, Dir[File.join(install_directory,'script','*')]
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
# Create required directories, like tmp
|
320
|
-
def create_directories
|
321
|
-
mkdir_p(File.join(install_directory,'tmp','cache'))
|
322
|
-
chmod(755, File.join(install_directory,'tmp','cache'))
|
323
|
-
mkdir_p(File.join(install_directory,'tmp','session'))
|
324
|
-
mkdir_p(File.join(install_directory,'tmp','sockets'))
|
325
|
-
mkdir_p(File.join(install_directory,'log'))
|
326
|
-
File.open(File.join(install_directory,'log','development.log'),'w')
|
327
|
-
File.open(File.join(install_directory,'log','production.log'),'w')
|
328
|
-
File.open(File.join(install_directory,'log','testing.log'),'w')
|
329
|
-
end
|
330
|
-
|
331
|
-
# Create the initial SQLite database
|
332
|
-
def create_initial_database
|
333
|
-
return if File.exists? db_file
|
334
|
-
return unless config['database'] == 'sqlite'
|
335
|
-
|
336
|
-
message "Creating initial #{@@app_name.capitalize} SQLite database"
|
337
|
-
schema_file = File.join(install_directory,'db','schema.sqlite.sql')
|
338
|
-
system("sqlite3 #{db_file} < #{schema_file}")
|
339
|
-
end
|
340
|
-
|
341
|
-
# Get the current schema version
|
342
|
-
def get_schema_version
|
343
|
-
File.read(File.join(install_directory,'db','schema_version')).to_i rescue 0
|
344
|
-
end
|
345
|
-
|
346
|
-
# The path to the installed config file
|
347
|
-
def config_file
|
348
|
-
File.join(install_directory,'installer','rails_installer.yml')
|
349
|
-
end
|
350
|
-
|
351
|
-
# The path to the config file that comes with the GEM
|
352
|
-
def backup_config_file
|
353
|
-
File.join(source_directory,'installer','rails_installer_defaults.yml')
|
354
|
-
end
|
355
|
-
|
356
|
-
# Pick a default port number
|
357
|
-
def set_initial_port_number
|
358
|
-
config['port-number'] ||= (rand(1000)+4000)
|
359
|
-
end
|
360
|
-
|
361
|
-
def pre_migrate_database
|
362
|
-
old_schema_version = get_schema_version
|
363
|
-
new_schema_version = File.read(File.join(source_directory,'db','schema_version')).to_i
|
364
|
-
|
365
|
-
return unless old_schema_version > 0
|
366
|
-
|
367
|
-
|
368
|
-
# Are we downgrading?
|
369
|
-
if old_schema_version > new_schema_version
|
370
|
-
message "Downgrading schema from #{old_schema_version} to #{new_schema_version}"
|
371
|
-
|
372
|
-
in_directory install_directory do
|
373
|
-
unless system("rake -s migrate VERSION=#{new_schema_version}")
|
374
|
-
raise InstallFailed, "Downgrade migrating from #{old_schema_version} to #{new_schema_version} failed."
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
# Migrate the database
|
381
|
-
def migrate
|
382
|
-
message "Migrating #{@@app_name.capitalize}'s database to newest release"
|
383
|
-
|
384
|
-
in_directory install_directory do
|
385
|
-
unless system("rake -s migrate")
|
386
|
-
raise InstallFailed, "Migration failed"
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
# Sweep the cache
|
392
|
-
def run_rails_tests
|
393
|
-
message "Running tests. This may take a minute or two"
|
394
|
-
|
395
|
-
in_directory install_directory do
|
396
|
-
if system_silently("rake -s test")
|
397
|
-
message "All tests pass. Congratulations."
|
398
|
-
else
|
399
|
-
message "***** Tests failed *****"
|
400
|
-
message "** Please run 'rake test' by hand in your install directory."
|
401
|
-
message "** Report problems to #{@@support_location}."
|
402
|
-
message "***** Tests failed *****"
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
def sha1_hash_directory_tree(directory, prefix='', hash={})
|
408
|
-
Dir.entries(directory).each do |file|
|
409
|
-
next if file =~ /^\./
|
410
|
-
pathname = File.join(directory,file)
|
411
|
-
if File.directory?(pathname)
|
412
|
-
sha1_hash_directory_tree(pathname, File.join(prefix,file), hash)
|
413
|
-
else
|
414
|
-
hash[File.join(prefix,file)] = Digest::SHA1.hexdigest(File.read(pathname))
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
hash
|
419
|
-
end
|
420
|
-
|
421
|
-
def save
|
422
|
-
write_yml(config_file,@config)
|
423
|
-
end
|
424
|
-
|
425
|
-
def read_yml(filename)
|
426
|
-
YAML.load(File.read(filename))
|
427
|
-
end
|
428
|
-
|
429
|
-
def write_yml(filename,object)
|
430
|
-
File.open(filename,'w') do |f|
|
431
|
-
f.write(YAML.dump(object))
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
# Locate the source directory for a specific Version
|
436
|
-
def find_source_directory(gem_name, version)
|
437
|
-
if version == 'cwd'
|
438
|
-
return Dir.pwd
|
439
|
-
elsif version
|
440
|
-
version_array = ["= #{version}"]
|
441
|
-
else
|
442
|
-
version_array = ["> 0.0.0"]
|
443
|
-
end
|
444
|
-
|
445
|
-
specs = Gem.source_index.find_name(gem_name,version_array)
|
446
|
-
unless specs.to_a.size > 0
|
447
|
-
raise InstallFailed, "Can't locate version #{version}!"
|
448
|
-
end
|
449
|
-
|
450
|
-
specs.last.full_gem_path
|
451
|
-
end
|
452
|
-
|
453
|
-
def system_silently(command)
|
454
|
-
if RUBY_PLATFORM =~ /mswin32/
|
455
|
-
null = 'NUL:'
|
456
|
-
else
|
457
|
-
null = '/dev/null'
|
458
|
-
end
|
459
|
-
|
460
|
-
system("#{command} > #{null} 2> #{null}")
|
461
|
-
end
|
462
|
-
|
463
|
-
def expand_template_files
|
464
|
-
rails_host = config['bind-address'] || `hostname`.chomp
|
465
|
-
rails_port = config['port-number'].to_s
|
466
|
-
rails_url = "http://#{rails_host}:#{rails_port}"
|
467
|
-
Dir[File.join(install_directory,'installer','*.template')].each do |template_file|
|
468
|
-
output_file = template_file.gsub(/\.template/,'')
|
469
|
-
next if File.exists?(output_file) # don't overwrite files
|
470
|
-
|
471
|
-
message "expanding #{File.basename(output_file)} template"
|
472
|
-
|
473
|
-
text = File.read(template_file).gsub(/\$RAILS_URL/,rails_url).gsub(/\$RAILS_HOST/,rails_host).gsub(/\$RAILS_PORT/,rails_port)
|
474
|
-
|
475
|
-
File.open(output_file,'w') do |f|
|
476
|
-
f.write text
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
# Execute a command-line command
|
482
|
-
def execute_command(*args)
|
483
|
-
if args.size < 2
|
484
|
-
display_help
|
485
|
-
exit(1)
|
486
|
-
end
|
487
|
-
|
488
|
-
command_class = Command.commands[args.first]
|
489
|
-
|
490
|
-
if command_class
|
491
|
-
command_class.command(self,*(args[2..-1]))
|
492
|
-
else
|
493
|
-
display_help
|
494
|
-
exit(1)
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
def display_help(error=nil)
|
499
|
-
STDERR.puts error if error
|
500
|
-
|
501
|
-
commands = Command.commands.keys.sort
|
502
|
-
commands.each do |cmd|
|
503
|
-
cmd_class = Command.commands[cmd]
|
504
|
-
flag_help = cmd_class.flag_help_text.gsub(/APPNAME/,app_name)
|
505
|
-
help = cmd_class.help_text.gsub(/APPNAME/,app_name)
|
506
|
-
|
507
|
-
STDERR.puts " #{app_name} #{cmd} DIRECTORY #{flag_help}"
|
508
|
-
STDERR.puts " #{help}"
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
|
-
# Run a block inside of a specific directory. Chdir into the directory
|
514
|
-
# before executing the block, then chdir back to the original directory
|
515
|
-
# when the block exits.
|
516
|
-
def in_directory(directory)
|
517
|
-
begin
|
518
|
-
old_dir = Dir.pwd
|
519
|
-
Dir.chdir(directory)
|
520
|
-
value = yield
|
521
|
-
ensure
|
522
|
-
Dir.chdir(old_dir)
|
523
|
-
end
|
524
|
-
|
525
|
-
return value
|
526
|
-
end
|
527
|
-
|