carrierwave 0.11.2 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +255 -125
  3. data/lib/carrierwave/compatibility/paperclip.rb +0 -2
  4. data/lib/carrierwave/error.rb +1 -0
  5. data/lib/carrierwave/locale/en.yml +7 -4
  6. data/lib/carrierwave/mount.rb +219 -176
  7. data/lib/carrierwave/mounter.rb +165 -0
  8. data/lib/carrierwave/orm/activerecord.rb +50 -21
  9. data/lib/carrierwave/processing/mini_magick.rb +86 -15
  10. data/lib/carrierwave/processing/rmagick.rb +63 -8
  11. data/lib/carrierwave/processing.rb +0 -1
  12. data/lib/carrierwave/sanitized_file.rb +51 -46
  13. data/lib/carrierwave/storage/abstract.rb +15 -2
  14. data/lib/carrierwave/storage/file.rb +69 -2
  15. data/lib/carrierwave/storage/fog.rb +152 -33
  16. data/lib/carrierwave/storage.rb +0 -9
  17. data/lib/carrierwave/test/matchers.rb +77 -12
  18. data/lib/carrierwave/uploader/cache.rb +41 -27
  19. data/lib/carrierwave/uploader/callbacks.rb +0 -2
  20. data/lib/carrierwave/uploader/configuration.rb +54 -9
  21. data/lib/carrierwave/uploader/content_type_whitelist.rb +1 -1
  22. data/lib/carrierwave/uploader/default_url.rb +3 -5
  23. data/lib/carrierwave/uploader/download.rb +66 -15
  24. data/lib/carrierwave/uploader/extension_blacklist.rb +14 -10
  25. data/lib/carrierwave/uploader/extension_whitelist.rb +13 -10
  26. data/lib/carrierwave/uploader/file_size.rb +43 -0
  27. data/lib/carrierwave/uploader/mountable.rb +7 -8
  28. data/lib/carrierwave/uploader/processing.rb +10 -10
  29. data/lib/carrierwave/uploader/proxy.rb +5 -7
  30. data/lib/carrierwave/uploader/remove.rb +0 -2
  31. data/lib/carrierwave/uploader/serialization.rb +1 -3
  32. data/lib/carrierwave/uploader/store.rb +14 -23
  33. data/lib/carrierwave/uploader/url.rb +3 -5
  34. data/lib/carrierwave/uploader/versions.rb +82 -82
  35. data/lib/carrierwave/uploader.rb +11 -2
  36. data/lib/carrierwave/utilities/uri.rb +5 -6
  37. data/lib/carrierwave/utilities.rb +0 -3
  38. data/lib/carrierwave/validations/active_model.rb +3 -5
  39. data/lib/carrierwave/version.rb +1 -1
  40. data/lib/carrierwave.rb +32 -10
  41. data/lib/generators/templates/uploader.rb +4 -8
  42. metadata +64 -79
  43. data/lib/carrierwave/locale/cs.yml +0 -11
  44. data/lib/carrierwave/locale/de.yml +0 -11
  45. data/lib/carrierwave/locale/el.yml +0 -11
  46. data/lib/carrierwave/locale/es.yml +0 -11
  47. data/lib/carrierwave/locale/fr.yml +0 -11
  48. data/lib/carrierwave/locale/ja.yml +0 -11
  49. data/lib/carrierwave/locale/nb.yml +0 -11
  50. data/lib/carrierwave/locale/nl.yml +0 -11
  51. data/lib/carrierwave/locale/pl.yml +0 -11
  52. data/lib/carrierwave/locale/pt-BR.yml +0 -11
  53. data/lib/carrierwave/locale/pt-PT.yml +0 -11
  54. data/lib/carrierwave/locale/ru.yml +0 -11
  55. data/lib/carrierwave/locale/sk.yml +0 -11
  56. data/lib/carrierwave/locale/tr.yml +0 -11
  57. data/lib/carrierwave/processing/mime_types.rb +0 -74
  58. data/lib/carrierwave/utilities/deprecation.rb +0 -18
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Proxy
@@ -19,7 +17,7 @@ module CarrierWave
19
17
  # [String] the path where the file is currently located.
