lib/org-converge/babel.rb in org-converge-0.0.1 vs lib/org-converge/babel.rb in org-converge-0.0.2
- old
+ new
@@ -27,11 +27,13 @@
tangle_file
end
logger.info "BEGIN(#{tangle_file}): Tangling #{lines.count} lines at '#{file}'"
# TODO: should abort when the directory does not exists
+ # Org mode blocks have :mkdirp true
# TODO: should abort when the directory failed because of permissions
+ # TODO: should apply :tangle-mode for permissions
if not Dir.exists?(File.dirname(file))
logger.error "Could not tangle #{file} because directory does not exists!"
raise TangleError
end
@@ -50,10 +52,29 @@
raise TangleError
end
logger.info "END(#{file}): done."
end
- logger.info "Tangling succeeded!".green
+ logger.info "Tangling succeeded!"
+ end
+
+ def tangle_runnable_blocks!(run_dir='run')
+ FileUtils.mkdir_p(run_dir)
+
+ logger.info "Tangling #{ob.scripts.count} scripts within directory: #{run_dir}..."
+
+ ob.scripts.each_pair do |script_key, script|
+ file = script_key.to_s
+ if File.exists?(file)
+ logger.warn "File already exists at #{file}, it will be overwritten"
+ end
+
+ File.open(File.join(run_dir, file), 'w') do |f|
+ script[:lines].each_line do |line|
+ f.puts line
+ end
+ end
+ end
end
class TangleError < Exception; end
end
end