uppr 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/License.txt +22 -0
- data/Readme.md +66 -0
- data/lib/uppr.rb +10 -0
- data/lib/uppr/attachment.rb +63 -0
- data/lib/uppr/image.rb +93 -0
- data/lib/uppr/version.rb +3 -0
- data/lib/uppr/video.rb +95 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99fc982a2170512b8fc0ef0685d9aa24f13d40a8
|
4
|
+
data.tar.gz: 944e414f0356a5cb863a450bb685127287617bfe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bea16d44cd83808cd5ebf5132ff5d07843f66ca5226d559bd9310648a2b4e9367418bf61cc84de92d9272dbd245baf6696d24b3342612c855a42591118b7813c
|
7
|
+
data.tar.gz: 17201d88effb2c4123a4901719146d45d487d26fcf6268c735f320fc45e4d17dcf41968ba66ff8f9296e11a41e0ad7de91bdb48fc66d8ce049b698358d51eb61
|
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 JiriKolarik
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Readme.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Uppr
|
2
|
+
|
3
|
+
Uploader for Rails using CarrierWave uploader and support for image, video and attachment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
* Add this line to your application's Gemfile
|
8
|
+
```ruby
|
9
|
+
gem 'uppr'
|
10
|
+
```
|
11
|
+
|
12
|
+
* Load it in `lib/your_engine/engine.rb` if is used in engine
|
13
|
+
```ruby
|
14
|
+
require 'uppr'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Mount uploader to your model. Uploader supports images, videos and files.
|
20
|
+
|
21
|
+
* Uppr::Image
|
22
|
+
* Uppr::Video
|
23
|
+
* Uppr::Attachment
|
24
|
+
|
25
|
+
#####Example
|
26
|
+
```ruby
|
27
|
+
mount_uploader :image, Uppr::Image
|
28
|
+
mount_uploader :video, Uppr::Video
|
29
|
+
mount_uploader :attachment, Uppr::Attachment
|
30
|
+
```
|
31
|
+
|
32
|
+
It supports background uploading. If you want to upload on background, you need to have `attribute_tmp` in your database table.
|
33
|
+
|
34
|
+
#####Example
|
35
|
+
```ruby
|
36
|
+
store_in_background :image
|
37
|
+
store_in_background :video
|
38
|
+
store_in_background :attachment
|
39
|
+
```
|
40
|
+
|
41
|
+
### Image versions
|
42
|
+
* `original` 1920px x auto
|
43
|
+
* `original.thumb` 720px x auto
|
44
|
+
* `square` 1920px x 1920px
|
45
|
+
* `square.thumb` 720px x 720px
|
46
|
+
* `portrait` 1080 x 1920px
|
47
|
+
* `portrait.thumb` 720px x 1280px
|
48
|
+
* `landscape` 1920px x 1080px
|
49
|
+
* `landscape.thumb` 1280px x 720px
|
50
|
+
|
51
|
+
### Video versions
|
52
|
+
* `mp4` - original resolution in Apple format
|
53
|
+
* `mp4.p1080` - 1080p
|
54
|
+
* `mp4.p720` - 720p
|
55
|
+
* `ogv` - original resolution in Firefox format
|
56
|
+
* `ogv.p1080` - 1080p
|
57
|
+
* `ogv.p720` - 720p
|
58
|
+
* `webm` - original resolution in Google format
|
59
|
+
* `webm.p1080` - 1080p
|
60
|
+
* `webm.p720` - 720p
|
61
|
+
|
62
|
+
### Allowed attachments
|
63
|
+
* zip
|
64
|
+
* rar
|
65
|
+
* pdf
|
66
|
+
* doc
|
data/lib/uppr.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Uppr
|
2
|
+
class Attachment < CarrierWave::Uploader::Base
|
3
|
+
include ::CarrierWave::Backgrounder::Delay
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
# include CarrierWave::MiniMagick
|
7
|
+
|
8
|
+
# Choose what kind of storage to use for this uploader:
|
9
|
+
storage :file
|
10
|
+
# storage :fog
|
11
|
+
|
12
|
+
# Override the directory where uploaded files will be stored.
|
13
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
14
|
+
def store_dir
|
15
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
before :store, :remember_cache_id
|
19
|
+
after :store, :delete_tmp_dir
|
20
|
+
|
21
|
+
# store! nil's the cache_id after it finishes so we need to remember it for deletion
|
22
|
+
def remember_cache_id(new_file)
|
23
|
+
@cache_id_was = cache_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_tmp_dir(new_file)
|
27
|
+
# make sure we don't delete other things accidentally by checking the name pattern
|
28
|
+
if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
|
29
|
+
FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
34
|
+
# def default_url
|
35
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Process files as they are uploaded:
|
39
|
+
# process :scale => [200, 300]
|
40
|
+
#
|
41
|
+
# def scale(width, height)
|
42
|
+
# # do something
|
43
|
+
# end
|
44
|
+
|
45
|
+
# Create different versions of your uploaded files:
|
46
|
+
# version :thumb do
|
47
|
+
# process :scale => [50, 50]
|
48
|
+
# end
|
49
|
+
|
50
|
+
|
51
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
52
|
+
# For images you might use something like this:
|
53
|
+
def extension_white_list
|
54
|
+
%w(zip rar pdf doc)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Override the filename of the uploaded files:
|
58
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
59
|
+
# def filename
|
60
|
+
# "something.jpg" if original_filename
|
61
|
+
# end
|
62
|
+
end
|
63
|
+
end
|
data/lib/uppr/image.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
module Uppr
|
2
|
+
class Image < CarrierWave::Uploader::Base
|
3
|
+
include ::CarrierWave::Backgrounder::Delay
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
include CarrierWave::MiniMagick
|
7
|
+
|
8
|
+
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
9
|
+
include Sprockets::Rails::Helper
|
10
|
+
|
11
|
+
# Choose what kind of storage to use for this uploader:
|
12
|
+
storage :file
|
13
|
+
# storage :fog
|
14
|
+
|
15
|
+
# Override the directory where uploaded files will be stored.
|
16
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
17
|
+
def store_dir
|
18
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
22
|
+
def default_url
|
23
|
+
ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
|
24
|
+
end
|
25
|
+
|
26
|
+
before :store, :remember_cache_id
|
27
|
+
after :store, :delete_tmp_dir
|
28
|
+
|
29
|
+
# store! nil's the cache_id after it finishes so we need to remember it for deletion
|
30
|
+
def remember_cache_id(new_file)
|
31
|
+
@cache_id_was = cache_id
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_tmp_dir(new_file)
|
35
|
+
# make sure we don't delete other things accidentally by checking the name pattern
|
36
|
+
if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
|
37
|
+
FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Process files as they are uploaded:
|
42
|
+
# process :scale => [200, 300]
|
43
|
+
#
|
44
|
+
# def scale(width, height)
|
45
|
+
# # do something
|
46
|
+
# end
|
47
|
+
|
48
|
+
version :original do
|
49
|
+
process resize_to_limit: [1920, nil]
|
50
|
+
|
51
|
+
version :thumb do
|
52
|
+
process resize_to_limit: [720, nil]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
version :square do
|
57
|
+
process resize_to_fill: [1920, 1920]
|
58
|
+
|
59
|
+
version :thumb do
|
60
|
+
process resize_to_fill: [720, 720]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
version :portrait do
|
65
|
+
process resize_to_fill: [1080, 1920]
|
66
|
+
|
67
|
+
version :thumb do
|
68
|
+
process resize_to_fill: [720, 1280]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
version :landscape do
|
73
|
+
process resize_to_fill: [1920, 1080]
|
74
|
+
|
75
|
+
version :thumb do
|
76
|
+
process resize_to_fill: [1280, 720]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
81
|
+
# For images you might use something like this:
|
82
|
+
def extension_white_list
|
83
|
+
%w(jpg jpeg gif png)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Override the filename of the uploaded files:
|
87
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
88
|
+
# def filename
|
89
|
+
# "something.jpg" if original_filename
|
90
|
+
# end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
data/lib/uppr/version.rb
ADDED
data/lib/uppr/video.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module Uppr
|
2
|
+
class Video < CarrierWave::Uploader::Base
|
3
|
+
include ::CarrierWave::Backgrounder::Delay
|
4
|
+
include CarrierWave::FFmpeg
|
5
|
+
|
6
|
+
RESOLUTIONS = [
|
7
|
+
{ version: :p1080, resolution: '1920x1080'},
|
8
|
+
{ version: :p720, resolution: '1280x720'}
|
9
|
+
]
|
10
|
+
|
11
|
+
# Choose what kind of storage to use for this uploader:
|
12
|
+
storage :file
|
13
|
+
|
14
|
+
# Override the directory where uploaded files will be stored.
|
15
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
16
|
+
def store_dir
|
17
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
18
|
+
end
|
19
|
+
|
20
|
+
before :store, :remember_cache_id
|
21
|
+
after :store, :delete_tmp_dir
|
22
|
+
|
23
|
+
# store! nil's the cache_id after it finishes so we need to remember it for deletion
|
24
|
+
def remember_cache_id(new_file)
|
25
|
+
@cache_id_was = cache_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_tmp_dir(new_file)
|
29
|
+
# make sure we don't delete other things accidentally by checking the name pattern
|
30
|
+
if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
|
31
|
+
FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
version :mp4 do
|
36
|
+
process encode: [:mp4]
|
37
|
+
|
38
|
+
def full_filename(for_file)
|
39
|
+
super.chomp(File.extname(super)) + '.mp4'
|
40
|
+
end
|
41
|
+
|
42
|
+
RESOLUTIONS.each do |resolution|
|
43
|
+
version resolution[:version], if: "bigger_than_#{resolution[:resolution]}?".to_sym
|
44
|
+
|
45
|
+
version resolution[:version] do
|
46
|
+
process encode: [:mp4, resolution: resolution[:resolution]]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
version :webm do
|
52
|
+
process encode: [:webm]
|
53
|
+
|
54
|
+
def full_filename(for_file)
|
55
|
+
super.chomp(File.extname(super)) + '.webm'
|
56
|
+
end
|
57
|
+
|
58
|
+
RESOLUTIONS.each do |resolution|
|
59
|
+
version resolution[:version], if: "bigger_than_#{resolution[:resolution]}?".to_sym
|
60
|
+
|
61
|
+
version resolution[:version] do
|
62
|
+
process encode: [:webm, resolution: resolution[:resolution]]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
version :ogv do
|
68
|
+
process encode: [:ogv]
|
69
|
+
|
70
|
+
def full_filename(for_file)
|
71
|
+
super.chomp(File.extname(super)) + '.ogv'
|
72
|
+
end
|
73
|
+
|
74
|
+
RESOLUTIONS.each do |resolution|
|
75
|
+
version resolution[:version], if: "bigger_than_#{resolution[:resolution]}?".to_sym
|
76
|
+
|
77
|
+
version resolution[:version] do
|
78
|
+
process encode: [:ogv, resolution: resolution[:resolution]]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
RESOLUTIONS.each do |action|
|
84
|
+
define_method("bigger_than_#{action[:resolution]}?") do |argument|
|
85
|
+
movie(argument.path).resolution > action[:resolution] ? true : false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
90
|
+
# For images you might use something like this:
|
91
|
+
def extension_white_list
|
92
|
+
%w(mp4 mov avi mkv 3gp mpg mpeg)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uppr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiri Kolarik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: carrierwave_backgrounder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: carrierwave-ffmpeg
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mini_magick
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
description: Easy images, videos and files uploader
|
84
|
+
email:
|
85
|
+
- jiri.kolarik@imin.cz
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- License.txt
|
91
|
+
- Readme.md
|
92
|
+
- lib/uppr.rb
|
93
|
+
- lib/uppr/attachment.rb
|
94
|
+
- lib/uppr/image.rb
|
95
|
+
- lib/uppr/version.rb
|
96
|
+
- lib/uppr/video.rb
|
97
|
+
homepage: http://werein.cz
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: CarrierWave classes for uploading images, videos and files with background
|
121
|
+
support
|
122
|
+
test_files: []
|