20
18
  #
21
19
  def current_path
22
- file.path if file.respond_to?(:path)
20
+ file.try(:path)
23
21
  end
24
22
 
25
23
  alias_method :path, :current_path
@@ -32,7 +30,7 @@ module CarrierWave
32
30
  # [String] uniquely identifies a file
33
31
  #
34
32
  def identifier
35
- storage.identifier if storage.respond_to?(:identifier)
33
+ storage.try(:identifier)
36
34
  end
37
35
 
38
36
  ##
@@ -43,7 +41,7 @@ module CarrierWave
43
41
  # [String] contents of the file
44
42
  #
45
43
  def read
46
- file.read if file.respond_to?(:read)
44
+ file.try(:read)
47
45
  end
48
46
 
49
47
  ##
@@ -54,7 +52,7 @@ module CarrierWave
54
52
  # [Integer] size of the file
55
53
  #
56
54
  def size
57
- file.respond_to?(:size) ? file.size : 0
55
+ file.try(:size) || 0
58
56
  end
59
57
 
60
58
  ##
@@ -80,7 +78,7 @@ module CarrierWave
80
78
  # [String] content type of the file
81
79
  #
82
80
  def content_type
83
- file.respond_to?(:content_type) ? file.content_type : nil
81
+ file.try(:content_type)
84
82
  end
85
83
 
86
84
  end # Proxy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Remove
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require "json"
4
2
  require "active_support/core_ext/hash"
5
3
 
@@ -13,7 +11,7 @@ module CarrierWave
13
11
  end
14
12
 
15
13
  def as_json(options=nil)
16
- Hash[mounted_as || "uploader", serializable_hash]
14
+ serializable_hash
17
15
  end
18
16
 
19
17
  def to_json(options=nil)
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Store
@@ -9,6 +7,15 @@ module CarrierWave
9
7
  include CarrierWave::Uploader::Configuration
10
8
  include CarrierWave::Uploader::Cache
11
9
 
10
+ included do
11
+ prepend Module.new {
12
+ def initialize(*)
13
+ super
14
+ @file, @filename, @cache_id = nil
15
+ end
16
+ }
17
+ end
18
+
12
19
  ##
13
20
  # Override this in your Uploader to change the filename.
14
21
  #
@@ -54,35 +61,19 @@ module CarrierWave
54
61
  #
55
62
  def store!(new_file=nil)
56
63
  cache!(new_file) if new_file && ((@cache_id != parent_cache_id) || @cache_id.nil?)
57
- if @file and @cache_id
64
+ if !cache_only and @file and @cache_id
58
65
  with_callbacks(:store, new_file) do
59
66
  new_file = storage.store!(@file)
60
- @file.delete if (delete_tmp_file_after_storage && ! move_to_store)
61
- delete_cache_id
67
+ if delete_tmp_file_after_storage
68
+ @file.delete unless move_to_store
69
+ cache_storage.delete_dir!(cache_path(nil))
70
+ end
62
71
  @file = new_file
63
72
  @cache_id = nil
64
73
  end
65
74
  end
66
75
  end
67
76
 
68
- ##
69
- # Deletes a cache id (tmp dir in cache)
70
- #
71
- def delete_cache_id
72
- if @cache_id
73
- path = File.expand_path(File.join(cache_dir, @cache_id), CarrierWave.root)
74
- begin
75
- Dir.rmdir(path)
76
- rescue Errno::ENOENT
77
- # Ignore: path does not exist
78
- rescue Errno::ENOTDIR
79
- # Ignore: path is not a dir
80
- rescue Errno::ENOTEMPTY, Errno::EEXIST
81
- # Ignore: dir is not empty
82
- end
83
- end
84
- end
85
-
86
77
  ##
