thorsson_carrierwave 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Generators +4 -0
- data/History.txt +125 -0
- data/Manifest.txt +111 -0
- data/README.rdoc +528 -0
- data/Rakefile +39 -0
- data/cucumber.yml +2 -0
- data/features/caching.feature +28 -0
- data/features/download.feature +20 -0
- data/features/file_storage.feature +37 -0
- data/features/file_storage_overridden_filename.feature +38 -0
- data/features/file_storage_overridden_store_dir.feature +38 -0
- data/features/file_storage_reversing_processor.feature +43 -0
- data/features/fixtures/bork.txt +1 -0
- data/features/fixtures/monkey.txt +1 -0
- data/features/grid_fs_storage.feature +32 -0
- data/features/mount_activerecord.feature +46 -0
- data/features/mount_datamapper.feature +46 -0
- data/features/step_definitions/activerecord_steps.rb +22 -0
- data/features/step_definitions/caching_steps.rb +14 -0
- data/features/step_definitions/datamapper_steps.rb +29 -0
- data/features/step_definitions/download_steps.rb +4 -0
- data/features/step_definitions/file_steps.rb +53 -0
- data/features/step_definitions/general_steps.rb +85 -0
- data/features/step_definitions/mount_steps.rb +19 -0
- data/features/step_definitions/store_steps.rb +18 -0
- data/features/support/activerecord.rb +30 -0
- data/features/support/datamapper.rb +7 -0
- data/features/support/env.rb +22 -0
- data/features/versions_basics.feature +50 -0
- data/features/versions_nested_versions.feature +70 -0
- data/features/versions_overridden_filename.feature +51 -0
- data/features/versions_overriden_store_dir.feature +41 -0
- data/lib/carrierwave/compatibility/paperclip.rb +95 -0
- data/lib/carrierwave/core_ext/blank.rb +46 -0
- data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
- data/lib/carrierwave/core_ext/module_setup.rb +51 -0
- data/lib/carrierwave/mount.rb +359 -0
- data/lib/carrierwave/orm/activerecord.rb +73 -0
- data/lib/carrierwave/orm/datamapper.rb +27 -0
- data/lib/carrierwave/orm/mongoid.rb +23 -0
- data/lib/carrierwave/orm/mongomapper.rb +27 -0
- data/lib/carrierwave/orm/sequel.rb +45 -0
- data/lib/carrierwave/processing/image_science.rb +101 -0
- data/lib/carrierwave/processing/mini_magick.rb +265 -0
- data/lib/carrierwave/processing/rmagick.rb +282 -0
- data/lib/carrierwave/sanitized_file.rb +273 -0
- data/lib/carrierwave/storage/abstract.rb +30 -0
- data/lib/carrierwave/storage/cloud_files.rb +169 -0
- data/lib/carrierwave/storage/file.rb +48 -0
- data/lib/carrierwave/storage/grid_fs.rb +97 -0
- data/lib/carrierwave/storage/right_s3.rb +167 -0
- data/lib/carrierwave/storage/s3.rb +199 -0
- data/lib/carrierwave/test/matchers.rb +128 -0
- data/lib/carrierwave/uploader/cache.rb +145 -0
- data/lib/carrierwave/uploader/callbacks.rb +42 -0
- data/lib/carrierwave/uploader/configuration.rb +130 -0
- data/lib/carrierwave/uploader/default_url.rb +19 -0
- data/lib/carrierwave/uploader/download.rb +59 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
- data/lib/carrierwave/uploader/mountable.rb +39 -0
- data/lib/carrierwave/uploader/processing.rb +83 -0
- data/lib/carrierwave/uploader/proxy.rb +62 -0
- data/lib/carrierwave/uploader/remove.rb +22 -0
- data/lib/carrierwave/uploader/store.rb +89 -0
- data/lib/carrierwave/uploader/url.rb +33 -0
- data/lib/carrierwave/uploader/versions.rb +146 -0
- data/lib/carrierwave/uploader.rb +44 -0
- data/lib/carrierwave.rb +99 -0
- data/merb_generators/uploader_generator.rb +22 -0
- data/rails_generators/uploader/USAGE +2 -0
- data/rails_generators/uploader/templates/uploader.rb +47 -0
- data/rails_generators/uploader/uploader_generator.rb +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/compatibility/paperclip_spec.rb +52 -0
- data/spec/fixtures/bork.txt +1 -0
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +1 -0
- data/spec/fixtures/test.jpg +1 -0
- data/spec/mount_spec.rb +538 -0
- data/spec/orm/activerecord_spec.rb +271 -0
- data/spec/orm/datamapper_spec.rb +168 -0
- data/spec/orm/mongoid_spec.rb +202 -0
- data/spec/orm/mongomapper_spec.rb +202 -0
- data/spec/orm/sequel_spec.rb +183 -0
- data/spec/processing/image_science_spec.rb +56 -0
- data/spec/processing/mini_magick_spec.rb +76 -0
- data/spec/processing/rmagick_spec.rb +75 -0
- data/spec/sanitized_file_spec.rb +623 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/storage/grid_fs_spec.rb +83 -0
- data/spec/storage/right_s3_spec.rb +83 -0
- data/spec/storage/s3_spec.rb +95 -0
- data/spec/uploader/cache_spec.rb +209 -0
- data/spec/uploader/configuration_spec.rb +105 -0
- data/spec/uploader/default_url_spec.rb +85 -0
- data/spec/uploader/download_spec.rb +75 -0
- data/spec/uploader/extension_whitelist_spec.rb +44 -0
- data/spec/uploader/mountable_spec.rb +33 -0
- data/spec/uploader/paths_spec.rb +22 -0
- data/spec/uploader/processing_spec.rb +73 -0
- data/spec/uploader/proxy_spec.rb +54 -0
- data/spec/uploader/remove_spec.rb +70 -0
- data/spec/uploader/store_spec.rb +264 -0
- data/spec/uploader/url_spec.rb +102 -0
- data/spec/uploader/versions_spec.rb +298 -0
- metadata +436 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Uploader
|
5
|
+
module Remove
|
6
|
+
|
7
|
+
depends_on CarrierWave::Uploader::Callbacks
|
8
|
+
|
9
|
+
##
|
10
|
+
# Removes the file and reset it
|
11
|
+
#
|
12
|
+
def remove!
|
13
|
+
with_callbacks(:remove) do
|
14
|
+
@file.delete if @file
|
15
|
+
@file = nil
|
16
|
+
@cache_id = nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end # Remove
|
21
|
+
end # Uploader
|
22
|
+
end # CarrierWave
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Uploader
|
5
|
+
module Store
|
6
|
+
|
7
|
+
depends_on CarrierWave::Uploader::Callbacks
|
8
|
+
depends_on CarrierWave::Uploader::Configuration
|
9
|
+
depends_on CarrierWave::Uploader::Cache
|
10
|
+
|
11
|
+
##
|
12
|
+
# Override this in your Uploader to change the filename.
|
13
|
+
#
|
14
|
+
# Be careful using record ids as filenames. If the filename is stored in the database
|
15
|
+
# the record id will be nil when the filename is set. Don't use record ids unless you
|
16
|
+
# understand this limitation.
|
17
|
+
#
|
18
|
+
# Do not use the version_name in the filename, as it will prevent versions from being
|
19
|
+
# loaded correctly.
|
20
|
+
#
|
21
|
+
# === Returns
|
22
|
+
#
|
23
|
+
# [String] a filename
|
24
|
+
#
|
25
|
+
def filename
|
26
|
+
@filename
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Calculates the path where the file should be stored. If +for_file+ is given, it will be
|
31
|
+
# used as the filename, otherwise +CarrierWave::Uploader#filename+ is assumed.
|
32
|
+
#
|
33
|
+
# === Parameters
|
34
|
+
#
|
35
|
+
# [for_file (String)] name of the file <optional>
|
36
|
+
#
|
37
|
+
# === Returns
|
38
|
+
#
|
39
|
+
# [String] the store path
|
40
|
+
#
|
41
|
+
def store_path(for_file=filename)
|
42
|
+
File.join([store_dir, full_filename(for_file)].compact)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Stores the file by passing it to this Uploader's storage engine.
|
47
|
+
#
|
48
|
+
# If new_file is omitted, a previously cached file will be stored.
|
49
|
+
#
|
50
|
+
# === Parameters
|
51
|
+
#
|
52
|
+
# [new_file (File, IOString, Tempfile)] any kind of file object
|
53
|
+
#
|
54
|
+
def store!(new_file=nil)
|
55
|
+
cache!(new_file) if new_file
|
56
|
+
if @file and @cache_id
|
57
|
+
with_callbacks(:store, new_file) do
|
58
|
+
@file = storage.store!(@file)
|
59
|
+
@cache_id = nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Retrieves the file from the storage.
|
66
|
+
#
|
67
|
+
# === Parameters
|
68
|
+
#
|
69
|
+
# [identifier (String)] uniquely identifies the file to retrieve
|
70
|
+
#
|
71
|
+
def retrieve_from_store!(identifier)
|
72
|
+
with_callbacks(:retrieve_from_store, identifier) do
|
73
|
+
@file = storage.retrieve!(identifier)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def full_filename(for_file)
|
80
|
+
for_file
|
81
|
+
end
|
82
|
+
|
83
|
+
def storage
|
84
|
+
@storage ||= self.class.storage.new(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
end # Store
|
88
|
+
end # Uploader
|
89
|
+
end # CarrierWave
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Uploader
|
5
|
+
module Url
|
6
|
+
|
7
|
+
##
|
8
|
+
# === Returns
|
9
|
+
#
|
10
|
+
# [String] the location where this file is accessible via a url
|
11
|
+
#
|
12
|
+
def url
|
13
|
+
if file.respond_to?(:url) and not file.url.blank?
|
14
|
+
file.url
|
15
|
+
elsif current_path
|
16
|
+
File.expand_path(current_path).gsub(File.expand_path(root), '')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :to_s, :url
|
21
|
+
|
22
|
+
##
|
23
|
+
# === Returns
|
24
|
+
#
|
25
|
+
# [String] A JSON serializtion containing this uploader's URL
|
26
|
+
#
|
27
|
+
def to_json
|
28
|
+
{ 'url' => url }.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
end # Url
|
32
|
+
end # Uploader
|
33
|
+
end # CarrierWave
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Uploader
|
5
|
+
module Versions
|
6
|
+
|
7
|
+
depends_on CarrierWave::Uploader::Callbacks
|
8
|
+
|
9
|
+
setup do
|
10
|
+
after :cache, :cache_versions!
|
11
|
+
after :store, :store_versions!
|
12
|
+
after :remove, :remove_versions!
|
13
|
+
after :retrieve_from_cache, :retrieve_versions_from_cache!
|
14
|
+
after :retrieve_from_store, :retrieve_versions_from_store!
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def version_names
|
20
|
+
@version_names ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Adds a new version to this uploader
|
25
|
+
#
|
26
|
+
# === Parameters
|
27
|
+
#
|
28
|
+
# [name (#to_sym)] name of the version
|
29
|
+
# [&block (Proc)] a block to eval on this version of the uploader
|
30
|
+
#
|
31
|
+
def version(name, &block)
|
32
|
+
name = name.to_sym
|
33
|
+
unless versions[name]
|
34
|
+
versions[name] = Class.new(self)
|
35
|
+
versions[name].version_names.push(*version_names)
|
36
|
+
versions[name].version_names.push(name)
|
37
|
+
class_eval <<-RUBY
|
38
|
+
def #{name}
|
39
|
+
versions[:#{name}]
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
end
|
43
|
+
versions[name].class_eval(&block) if block
|
44
|
+
versions[name]
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# === Returns
|
49
|
+
#
|
50
|
+
# [Hash{Symbol => Class}] a list of versions available for this uploader
|
51
|
+
#
|
52
|
+
def versions
|
53
|
+
@versions ||= {}
|
54
|
+
end
|
55
|
+
|
56
|
+
end # ClassMethods
|
57
|
+
|
58
|
+
##
|
59
|
+
# Returns a hash mapping the name of each version of the uploader to an instance of it
|
60
|
+
#
|
61
|
+
# === Returns
|
62
|
+
#
|
63
|
+
# [Hash{Symbol => CarrierWave::Uploader}] a list of uploader instances
|
64
|
+
#
|
65
|
+
def versions
|
66
|
+
return @versions if @versions
|
67
|
+
@versions = {}
|
68
|
+
self.class.versions.each do |name, klass|
|
69
|
+
@versions[name] = klass.new(model, mounted_as)
|
70
|
+
end
|
71
|
+
@versions
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# === Returns
|
76
|
+
#
|
77
|
+
# [String] the name of this version of the uploader
|
78
|
+
#
|
79
|
+
def version_name
|
80
|
+
self.class.version_names.join('_').to_sym unless self.class.version_names.blank?
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# When given a version name as a parameter, will return the url for that version
|
85
|
+
# This also works with nested versions.
|
86
|
+
#
|
87
|
+
# === Example
|
88
|
+
#
|
89
|
+
# my_uploader.url # => /path/to/my/uploader.gif
|
90
|
+
# my_uploader.url(:thumb) # => /path/to/my/thumb_uploader.gif
|
91
|
+
# my_uploader.url(:thumb, :small) # => /path/to/my/thumb_small_uploader.gif
|
92
|
+
#
|
93
|
+
# === Parameters
|
94
|
+
#
|
95
|
+
# [*args (Symbol)] any number of versions
|
96
|
+
#
|
97
|
+
# === Returns
|
98
|
+
#
|
99
|
+
# [String] the location where this file is accessible via a url
|
100
|
+
#
|
101
|
+
def url(*args)
|
102
|
+
if(args.first)
|
103
|
+
raise ArgumentError, "Version #{args.first} doesn't exist!" if versions[args.first.to_sym].nil?
|
104
|
+
# recursively proxy to version
|
105
|
+
versions[args.first.to_sym].url(*args[1..-1])
|
106
|
+
else
|
107
|
+
super()
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def full_filename(for_file)
|
114
|
+
[version_name, super(for_file)].compact.join('_')
|
115
|
+
end
|
116
|
+
|
117
|
+
def full_original_filename
|
118
|
+
[version_name, super].compact.join('_')
|
119
|
+
end
|
120
|
+
|
121
|
+
def cache_versions!(new_file)
|
122
|
+
versions.each do |name, v|
|
123
|
+
v.send(:cache_id=, cache_id)
|
124
|
+
v.cache!(new_file)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def store_versions!(new_file)
|
129
|
+
versions.each { |name, v| v.store!(new_file) }
|
130
|
+
end
|
131
|
+
|
132
|
+
def remove_versions!
|
133
|
+
versions.each { |name, v| v.remove! }
|
134
|
+
end
|
135
|
+
|
136
|
+
def retrieve_versions_from_cache!(cache_name)
|
137
|
+
versions.each { |name, v| v.retrieve_from_cache!(cache_name) }
|
138
|
+
end
|
139
|
+
|
140
|
+
def retrieve_versions_from_store!(identifier)
|
141
|
+
versions.each { |name, v| v.retrieve_from_store!(identifier) }
|
142
|
+
end
|
143
|
+
|
144
|
+
end # Versions
|
145
|
+
end # Uploader
|
146
|
+
end # CarrierWave
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
|
5
|
+
##
|
6
|
+
# See CarrierWave::Uploader::Base
|
7
|
+
#
|
8
|
+
module Uploader
|
9
|
+
|
10
|
+
##
|
11
|
+
# An uploader is a class that allows you to easily handle the caching and storage of
|
12
|
+
# uploaded files. Please refer to the README for configuration options.
|
13
|
+
#
|
14
|
+
# Once you have an uploader you can use it in isolation:
|
15
|
+
#
|
16
|
+
# my_uploader = MyUploader.new
|
17
|
+
# my_uploader.cache!(File.open(path_to_file))
|
18
|
+
# my_uploader.retrieve_from_store!('monkey.png')
|
19
|
+
#
|
20
|
+
# Alternatively, you can mount it on an ORM or other persistence layer, with
|
21
|
+
# +CarrierWave::Mount#mount_uploader+. There are extensions for activerecord and datamapper
|
22
|
+
# these are *very* simple (they are only a dozen lines of code), so adding your own should
|
23
|
+
# be trivial.
|
24
|
+
#
|
25
|
+
class Base
|
26
|
+
attr_reader :file
|
27
|
+
|
28
|
+
use CarrierWave::Uploader::Callbacks
|
29
|
+
use CarrierWave::Uploader::Proxy
|
30
|
+
use CarrierWave::Uploader::Url
|
31
|
+
use CarrierWave::Uploader::Mountable
|
32
|
+
use CarrierWave::Uploader::Cache
|
33
|
+
use CarrierWave::Uploader::Store
|
34
|
+
use CarrierWave::Uploader::Download
|
35
|
+
use CarrierWave::Uploader::Remove
|
36
|
+
use CarrierWave::Uploader::ExtensionWhitelist
|
37
|
+
use CarrierWave::Uploader::Processing
|
38
|
+
use CarrierWave::Uploader::Versions
|
39
|
+
use CarrierWave::Uploader::DefaultUrl
|
40
|
+
use CarrierWave::Uploader::Configuration
|
41
|
+
end # Base
|
42
|
+
|
43
|
+
end # Uploader
|
44
|
+
end # CarrierWave
|
data/lib/carrierwave.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'carrierwave/core_ext/blank'
|
5
|
+
require 'carrierwave/core_ext/module_setup'
|
6
|
+
require 'carrierwave/core_ext/inheritable_attributes'
|
7
|
+
require 'carrierwave/core_ext/file'
|
8
|
+
|
9
|
+
module CarrierWave
|
10
|
+
|
11
|
+
VERSION = "0.4.5"
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :root
|
15
|
+
|
16
|
+
def configure(&block)
|
17
|
+
CarrierWave::Uploader::Base.configure(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean_cached_files!
|
21
|
+
CarrierWave::Uploader::Base.clean_cached_files!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class UploadError < StandardError; end
|
26
|
+
class IntegrityError < UploadError; end
|
27
|
+
class InvalidParameter < UploadError; end
|
28
|
+
class ProcessingError < UploadError; end
|
29
|
+
class DownloadError < UploadError; end
|
30
|
+
|
31
|
+
autoload :SanitizedFile, 'carrierwave/sanitized_file'
|
32
|
+
autoload :Mount, 'carrierwave/mount'
|
33
|
+
autoload :RMagick, 'carrierwave/processing/rmagick'
|
34
|
+
autoload :ImageScience, 'carrierwave/processing/image_science'
|
35
|
+
autoload :MiniMagick, 'carrierwave/processing/mini_magick'
|
36
|
+
|
37
|
+
module Storage
|
38
|
+
autoload :Abstract, 'carrierwave/storage/abstract'
|
39
|
+
autoload :File, 'carrierwave/storage/file'
|
40
|
+
autoload :S3, 'carrierwave/storage/s3'
|
41
|
+
autoload :GridFS, 'carrierwave/storage/grid_fs'
|
42
|
+
autoload :RightS3, 'carrierwave/storage/right_s3'
|
43
|
+
autoload :CloudFiles, 'carrierwave/storage/cloud_files'
|
44
|
+
end
|
45
|
+
|
46
|
+
module Uploader
|
47
|
+
autoload :Base, 'carrierwave/uploader'
|
48
|
+
autoload :Cache, 'carrierwave/uploader/cache'
|
49
|
+
autoload :Store, 'carrierwave/uploader/store'
|
50
|
+
autoload :Download, 'carrierwave/uploader/download'
|
51
|
+
autoload :Callbacks, 'carrierwave/uploader/callbacks'
|
52
|
+
autoload :Processing, 'carrierwave/uploader/processing'
|
53
|
+
autoload :Versions, 'carrierwave/uploader/versions'
|
54
|
+
autoload :Remove, 'carrierwave/uploader/remove'
|
55
|
+
autoload :ExtensionWhitelist, 'carrierwave/uploader/extension_whitelist'
|
56
|
+
autoload :DefaultUrl, 'carrierwave/uploader/default_url'
|
57
|
+
autoload :Proxy, 'carrierwave/uploader/proxy'
|
58
|
+
autoload :Url, 'carrierwave/uploader/url'
|
59
|
+
autoload :Mountable, 'carrierwave/uploader/mountable'
|
60
|
+
autoload :Configuration, 'carrierwave/uploader/configuration'
|
61
|
+
end
|
62
|
+
|
63
|
+
module Compatibility
|
64
|
+
autoload :Paperclip, 'carrierwave/compatibility/paperclip'
|
65
|
+
end
|
66
|
+
|
67
|
+
module Test
|
68
|
+
autoload :Matchers, 'carrierwave/test/matchers'
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
if defined?(Merb)
|
74
|
+
|
75
|
+
CarrierWave.root = Merb.dir_for(:public)
|
76
|
+
Merb::BootLoader.before_app_loads do
|
77
|
+
# Setup path for uploaders and load all of them before classes are loaded
|
78
|
+
Merb.push_path(:uploaders, Merb.root / 'app' / 'uploaders', '*.rb')
|
79
|
+
Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
|
80
|
+
end
|
81
|
+
|
82
|
+
elsif defined?(Rails)
|
83
|
+
|
84
|
+
CarrierWave.root = File.join(Rails.root, 'public')
|
85
|
+
ActiveSupport::Dependencies.load_paths << File.join(Rails.root, "app", "uploaders")
|
86
|
+
|
87
|
+
elsif defined?(Sinatra)
|
88
|
+
|
89
|
+
CarrierWave.root = Sinatra::Application.public
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'activerecord') if defined?(ActiveRecord)
|
95
|
+
require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'datamapper') if defined?(DataMapper)
|
96
|
+
require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'sequel') if defined?(Sequel)
|
97
|
+
# ActiveRecord still used, mongomapper is used for cache
|
98
|
+
#require File.join(File.dirname(__FILE__), "carrierwave", "orm", "mongomapper") if defined?(MongoMapper)
|
99
|
+
require File.join(File.dirname(__FILE__), "carrierwave", "orm", "mongoid") if defined?(Mongoid)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Merb
|
4
|
+
module Generators
|
5
|
+
class UploaderGenerator < NamedGenerator
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.join(File.dirname(__FILE__), '..', '..', 'rails_generators', 'uploader', 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
first_argument :name, :required => true, :desc => "The name of this uploader"
|
12
|
+
|
13
|
+
template :uploader do |t|
|
14
|
+
t.source = 'uploader.rb'
|
15
|
+
t.destination = "app/uploaders/#{file_name}_uploader.rb"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
add :uploader, UploaderGenerator
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|