Browse code

Added prompt for overwriting posts and pages when a new_post and new_page tasks are run and the file already exists. Fixes #130

Brandon Mathis authored on 03/09/2011 at 13:06:36
Showing 1 changed files
... ...
@@ -92,6 +92,11 @@ task :new_post, :title do |t, args|
92 92
   args.with_defaults(:title => 'new-post')
93 93
   title = args.title
94 94
   filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
95
+  if File.exist?(filename)
96
+    puts "### #{filename} Already exists. Overwrite? y/n:"
97
+    response = $stdin.gets.chomp.downcase
98
+    next unless response == 'y'
99
+  end
95 100
   puts "Creating new post: #{filename}"
96 101
   open(filename, 'w') do |post|
97 102
     system "mkdir -p #{source_dir}/#{posts_dir}/";
... ...
@@ -119,6 +124,11 @@ task :new_page, :filename do |t, args|
119 119
     filename = "#{name}.#{extension}"
120 120
     mkdir_p page_dir
121 121
     file = page_dir + filename
122
+    if File.exist?(file)
123
+      puts "### #{file} Already exists. Overwrite? y/n:"
124
+      response = $stdin.gets.chomp.downcase
125
+      next unless response == 'y'
126
+    end
122 127
     puts "Creating new page: #{file}"
123 128
     open(file, 'w') do |page|
124 129
       page.puts "---"