Skip to content

Instantly share code, notes, and snippets.

@auxesis
Created September 18, 2009 12:37
Show Gist options
  • Save auxesis/189033 to your computer and use it in GitHub Desktop.
Save auxesis/189033 to your computer and use it in GitHub Desktop.
desc "build pngs from svgs"
task :build do
Dir.glob("sources/*.svg").each do |file|
if modified?(file)
basename = File.basename(file, '.svg')
slide = "slides/#{basename}.png"
system("inkscape -e #{slide} -f #{file}")
end
end
end
def modified?(filename)
index_filename = File.join(File.dirname(__FILE__), "cache", "index")
# read or initialise index
if File.exists?(index_filename)
@index = File.open(index_filename, 'r') { |f| Marshal.load(f) }
else
@index = {}
end
# check if modified
if @index[filename]
modified = File.mtime(filename) > @index[filename][:mtime]
else
modified = true
end
# update index
@index[filename] = {:mtime => File.mtime(filename)}
File.open(index_filename, 'w') { |f| Marshal.dump(@index, f) }
return modified
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment