Module: Burp::Util
- Defined in:
- app/lib/burp/util.rb,
app/lib/burp/util/upload_handler.rb
Defined Under Namespace
Classes: UploadHandler
Constant Summary collapse
- SIZES =
{:small => [200,300],:medium => [600,900], :large => [1000,1500]}
Class Method Summary collapse
- .commit(message = "auto commit", options = {}) ⇒ Object
- .create_smaller_images(file_path) ⇒ Object
- .remove_all_versions_of_image(file_path) ⇒ Object
Class Method Details
.commit(message = "auto commit", options = {}) ⇒ Object
10 11 12 13 14 |
# File 'app/lib/burp/util.rb', line 10 def self.commit( = "auto commit", = {}) [:path] ||= Burp.content_directory raise "missing git repo in burp cms directory" if `cd #{[:path]}; git st 2>&1`.match(/Not a git repository/) `cd #{[:path]}; git add .; git commit -a -m "Burp: #{}"` end |
.create_smaller_images(file_path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/lib/burp/util.rb', line 23 def self.create_smaller_images(file_path) image = Magick::ImageList.new(file_path).first image.auto_orient! SIZES.each_pair do |key,value| FileUtils.mkdir_p("#{upload_directory_path}#{key.to_s}") target_path = "#{upload_directory_path}#{key.to_s}/#{File.basename(file_path)}" if value[0] < image.columns # We only downscale image.resize_to_fit(value[0],value[1]).write(target_path) { self.quality = 75 } FileUtils.chmod(0644, target_path) else File.unlink(target_path) if File.exist?(target_path) File.symlink("../#{File.basename(file_path)}",target_path) end end image.destroy! end |
.remove_all_versions_of_image(file_path) ⇒ Object
16 17 18 19 20 21 |
# File 'app/lib/burp/util.rb', line 16 def self.remove_all_versions_of_image(file_path) SIZES.each_pair do |key,value| target_path = "#{upload_directory_path}#{key.to_s}/#{File.basename(file_path)}" File.unlink(target_path) if File.exist?(target_path) end end |