Permalink
Browse files

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
  • Loading branch information...
1 parent 0544f0f commit 17a150f26348763a717aa27b42767d976b779780 jyurek committed Mar 19, 2008
Showing with 32 additions and 7 deletions.
  1. +15 −6 lib/paperclip/attachment.rb
  2. +1 −1 lib/paperclip/geometry.rb
  3. +16 −0 test/helper.rb
@@ -14,7 +14,7 @@ def initialize name, instance, options
@url = options[:url] ||
"/:attachment/:id/:style/:basename.:extension"
@path = options[:path] ||
- ":attachment/:id/:style/:basename.:extension"
+ ":rails_root/public/:attachment/:id/:style/:basename.:extension"
@styles = options[:styles] || {}
@default_url = options[:default_url] || "/:attachment/:style/missing.png"
@validations = options[:validations] || []
@@ -25,6 +25,8 @@ def initialize name, instance, options
@validation_errors = nil
@dirty = false
+ normalize_style_definition
+
@file = File.new(path) if original_filename && File.exists?(path)
end
@@ -116,16 +118,16 @@ def original_filename
def self.interpolations
@interpolations ||= {
: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|
attachment.original_filename.gsub(/\.(.*?)$/, "")
end,
:extension => lambda do |attachment,style|
((style = attachment.styles[style]) && style.last) ||
- File.extname(attachment.original_filename).gsub(/^\./, "")
+ File.extname(attachment.original_filename).gsub(/^\.+/, "")
end,
: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 },
}
end
@@ -145,12 +147,19 @@ def validate #:nodoc:
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:
return nil if @file.nil?
@styles.each do |name, args|
begin
- dimensions, format = [args, nil].flatten[0..1]
- @styles[name] = [dimensions, format]
+ dimensions, format = args
@processed_files[name] = Thumbnail.make(self.file,
dimensions,
format,
@@ -17,7 +17,7 @@ def initialize width = nil, height = nil, modifier = nil
# File or path.
def self.from_file file
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)
end
View
@@ -15,6 +15,22 @@
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")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")

0 comments on commit 17a150f

Please sign in to comment.