87
78
  # Retrieves the file from the storage.
88
79
  #
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Url
@@ -17,10 +15,10 @@ module CarrierWave
17
15
  # [String] the location where this file is accessible via a url
18
16
  #
19
17
  def url(options = {})
20
- if file.respond_to?(:url) and not file.url.blank?
21
- file.method(:url).arity == 0 ? file.url : file.url(options)
18
+ if file.respond_to?(:url) and not (tmp_url = file.url).blank?
19
+ file.method(:url).arity == 0 ? tmp_url : file.url(options)
22
20
  elsif file.respond_to?(:path)
23
- path = encode_path(file.path.gsub(File.expand_path(root), ''))
21
+ path = encode_path(file.path.sub(File.expand_path(root), ''))
24
22
 
25
23
  if host = asset_host
26
24
  if host.respond_to? :call
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Versions
@@ -8,12 +6,12 @@ module CarrierWave
8
6
  include CarrierWave::Uploader::Callbacks
9
7
 
10
8
  included do
11
- class_attribute :versions, :version_names, :instance_reader => false, :instance_writer => false
9
+ class_attribute :versions, :version_names, :version_options, :instance_reader => false, :instance_writer => false
12
10
 
13
11
  self.versions = {}
14
12
  self.version_names = []
15
13
 
16
- attr_accessor :parent_cache_id
14
+ attr_accessor :parent_cache_id, :parent_version
17
15
 
18
16
  after :cache, :assign_parent_cache_id
19
17
  after :cache, :cache_versions!
@@ -21,6 +19,13 @@ module CarrierWave
21
19
  after :remove, :remove_versions!
22
20
  after :retrieve_from_cache, :retrieve_versions_from_cache!
23
21
  after :retrieve_from_store, :retrieve_versions_from_store!
22
+
23
+ prepend Module.new {
24
+ def initialize(*)
25
+ super
26
+ @versions = nil
27
+ end
28
+ }
24
29
  end
25
30
 
26
31
  module ClassMethods
@@ -50,72 +55,74 @@ module CarrierWave
50
55
  #
51
56
  def version(name, options = {}, &block)
52
57
  name = name.to_sym
53
- build_version(name, options) unless versions[name]
58
+ build_version(name, options)
54
59
 
55
- versions[name][:uploader].class_eval(&block) if block
60
+ versions[name].class_eval(&block) if block
56
61
  versions[name]
57
62
  end
58
63
 
59
64
  def recursively_apply_block_to_versions(&block)
60
65
  versions.each do |name, version|
61
- version[:uploader].class_eval(&block)
62
- version[:uploader].recursively_apply_block_to_versions(&block)
66
+ version.class_eval(&block)
67
+ version.recursively_apply_block_to_versions(&block)
63
68
  end
64
69
  end
65
70
 
66
71
  private
67
72
 
68
73
  def build_version(name, options)
69
- uploader = Class.new(self)
70
- const_set("Uploader#{uploader.object_id}".gsub('-', '_'), uploader)
71
- uploader.version_names += [name]
72
- uploader.versions = {}
73
- uploader.processors = []
74
-
75
- uploader.class_eval <<-RUBY, __FILE__, __LINE__ + 1
76
- # Define the enable_processing method for versions so they get the
77
- # value from the parent class unless explicitly overwritten
78
- def self.enable_processing(value=nil)
79
- self.enable_processing = value if value
80
- if !@enable_processing.nil?
81
- @enable_processing
82
- else
83
- superclass.enable_processing
74
+ if !versions.has_key?(name)
75
+ uploader = Class.new(self)
76
+ const_set("Uploader#{uploader.object_id}".tr('-', '_'), uploader)
77
+ uploader.version_names += [name]
78
+ uploader.versions = {}
79
+ uploader.processors = []
80
+ uploader.version_options = options
81
+
82
+ uploader.class_eval <<-RUBY, __FILE__, __LINE__ + 1
83
+ # Define the enable_processing method for versions so they get the
84
+ # value from the parent class unless explicitly overwritten
85
+ def self.enable_processing(value=nil)
86
+ self.enable_processing = value if value
87
+ if defined?(@enable_processing) && !@enable_processing.nil?
88
+ @enable_processing
89
+ else
90
+ superclass.enable_processing
91
+ end
92
+ end
93
+
94
+ # Regardless of what is set in the parent uploader, do not enforce the
95
+ # move_to_cache config option on versions because it moves the original
96
+ # file to the version's target file.
97
+ #
98
+ # If you want to enforce this setting on versions, override this method
99
+ # in each version:
100
+ #
101
+ # version :thumb do
102
+ # def move_to_cache
103
+ # true
104
+ # end
105
+ # end
106
+ #
107
+ def move_to_cache
108
+ false
84
109
  end
