carrierwave-magic 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -16
- data/carrierwave-magic.gemspec +1 -1
- data/lib/carrierwave-magic/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -2,29 +2,20 @@
|
|
2
2
|
|
3
3
|
This allows to set file type with ruby-filemagic instead of an extension
|
4
4
|
|
5
|
-
To set correct file extension on resulting files:
|
5
|
+
To set correct file extension on resulting files on disk:
|
6
|
+
|
6
7
|
1) Add 'mime-types' gem I reccomend using 'mime_types' 1.20 from git:
|
7
8
|
|
8
9
|
gem 'mime-types', github: 'halostatue/mime-types'
|
9
10
|
|
10
11
|
2) Add this to your uploader (or any other way)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
else
|
18
|
-
"#{secure_token(10)}.jpg"
|
19
|
-
end
|
13
|
+
def filename
|
14
|
+
if original_filename.present?
|
15
|
+
ext = MIME::Types[file.content_type].nil? ? file.extension : MIME::Types[file.content_type].first.extensions.first
|
16
|
+
split_extension(original_filename)[0] + '.' + ext
|
17
|
+
end
|
20
18
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
def secure_token(length=16)
|
25
|
-
var = :"@#{mounted_as}_secure_token"
|
26
|
-
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
|
27
|
-
end
|
28
19
|
|
29
20
|
|
30
21
|
Idea and some of the code from this pull request: https://github.com/jnicklas/carrierwave/pull/949
|
data/carrierwave-magic.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["glebtv@gmail.com"]
|
11
11
|
gem.description = %q{ruby-filemagic and mime-types for carrierwave}
|
12
12
|
gem.summary = %q{Set file mime type with ruby-filemagic and extension from mime type with mime-types for carrierwave}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/glebtv/carrierwave-magic"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-filemagic
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- carrierwave-magic.gemspec
|
59
59
|
- lib/carrierwave-magic.rb
|
60
60
|
- lib/carrierwave-magic/version.rb
|
61
|
-
homepage:
|
61
|
+
homepage: https://github.com/glebtv/carrierwave-magic
|
62
62
|
licenses: []
|
63
63
|
post_install_message:
|
64
64
|
rdoc_options: []
|