lib/s3-static-site.rb in s3-static-site-0.2.0 vs lib/s3-static-site.rb in s3-static-site-0.3.0

- old
+ new

@@ -1,18 +1,20 @@ require 'haml' require 'aws/s3' +require 'mime/types' unless Capistrano::Configuration.respond_to?(:instance) abort "s3-static-site requires Capistrano >= 2." end Capistrano::Configuration.instance(true).load do def _cset(name, *args, &block) set(name, *args, &block) if !exists?(name) end - _cset :deployment_path, `pwd`.gsub("\n", "") + "/public" + _cset :deployment_path, Dir.pwd.gsub("\n", "") + "/public" + _cset :deploy_to, "" def base_file_path(file) file.gsub(deployment_path, "") end @@ -62,11 +64,24 @@ engine.render else open(file) end - _s3.buckets[bucket].objects[path].write(contents, :acl => :public_read) + types = MIME::Types.type_for(File.basename(file)) + if types.empty? + options = { + :acl => :public_read + } + else + options = { + :acl => :public_read, + :content_type => types[0] + } + end + + target = deploy_to.empty? ? path : File.join(deploy_to, path) + _s3.buckets[bucket].objects[target].write(contents, options) end end end end @@ -74,6 +89,6 @@ s3.upload_files end task :restart do; end end -end \ No newline at end of file +end