parameterize folder names
This commit is contained in:
parent
1131c656d5
commit
d9607ea0c8
|
@ -24,6 +24,7 @@ class Album < ActiveRecord::Base
|
||||||
|
|
||||||
def ensure_path
|
def ensure_path
|
||||||
self.path = self.title unless self.path
|
self.path = self.title unless self.path
|
||||||
|
self.path.parameterize
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_title
|
def set_title
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Photo < ActiveRecord::Base
|
||||||
def swf_uploaded_data=(data)
|
def swf_uploaded_data=(data)
|
||||||
data.content_type = MIME::Types.type_for(data.original_filename)
|
data.content_type = MIME::Types.type_for(data.original_filename)
|
||||||
self.title = data.original_filename
|
self.title = data.original_filename
|
||||||
self.path = self.album.path + "/" + data.original_filename
|
self.path = self.album.path + "/" + data.original_filename.parameterize
|
||||||
File.open(APP_CONFIG[:photos_path] + self.path, 'wb') { |f| f.write(data.read) }
|
File.open(APP_CONFIG[:photos_path] + self.path, 'wb') { |f| f.write(data.read) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")[RAILS_ENV].symbolize_keys
|
#APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")[RAILS_ENV].symbolize_keys
|
||||||
|
APP_CONFIG = YAML.load(ERB.new(File.read("#{RAILS_ROOT}/config/settings.yml")).result)[RAILS_ENV].symbolize_keys
|
||||||
|
|
17
lib/scan.rb
17
lib/scan.rb
|
@ -1,10 +1,11 @@
|
||||||
module ScanFiles
|
module ScanFiles
|
||||||
require "find"
|
require "find"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
supported_files = ["jpeg", "jpg", "gif", "png"]
|
supported_files = ["jpeg", "jpg", "gif", "png"]
|
||||||
|
|
||||||
def self.FullScan
|
def self.FullScan
|
||||||
|
puts "Scanning " + APP_CONFIG[:photos_path]
|
||||||
prevalbum = ""
|
prevalbum = ""
|
||||||
dirs = Array.new
|
dirs = Array.new
|
||||||
Find.find( APP_CONFIG[:photos_path] ) { |path|
|
Find.find( APP_CONFIG[:photos_path] ) { |path|
|
||||||
|
@ -14,6 +15,20 @@ module ScanFiles
|
||||||
if File.file?(path) && [".jpeg", ".jpg", ".gif", ".png"].include?( File.extname(path) )
|
if File.file?(path) && [".jpeg", ".jpg", ".gif", ".png"].include?( File.extname(path) )
|
||||||
relpath = File.dirname( path ).sub(APP_CONFIG[:photos_path], '')
|
relpath = File.dirname( path ).sub(APP_CONFIG[:photos_path], '')
|
||||||
relfile = path.sub(APP_CONFIG[:photos_path], '')
|
relfile = path.sub(APP_CONFIG[:photos_path], '')
|
||||||
|
puts relpath
|
||||||
|
relpathdirs = relpath.split("/")
|
||||||
|
relpathparam = ""
|
||||||
|
relpathdirs.each{|d|
|
||||||
|
relpathparam += d.parameterize + "/"
|
||||||
|
}
|
||||||
|
relpathparam = relpathparam.slice(0..relpathparam.length-2)
|
||||||
|
if relpath != relpathparam
|
||||||
|
puts APP_CONFIG[:photos_path] + relpath + " will now be moved to " + APP_CONFIG[:photos_path] + relpathparam
|
||||||
|
FileUtils.mv APP_CONFIG[:photos_path] + relpath, APP_CONFIG[:photos_path] + relpathparam
|
||||||
|
puts "reload!"
|
||||||
|
self.FullScan
|
||||||
|
return
|
||||||
|
end
|
||||||
album = Album.find_by_path( relpath )
|
album = Album.find_by_path( relpath )
|
||||||
if prevalbum != relpath
|
if prevalbum != relpath
|
||||||
puts relpath
|
puts relpath
|
||||||
|
|
Loading…
Reference in a new issue