Skip to content

Instantly share code, notes, and snippets.

@autumn-hoerr
Forked from jasmarc/create_webpages.command
Created August 3, 2012 14:15
Show Gist options
  • Save autumn-hoerr/3248037 to your computer and use it in GitHub Desktop.
Save autumn-hoerr/3248037 to your computer and use it in GitHub Desktop.
Creates a photo gallery from a folder full of images, somewhat per this request: http://www.idiotking.org/archives/2012/05/exercise-in-futility/
# save as "Rakefile" in desired directory
# cd to directory and type "rake"
task :default => 'make_html'
desc "Turns a directory of images into linked HTML"
task :make_html do
extensions = "png,PNG,jpg,JPG,gif"
working_dir =File.dirname(__FILE__)
pictures = Dir.glob("#{working_dir}/*.{#{extensions}}")
puts "converting pictures in #{working_dir}"
pictures.each_with_index do |img_name, index|
current_file = "index#{index == 0 ? nil : index}.html"
next_index = (index + 1) % pictures.size
next_file = "index#{next_index == 0 ? nil : next_index}.html"
File.open("#{working_dir}/#{current_file}", "w").write <<-EOF
<html>
<a href="#{next_file}"><img src="#{img_name}" /></a>
</html>
EOF
end
sh "cd '#{working_dir}'; open index.html"
end
desc "Upload all html files and images into a directory via FTP"
task :upload do
require 'net/ftp'
# ----------------------------------
#
# EDIT THESE VARIABLES
username = "username"
password = "password"
server = "ftp.ftpserver.com"
remote_dir = ENV["TO_DIR"] || "remotedir/www/myfolder"
# leave everything else alone
#
# ----------------------------------
working_dir = File.dirname(__FILE__)
extensions = "png,PNG,jpg,JPG,gif,HTML,html"
files = Dir.glob("#{working_dir}/*.{#{extensions}}")
puts "connecting to #{server} as #{username}"
Net::FTP.open(server, username, password) do |ftp|
ftp.chdir remote_dir
files.each do |file|
puts "uploading #{file}"
ftp.put file
end
ftp.ls.each do |remote_file|
puts "remote file: #{remote_file}"
end
ftp.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment