Commit 17a150f2 by jyurek

Fixed defaults for path, and a bug related to format-finding when no format was supplied.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@397 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 0544f0f9
...@@ -14,7 +14,7 @@ module Paperclip ...@@ -14,7 +14,7 @@ module Paperclip
@url = options[:url] || @url = options[:url] ||
"/:attachment/:id/:style/:basename.:extension" "/:attachment/:id/:style/:basename.:extension"
@path = options[:path] || @path = options[:path] ||
":attachment/:id/:style/:basename.:extension" ":rails_root/public/:attachment/:id/:style/:basename.:extension"
@styles = options[:styles] || {} @styles = options[:styles] || {}
@default_url = options[:default_url] || "/:attachment/:style/missing.png" @default_url = options[:default_url] || "/:attachment/:style/missing.png"
@validations = options[:validations] || [] @validations = options[:validations] || []
...@@ -25,6 +25,8 @@ module Paperclip ...@@ -25,6 +25,8 @@ module Paperclip
@validation_errors = nil @validation_errors = nil
@dirty = false @dirty = false
normalize_style_definition
@file = File.new(path) if original_filename && File.exists?(path) @file = File.new(path) if original_filename && File.exists?(path)
end end
...@@ -116,16 +118,16 @@ module Paperclip ...@@ -116,16 +118,16 @@ module Paperclip
def self.interpolations def self.interpolations
@interpolations ||= { @interpolations ||= {
:rails_root => lambda{|attachment,style| RAILS_ROOT }, :rails_root => lambda{|attachment,style| RAILS_ROOT },
:class => lambda{|attachment,style| attachment.instance.class.to_s }, :class => lambda{|attachment,style| attachment.instance.class.to_s.pluralize },
:basename => lambda do |attachment,style| :basename => lambda do |attachment,style|
attachment.original_filename.gsub(/\.(.*?)$/, "") attachment.original_filename.gsub(/\.(.*?)$/, "")
end, end,
:extension => lambda do |attachment,style| :extension => lambda do |attachment,style|
((style = attachment.styles[style]) && style.last) || ((style = attachment.styles[style]) && style.last) ||
File.extname(attachment.original_filename).gsub(/^\./, "") File.extname(attachment.original_filename).gsub(/^\.+/, "")
end, end,
:id => lambda{|attachment,style| attachment.instance.id }, :id => lambda{|attachment,style| attachment.instance.id },
:attachment => lambda{|attachment,style| attachment.name }, :attachment => lambda{|attachment,style| attachment.name.pluralize },
:style => lambda{|attachment,style| style || attachment.default_style }, :style => lambda{|attachment,style| style || attachment.default_style },
} }
end end
...@@ -145,12 +147,19 @@ module Paperclip ...@@ -145,12 +147,19 @@ module Paperclip
end end
end end
def normalize_style_definition
@styles.each do |name, args|
dimensions, format = [args, nil].flatten[0..1]
format = nil if format == ""
@styles[name] = [dimensions, format]
end
end
def post_process #:nodoc: def post_process #:nodoc:
return nil if @file.nil? return nil if @file.nil?
@styles.each do |name, args| @styles.each do |name, args|
begin begin
dimensions, format = [args, nil].flatten[0..1] dimensions, format = args
@styles[name] = [dimensions, format]
@processed_files[name] = Thumbnail.make(self.file, @processed_files[name] = Thumbnail.make(self.file,
dimensions, dimensions,
format, format,
......
...@@ -17,7 +17,7 @@ module Paperclip ...@@ -17,7 +17,7 @@ module Paperclip
# File or path. # File or path.
def self.from_file file def self.from_file file
file = file.path if file.respond_to? "path" file = file.path if file.respond_to? "path"
parse(`#{Paperclip.path_for_command('identify')} "#{file}" 2>/dev/null`) || parse(`#{Paperclip.path_for_command('identify')} "#{file}"`) ||
raise(Errno::ENOENT, file) raise(Errno::ENOENT, file)
end end
......
...@@ -15,6 +15,22 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip') ...@@ -15,6 +15,22 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
require File.join(ROOT, 'lib', 'paperclip.rb') require File.join(ROOT, 'lib', 'paperclip.rb')
class String
unless methods.include? :pluralize
def pluralize
"#{self}s"
end
end
end
class Symbol
unless methods.include? :pluralize
def pluralize
"#{self}s"
end
end
end
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment