jumpstart 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -139,7 +139,7 @@ Can be omitted or left blank.
|
|
139
139
|
List files that you would like to perform string substitution on. This can be useful for populating files such as a capistrano deploy.rb file.
|
140
140
|
Paths use the newly created project folder as root.
|
141
141
|
Any key:value pair can be used for substitution, simply add the key name in CAPS to the template file then specify the symbol key and value as in the example.
|
142
|
-
|
142
|
+
As of version 0.5 it is now possible to append _CLASS to the capitalized key name in your templates. This will capitalise the replacement value, which is very handy for files where you need a lowercase and capitalized version of the same string, like class or module definitions.
|
143
143
|
Note! The value of :project_name is hard coded to be the same as the projects name, no matter the value entered in this config file. This helps with capistrano.
|
144
144
|
e.g.
|
145
145
|
:replace_strings:
|
data/lib/jumpstart/filetools.rb
CHANGED
@@ -121,11 +121,13 @@ module JumpStart::FileTools
|
|
121
121
|
# Hello there NAME from COUNTRY
|
122
122
|
# Will also replace strings present in the target_file path. so if the method call looked like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
|
123
123
|
# and target_file was: /Users/name/Sites/country the strings matching NAME and COUNTRY inside the file would be swapped out and then a new file at the path: /Users/Ian/Sites/England would be created and populated with the contents. The file at the previous path would be deleted.
|
124
|
+
# Finally if you specify a symbol and append _CLASS in the template, that instance will be replace with a capitalized version of the string.
|
124
125
|
def replace_strings(target_file, args)
|
125
126
|
if File.file?(target_file)
|
126
127
|
txt = IO.read(target_file)
|
127
128
|
new_file = target_file.dup
|
128
129
|
args.each do |x, y|
|
130
|
+
txt.gsub!(/#{x.to_s.upcase}_CLASS/, y.capitalize)
|
129
131
|
txt.gsub!(/#{x.to_s.upcase}/, y)
|
130
132
|
new_file.gsub!(/#{x.to_s.downcase}/, y)
|
131
133
|
end
|
@@ -49,6 +49,7 @@
|
|
49
49
|
# List files that you would like to perform string substitution on. This can be useful for populating files such as a capistrano deploy.rb file.
|
50
50
|
# Paths use the newly created project folder as root.
|
51
51
|
# Any key:value pair can be used for substitution, simply add the key name in CAPS to the template file then specify the symbol key and value as in the example.
|
52
|
+
# As of version 0.5 it is now possible to append _CLASS to the capitalized key name in your templates. This will capitalise the replacement value, which is very handy for files where you need a lowercase and capitalized version of the same string, like class or module definitions.
|
52
53
|
# Note! The value of :project_name is hard coded to be the same as the projects name, no matter the value entered in this config file. This helps with capistrano.
|
53
54
|
# e.g.
|
54
55
|
# :replace_strings:
|
@@ -233,7 +233,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
233
233
|
end
|
234
234
|
|
235
235
|
context "Testing JumpStart::FileUtils#replace_strings class method.\n" do
|
236
|
-
|
236
|
+
|
237
237
|
setup do
|
238
238
|
@target_file_1 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb"
|
239
239
|
@target_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_app_name.rb"
|
@@ -249,7 +249,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
teardown do
|
254
254
|
FileUtils.remove_files(@target_files)
|
255
255
|
if File.exists?(@new_file_2)
|
@@ -266,7 +266,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
266
266
|
assert_equal "set :application, 'test_app'\n", file[0]
|
267
267
|
assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
should "replace strings with replace_strings method if the path does not contain the replacement strings and more than one replacement string is provided" do
|
271
271
|
FileUtils.replace_strings(@target_file_1, :app_name => 'test_app', :REMOTE_SERVER => 'remote_box')
|
272
272
|
file = IO.readlines(@target_file_1)
|
@@ -274,7 +274,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
274
274
|
assert_equal "set :domain, 'remote_box'\n", file[1]
|
275
275
|
assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
should "replace strings inside the target path if the target is a file and there is more than one argument." do
|
279
279
|
FileUtils.replace_strings(@target_file_2, :app_name => 'bungle', :remote_server => 'boxy')
|
280
280
|
file = IO.readlines(@new_file_2)
|
@@ -284,7 +284,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
284
284
|
assert File.exists?(@new_file_2)
|
285
285
|
assert !File.exists?(@target_file_2)
|
286
286
|
end
|
287
|
-
|
287
|
+
|
288
288
|
should "replace strings inside the target path if the target is a file and there is more than one argument and the replacement string is found in the directory structure." do
|
289
289
|
FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
|
290
290
|
file = IO.readlines(@new_file_3)
|
@@ -294,7 +294,19 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
294
294
|
assert File.exists?(@new_file_3)
|
295
295
|
assert !File.exists?(@target_file_3)
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
|
+
should "replace strings that have _CLASS appended to them with a capitalised version of the replacement string." do
|
299
|
+
FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
|
300
|
+
file = IO.readlines(@new_file_3)
|
301
|
+
assert_equal "set :application, 'bungle'\n", file[0]
|
302
|
+
assert_equal "set :domain, 'boxy'\n", file[1]
|
303
|
+
assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf bungle\"\n", file[44]
|
304
|
+
assert_equal "# This is a test string Bungle\n", file[63]
|
305
|
+
assert_equal "# This is a test string Boxy\n", file[64]
|
306
|
+
assert File.exists?(@new_file_3)
|
307
|
+
assert !File.exists?(@target_file_3)
|
308
|
+
end
|
309
|
+
|
298
310
|
end
|
299
311
|
|
300
312
|
context "Testing JumpStart::FileUtils#check_source_type class method.\n" do
|