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
@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 @@ module Paperclip
@validation_errors = nil
@dirty = false
normalize_style_definition
@file = File.new(path) if original_filename && File.exists?(path)
end
......@@ -116,16 +118,16 @@ module Paperclip
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 @@ module Paperclip
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 @@ module Paperclip
# 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
......
......@@ -15,6 +15,22 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
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")
......
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