jumpstart 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,10 +57,6 @@ The last line of the source file (ignoring whitespace) will be removed, and then
57
57
  Line templates insert their contents into a file at a specified line, pushing existing contents down the page. This is very handy. Say for example that you want to insert some extra configuration information into your new rails projects config/environments/development.rb at line 18. In your jumpstart template you would create a file called config/environments/_18._development.rb
58
58
  If the file you specify doesn't have as many lines as you said it would, whitespace will be added until the specified number is reached.
59
59
 
60
- == The JumpStart Command
61
-
62
- == The JumpStart Menu
63
-
64
60
  == Task Execution Order
65
61
  Jumpstart tasks are executed in the order that the YAML options below are displayed.
66
62
 
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
- :jumpstart_version_minor: 2
4
- :jumpstart_version_patch: 3
3
+ :jumpstart_version_minor: 3
4
+ :jumpstart_version_patch: 0
@@ -200,8 +200,8 @@ module JumpStart
200
200
  puts "\n\n******************************************************************************************************************************************\n\n"
201
201
  puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
202
202
  puts " Type a number for the template that you want.\n\n"
203
- count = 0
204
203
  unless JumpStart.existing_templates.empty?
204
+ count = 0
205
205
  JumpStart.existing_templates.each do |t|
206
206
  count += 1
207
207
  puts " #{count.to_s.yellow} #{t.green}"
@@ -240,19 +240,22 @@ module JumpStart
240
240
  puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
241
241
  puts " Existing templates:\n"
242
242
  unless JumpStart.existing_templates.nil?
243
+ count = 0
243
244
  JumpStart.existing_templates.each do |x|
244
- puts " #{x.green}\n"
245
+ count += 1
246
+ puts " #{count.to_s.yellow} #{x.green}\n"
245
247
  end
246
248
  end
247
249
  puts "\n b".yellow + " Back to main menu."
248
- puts "\n x".yellow + " Exit jumpstart\n\n"
250
+ puts "\n x".yellow + " Exit jumpstart\n"
249
251
  new_template_options
250
252
  end
251
253
 
254
+ # TODO Write additional tests for new_template_options to test duplication feature.
252
255
  # Captures user input for "create a new jumpstart template" menu and calls the appropriate action.
253
256
  # If the template name provided meets the methods requirements then a directory of that name containing a jumpstart_config dir and matching yaml file are created.
254
257
  def new_template_options
255
- puts "\n Enter a unique name for the new template.\n".yellow
258
+ puts "\n Enter a unique name to create a new template, or enter an existing templates name (or number) to duplicate it.".yellow
256
259
  input = gets.chomp.strip
257
260
  case
258
261
  when input == "b"
@@ -260,22 +263,73 @@ module JumpStart
260
263
  when input == "x"
261
264
  exit_normal
262
265
  when JumpStart.existing_templates.include?(input)
263
- puts " A template of the name ".red + input.red_bold + " already exists.".red
264
- new_template_options
266
+ puts "\n You have chosen to duplicate the " + input.green + " template." + "\n Please enter a name for the duplicate.".yellow
267
+ duplicate_template(input)
268
+ when input.to_i != 0 && input.to_i <= JumpStart.existing_templates.count
269
+ puts "\n You have chosen to duplicate the " + JumpStart.existing_templates[(input.to_i - 1)].green + " template." + "\n Please enter a name for the duplicate.".yellow
270
+ duplicate_template(JumpStart.existing_templates[(input.to_i - 1)])
265
271
  when input.length < 3
266
- puts " The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
272
+ puts "\n The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
267
273
  new_template_options
268
- when input.match(/^\W/)
269
- puts " The template name ".red + input.red_bold + " begins with an invalid character. Please enter a name that begins with a letter or a number.".red
274
+ when input.match(/^\W|\W$/)
275
+ puts "\n The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
270
276
  new_template_options
271
277
  else
272
278
  FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
273
279
  FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
274
- puts " The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
280
+ puts "\n The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
275
281
  jumpstart_menu
276
282
  end
277
283
  end
278
284
 
285
+ # TODO Write tests for duplicate_template
286
+ # TODO Look at refactoring this.
287
+ def duplicate_template(template)
288
+ input = gets.chomp.strip
289
+ case
290
+ when input == "b"
291
+ jumpstart_menu
292
+ when input == "x"
293
+ exit_normal
294
+ when JumpStart.existing_templates.include?(input)
295
+ puts " The template ".red + input.red_bold + " already exists. Please enter a unique name for the duplicate.".red
296
+ duplicate_template(template)
297
+ when input.length < 3
298
+ puts " The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
299
+ duplicate_template(template)
300
+ when input.match(/^\W|\W$/)
301
+ puts " The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
302
+ duplicate_template(template)
303
+ else
304
+ FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
305
+ FileUtils.touch(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
306
+ dirs, files = [], []
307
+ Find.find(FileUtils.join_paths(JumpStart.templates_path, template)) do |x|
308
+ case
309
+ when File.file?(x) && !x.match(/\/jumpstart_config\/*/)
310
+ files << x.sub(FileUtils.join_paths(JumpStart.templates_path, template), '')
311
+ when File.file?(x) && x.match(/\/jumpstart_config\/*/)
312
+ FileUtils.copy_file(x, FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml") )
313
+ when File.directory?(x)
314
+ dirs << x.sub(FileUtils.join_paths(JumpStart.templates_path, template), '')
315
+ end
316
+ end
317
+ dirs.each do |x|
318
+ unless x.length < 1
319
+ FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, x))
320
+ end
321
+ end
322
+ files.each do |x|
323
+ unless x.length < 0
324
+ FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, template, x), FileUtils.join_paths(JumpStart.templates_path, input, x))
325
+ end
326
+ end
327
+ puts "\n Duplication complete!".green_bold
328
+ puts " Template " + template.green + " has been duplicated to " + input.green
329
+ jumpstart_menu
330
+ end
331
+ end
332
+
279
333
  # Displays output for the "jumpstart default template options menu"
280
334
  def set_default_template_menu
281
335
  puts "\n\n******************************************************************************************************************************************\n\n"
@@ -493,7 +493,7 @@ class TestJumpstartBase < Test::Unit::TestCase
493
493
  JumpStart.expects(:existing_templates).once
494
494
  @test_project.expects(:new_template_options).once
495
495
  @test_project.instance_eval {new_template_menu}
496
- assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m CREATE A NEW JUMPSTART TEMPLATE\n\e[0m\n Existing templates:\n\e[1m\e[33m\n b\e[0m Back to main menu.\n\e[1m\e[33m\n x\e[0m Exit jumpstart\n\n", @test_project.output.string
496
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m CREATE A NEW JUMPSTART TEMPLATE\n\e[0m\n Existing templates:\n\e[1m\e[33m\n b\e[0m Back to main menu.\n\e[1m\e[33m\n x\e[0m Exit jumpstart\n", @test_project.output.string
497
497
  end
498
498
 
499
499
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
7
  - 3
9
- version: 0.2.3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)