Skip to content

Instantly share code, notes, and snippets.

@gterrill
Created April 27, 2010 23:07
Show Gist options
  • Save gterrill/381473 to your computer and use it in GitHub Desktop.
Save gterrill/381473 to your computer and use it in GitHub Desktop.
def zip(theme, location)
begin
FileUtils.mkdir_p(File.dirname(location))
FileUtils.rm(location) if File.exists?(location)
if RUBY_PLATFORM =~ /darwin/
Dir.chdir(THEMES) do
system("zip -r \"#{location}\" #{theme}/ -x \"*.svn*\" -x \"*.git*\"")
end
else
Zip::ZipFile.open(location, Zip::ZipFile::CREATE) do |zip|
zip.mkdir(theme)
zip.mkdir(theme + '/assets')
zip.mkdir(theme + '/layout')
zip.mkdir(theme + '/templates')
zip.mkdir(theme + '/config')
zip.mkdir(theme + '/snippets')
base = THEMES + "/"
files = []
files += Dir["#{base}#{theme}/assets/*"]
files += Dir["#{base}#{theme}/templates/*.liquid"]
files += Dir["#{base}#{theme}/layout/theme.liquid"]
files += Dir["#{base}#{theme}/README"]
files += Dir["#{base}#{theme}/config/*"]
files += Dir["#{base}#{theme}/snippets/*"]
files.each do |file|
position = file[base.size..-1]
zip.add(position, file)
end
end
end
File.open(location, "rb") { |fp| yield fp }
rescue
FileUtils.rm(location) if File.exists?(location)
raise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment