lib/hx/backend/rawfiles.rb in hx-0.17.0 vs lib/hx/backend/rawfiles.rb in hx-0.18.0
- old
+ new
@@ -31,11 +31,13 @@
include Hx::Filter
def initialize(input, options)
@entry_dir = Hx.get_pathname(options, :entry_dir)
@postedit_cmd = options[:postedit_cmd]
+ @postdelete_cmd = options[:postdelete_cmd]
@postedit_cmd = @postedit_cmd.split(/\s+/) if @postedit_cmd
+ @postdelete_cmd = @postdelete_cmd.split(/\s+/) if @postdelete_cmd
end
def path_to_pathname(path) ; @entry_dir + path ; end
private :path_to_pathname
@@ -51,11 +53,19 @@
rescue Errno::ENOENT
raise NoSuchEntryError, path unless prototype
text = prototype['content'].to_s
end
text = yield text
- Hx.write_file(pathname, text)
- system *(@postedit_cmd + [pathname]) if @postedit_cmd
+ if text
+ Hx.write_file(pathname, text)
+ system *(@postedit_cmd + [pathname]) if @postedit_cmd
+ else
+ begin
+ File.unlink(pathname)
+ system *(@postdelete_cmd + [pathname]) if @postdelete_cmd
+ rescue Errno::ENOENT
+ end
+ end
self
end
def each_entry_path(selector)
Pathname.glob(@entry_dir + '**/*') do |pathname|