Browse code

Updated new_post and new_page taks to use new ask method for dialogs

Brandon Mathis authored on 04/09/2011 at 13:47:36
Showing 1 changed files
... ...
@@ -96,9 +96,7 @@ task :new_post, :title do |t, args|
96 96
   title = args.title
97 97
   filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
98 98
   if File.exist?(filename)
99
-    puts "### #{filename} Already exists. Overwrite? y/n:"
100
-    response = $stdin.gets.chomp.downcase
101
-    next unless response == 'y'
99
+    abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
102 100
   end
103 101
   puts "Creating new post: #{filename}"
104 102
   open(filename, 'w') do |post|
... ...
@@ -128,9 +126,7 @@ task :new_page, :filename do |t, args|
128 128
     mkdir_p page_dir
129 129
     file = page_dir + filename
130 130
     if File.exist?(file)
131
-      puts "### #{file} Already exists. Overwrite? y/n:"
132
-      response = $stdin.gets.chomp.downcase
133
-      next unless response == 'y'
131
+      abort("rake aborted!") if ask("#{file} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
134 132
     end
135 133
     puts "Creating new page: #{file}"
136 134
     open(file, 'w') do |page|