85
- end
86
-
87
- # Regardless of what is set in the parent uploader, do not enforce the
88
- # move_to_cache config option on versions because it moves the original
89
- # file to the version's target file.
90
- #
91
- # If you want to enforce this setting on versions, override this method
92
- # in each version:
93
- #
94
- # version :thumb do
95
- # def move_to_cache
96
- # true
97
- # end
98
- # end
99
- #
100
- def move_to_cache
101
- false
102
- end
103
- RUBY
104
-
105
- class_eval <<-RUBY
106
- def #{name}
107
- versions[:#{name}]
108
- end
109
- RUBY
110
+ RUBY
111
+
112
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
113
+ def #{name}
114
+ versions[:#{name}]
115
+ end
116
+ RUBY
117
+ else
118
+ uploader = Class.new(versions[name])
119
+ const_set("Uploader#{uploader.object_id}".tr('-', '_'), uploader)
120
+ uploader.processors = []
121
+ uploader.version_options = uploader.version_options.merge(options)
122
+ end
110
123
 
111
124
  # Add the current version hash to class attribute :versions
112
- current_version = {
113
- name => {
114
- :uploader => uploader,
115
- :options => options
116
- }
117
- }
118
- self.versions = versions.merge(current_version)
125
+ self.versions = versions.merge(name => uploader)
119
126
  end
120
127
 
121
128
  end # ClassMethods
@@ -131,7 +138,8 @@ module CarrierWave
131
138
  return @versions if @versions
132
139
  @versions = {}
133
140
  self.class.versions.each do |name, version|
134
- @versions[name] = version[:uploader].new(model, mounted_as)
141
+ @versions[name] = version.new(model, mounted_as)
142
+ @versions[name].parent_version = self
135
143
  end
136
144
  @versions
137
145
  end
@@ -160,7 +168,7 @@ module CarrierWave
160
168
 
161
169
  return false unless self.class.versions.has_key?(name)
162
170
 
163
- condition = self.class.versions[name][:options][:if]
171
+ condition = self.class.versions[name].version_options[:if]
164
172
  if(condition)
165
173
  if(condition.respond_to?(:call))
166
174
  condition.call(self, :version => name, :file => file)
@@ -241,6 +249,18 @@ module CarrierWave
241
249
  end
242
250
  end
243
251
 
252
+ def dependent_versions
253
+ active_versions.reject do |name, v|
254
+ v.class.version_options[:from_version]
255
+ end.to_a + sibling_versions.select do |name, v|
256
+ v.class.version_options[:from_version] == self.class.version_names.last
257
+ end.to_a
258
+ end
259
+
260
+ def sibling_versions
261
+ parent_version.try(:versions) || []
262
+ end
263
+
244
264
  def full_filename(for_file)
245
265
  [version_name, super(for_file)].compact.join('_')
246
266
  end
@@ -250,29 +270,9 @@ module CarrierWave
250
270
  end
251
271
 
252
272
  def cache_versions!(new_file)
253
- # We might have processed the new_file argument after the callbacks were
254
- # initialized, so get the actual file based off of the current state of
255
- # our file
256
- processed_parent = SanitizedFile.new :tempfile => self.file,
257
- :filename => new_file.original_filename
258
-
259
- active_versions.each do |name, v|
260
- next if v.cached?
261
-
262
- v.send(:cache_id=, cache_id)
263
- # If option :from_version is present, create cache using cached file from
264
- # version indicated
265
- if self.class.versions[name][:options] && self.class.versions[name][:options][:from_version]
266
- # Maybe the reference version has not been cached yet
267
- unless versions[self.class.versions[name][:options][:from_version]].cached?
268
- versions[self.class.versions[name][:options][:from_version]].cache!(processed_parent)
269
- end
270
- processed_version = SanitizedFile.new :tempfile => versions[self.class.versions[name][:options][:from_version]],
271
- :filename => new_file.original_filename
272
- v.cache!(processed_version)
273
- else
274
- v.cache!(processed_parent)
275
- end
273
+ dependent_versions.each do |name, v|
274
+ v.send(:cache_id=, @cache_id)
275
+ v.cache!(new_file)
276
276
  end
277
277
  end
278
278
 
@@ -290,11 +290,11 @@ module CarrierWave
290
290
  end
291
291
 
292
292
  def retrieve_versions_from_cache!(cache_name)
293
- versions.each { |name, v| v.retrieve_from_cache!(cache_name) }
293
+ active_versions.each { |name, v| v.retrieve_from_cache!(cache_name) }
294
294
  end
295
295
 
296
296
  def retrieve_versions_from_store!(identifier)
297
- versions.each { |name, v| v.retrieve_from_store!(identifier) }
297
+ active_versions.each { |name, v| v.retrieve_from_store!(identifier) }
298
298
  end
299
299
 
300
300
  end # Versions
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require "carrierwave/uploader/configuration"
4
2
  require "carrierwave/uploader/callbacks"
5
3
  require "carrierwave/uploader/proxy"
@@ -13,6 +11,7 @@ require "carrierwave/uploader/extension_whitelist"
13
11
  require "carrierwave/uploader/extension_blacklist"
14
12
  require "carrierwave/uploader/content_type_whitelist"
15
13
  require "carrierwave/uploader/content_type_blacklist"
14
+ require "carrierwave/uploader/file_size"
16
15
  require "carrierwave/uploader/processing"
17
16
  require "carrierwave/uploader/versions"
18
17
  require "carrierwave/uploader/default_url"
@@ -44,6 +43,15 @@ module CarrierWave
44
43
  class Base
45
44
  attr_reader :file
46
45
 
46
+ ##
47
+ # Workaround for class_attribute malfunction when used with Module#prepend
48
+ #
49
+ if RUBY_VERSION < '2.1.0'
50
+ def self.singleton_class?
51
+ !ancestors.include? self
52
+ end
53
+ end
54
+
47
55
  include CarrierWave::Uploader::Configuration
48
56
  include CarrierWave::Uploader::Callbacks
49
57
  include CarrierWave::Uploader::Proxy
@@ -57,6 +65,7 @@ module CarrierWave
57
65
  include CarrierWave::Uploader::ExtensionBlacklist
58
66
  include CarrierWave::Uploader::ContentTypeWhitelist
59
67
  include CarrierWave::Uploader::ContentTypeBlacklist
68
+ include CarrierWave::Uploader::FileSize
60
69
  include CarrierWave::Uploader::Processing
61
70
  include CarrierWave::Uploader::Versions
62
71
  include CarrierWave::Uploader::DefaultUrl
@@ -1,16 +1,15 @@
1
- # encoding: utf-8
1
+ require 'uri'
2
2
 
3
3
  module CarrierWave
4
4
  module Utilities
5
5
  module Uri
6
+ # based on Ruby < 2.0's URI.encode
7
+ SAFE_STRING = URI::REGEXP::PATTERN::UNRESERVED + '\/'
8
+ UNSAFE = Regexp.new("[^#{SAFE_STRING}]", false)
6
9
 
7
10
  private
8
11
  def encode_path(path)
9
- # based on Ruby < 2.0's URI.encode
10
- safe_string = URI::REGEXP::PATTERN::UNRESERVED + '\/'
11
- unsafe = Regexp.new("[^#{safe_string}]", false)
12
-
13
- path.to_s.gsub(unsafe) do
12
+ path.to_s.gsub(UNSAFE) do
14
13
  us = $&
15
14
  tmp = ''
16
15
  us.each_byte do |uc|
@@ -1,7 +1,4 @@
1
- # encoding: utf-8
2
-
3
1
  require 'carrierwave/utilities/uri'
4
- require 'carrierwave/utilities/deprecation'
5
2
 
6
3
  module CarrierWave
7
4
  module Utilities
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'active_model/validator'
4
2
  require 'active_support/concern'
5
3
 
@@ -13,7 +11,7 @@ module CarrierWave
13
11
  class ProcessingValidator < ::ActiveModel::EachValidator
14
12
 
15
13
  def validate_each(record, attribute, value)
16
- if e = record.send("#{attribute}_processing_error")
14
+ if e = record.__send__("#{attribute}_processing_error")
17
15
  message = (e.message == e.class.to_s) ? :carrierwave_processing_error : e.message
18
16
  record.errors.add(attribute, message)
19
17
  end
@@ -23,7 +21,7 @@ module CarrierWave
23
21
  class IntegrityValidator < ::ActiveModel::EachValidator
24
22
 
25
23
  def validate_each(record, attribute, value)
26
- if e = record.send("#{attribute}_integrity_error")
24
+ if e = record.__send__("#{attribute}_integrity_error")
27
25
  message = (e.message == e.class.to_s) ? :carrierwave_integrity_error : e.message
28
26
  record.errors.add(attribute, message)
29
27
  end
@@ -33,7 +31,7 @@ module CarrierWave
33
31
  class DownloadValidator < ::ActiveModel::EachValidator
34
32
 
35
33
  def validate_each(record, attribute, value)
36
- if e = record.send("#{attribute}_download_error")
34
+ if e = record.__send__("#{attribute}_download_error")
37
35
  message = (e.message == e.class.to_s) ? :carrierwave_download_error : e.message
38
36
  record.errors.add(attribute, message)
39
37
  end
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.11.2"
2
+ VERSION = "1.3.2"
3
3
  end
data/lib/carrierwave.rb CHANGED
@@ -1,7 +1,6 @@
1
- # encoding: utf-8
2
-
3
1
  require 'fileutils'
4
2
  require 'active_support/core_ext/object/blank'
3
+ require 'active_support/core_ext/object/try'
5
4
  require 'active_support/core_ext/class/attribute'
6
5
  require 'active_support/concern'
7
6
 
@@ -9,6 +8,7 @@ module CarrierWave
9
8
 
10
9
  class << self
11
10
  attr_accessor :root, :base_path
11
+ attr_writer :tmp_path
12
12
 
13
13
  def configure(&block)
14
14
  CarrierWave::Uploader::Base.configure(&block)
@@ -17,6 +17,10 @@ module CarrierWave
17
17
  def clean_cached_files!(seconds=60*60*24)
18
18
  CarrierWave::Uploader::Base.clean_cached_files!(seconds)
19
19
  end
20
+
21
+ def tmp_path
22
+ @tmp_path ||= File.expand_path(File.join('..', 'tmp'), root)
23
+ end
20
24
  end
21
25
 
22
26
  end
@@ -30,13 +34,37 @@ if defined?(Merb)
30
34
  Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
31
35
  end
32
36
 
37
+ elsif defined?(Jets)
38
+
39
+ module CarrierWave
40
+ class Turbine < Jets::Turbine
41
+ initializer "carrierwave.setup_paths" do |app|
42
+ CarrierWave.root = Jets.root.to_s
43
+ CarrierWave.tmp_path = "/tmp/carrierwave"
44
+ CarrierWave.configure do |config|
45
+ config.cache_dir = "/tmp/carrierwave/uploads/tmp"
46
+ end
47
+ end
48
+
49
+ initializer "carrierwave.active_record" do
50
+ ActiveSupport.on_load :active_record do
51
+ require 'carrierwave/orm/activerecord'
52
+ end
53
+ end
54
+ end
55
+ end
56
+
33
57
  elsif defined?(Rails)
34
58
 
35
59
  module CarrierWave
36
60
  class Railtie < Rails::Railtie
37
- initializer "carrierwave.setup_paths" do
61
+ initializer "carrierwave.setup_paths" do |app|
38
62
  CarrierWave.root = Rails.root.join(Rails.public_path).to_s
39
63
  CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
64
+ available_locales = Array(app.config.i18n.available_locales || [])
65
+ if available_locales.blank? || available_locales.include?(:en)
66
+ I18n.load_path.prepend(File.join(File.dirname(__FILE__), 'carrierwave', 'locale', "en.yml"))
67
+ end
40
68
  end
41
69
 
42
70
  initializer "carrierwave.active_record" do
@@ -44,13 +72,6 @@ elsif defined?(Rails)
44
72
  require 'carrierwave/orm/activerecord'
45
73
  end
46
74
  end
47
-
48
- ##
49
- # Loads the Carrierwave locale files before the Rails application locales
50
- # letting the Rails application overrite the carrierwave locale defaults
51
- config.before_configuration do
52
- I18n.load_path << File.join(File.dirname(__FILE__), "carrierwave", "locale", 'en.yml')
53
- end
54
75
  end
55
76
  end
56
77
 
@@ -72,6 +93,7 @@ end
72
93
  require "carrierwave/utilities"
73
94
  require "carrierwave/error"
74
95
  require "carrierwave/sanitized_file"
96
+ require "carrierwave/mounter"
75
97
  require "carrierwave/mount"
76
98
  require "carrierwave/processing"
77
99
  require "carrierwave/version"
@@ -1,7 +1,4 @@
1
- # encoding: utf-8
2
-
3
1
  class <%= class_name %>Uploader < CarrierWave::Uploader::Base
4
-
5
2
  # Include RMagick or MiniMagick support:
6
3
  # include CarrierWave::RMagick
7
4
  # include CarrierWave::MiniMagick
@@ -17,7 +14,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
17
14
  end
18
15
 
19
16
  # Provide a default URL as a default if there hasn't been a file uploaded:
20
- # def default_url
17
+ # def default_url(*args)
21
18
  # # For Rails 3.1+ asset pipeline compatibility:
22
19
  # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
23
20
  #
@@ -25,7 +22,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
25
22
  # end
26
23
 
27
24
  # Process files as they are uploaded:
28
- # process :scale => [200, 300]
25
+ # process scale: [200, 300]
29
26
  #
30
27
  # def scale(width, height)
31
28
  # # do something
@@ -33,12 +30,12 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
33
30
 
34
31
  # Create different versions of your uploaded files:
35
32
  # version :thumb do
36
- # process :resize_to_fit => [50, 50]
33
+ # process resize_to_fit: [50, 50]
37
34
  # end
38
35
 
39
36
  # Add a white list of extensions which are allowed to be uploaded.
40
37
  # For images you might use something like this:
41
- # def extension_white_list
38
+ # def extension_whitelist
42
39
  # %w(jpg jpeg gif png)
43
40
  # end
44
41
 
@@ -47,5 +44,4 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
47
44
  # def filename
48
45
  # "something.jpg" if original_filename
49
46
  # end
50
-
51
47
  end