flexa_downloadable 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/flexa_downloadable/downloads_controller.rb +44 -3
- data/app/helpers/flexa_downloadable/application_helper.rb +2 -1
- data/app/helpers/flexa_downloadable/download_helper.rb +16 -0
- data/config/routes.rb +4 -0
- data/lib/flexa_downloadable/engine.rb +4 -0
- data/lib/flexa_downloadable/image.rb +19 -0
- data/lib/flexa_downloadable/version.rb +1 -1
- data/lib/flexa_downloadable.rb +1 -1
- metadata +19 -9
- data/app/assets/config/flexa_downloadable_manifest.js +0 -2
- data/app/assets/javascripts/flexa_downloadable/application.js +0 -13
- data/app/assets/stylesheets/flexa_downloadable/application.css +0 -15
- data/app/jobs/flexa_downloadable/application_job.rb +0 -4
- data/app/mailers/flexa_downloadable/application_mailer.rb +0 -6
- data/app/models/application_record.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e43e0d4f16bfa58abb44e24f9a21f032ad26802f
|
4
|
+
data.tar.gz: 726ec92cc292b811b0320a3d24ea103816163718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 008ea80636e198a2e2718e3645dc64356f94aaee0006d87a2abc073e4010a3cbd89552012b5251c14f7c362cbd04aa675986c134168cc22d9d23f792fff9f98b
|
7
|
+
data.tar.gz: 14bb1b9cc6f835222d2cd8d5cc84835cba6da5a23b87d27bdeb07548a01d91f3d14a1e7ba0ef528be0505796459d41355f1685fc9490c0b5bafbd14041010806
|
@@ -3,18 +3,59 @@ require_dependency "flexa_downloadable/application_controller"
|
|
3
3
|
module FlexaDownloadable
|
4
4
|
class FlexaDownloadable::DownloadsController < ApplicationController
|
5
5
|
def download
|
6
|
+
file = find_file
|
7
|
+
exec(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def by_id
|
11
|
+
file = FlexaDownloadable::Upload.find_by(file_params)
|
12
|
+
exec(file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def image
|
16
|
+
file = FlexaDownloadable::Upload.find_by(file_params)
|
17
|
+
exec(file, true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_file
|
6
21
|
id = params[:id].to_i
|
7
22
|
klass = params[:klass].classify
|
8
23
|
field = params[:field].downcase
|
9
24
|
|
10
25
|
object = eval("::#{klass}.find(#{id})")
|
11
|
-
|
26
|
+
object.send(field)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def exec(file, is_image = false)
|
12
32
|
if file
|
13
|
-
|
33
|
+
content = file.content
|
34
|
+
content = to_image(content) if is_image
|
35
|
+
send_data(
|
36
|
+
content,
|
37
|
+
filename: file.filename,
|
38
|
+
content_type: file.content_type,
|
39
|
+
disposition: content_disposition(is_image))
|
14
40
|
else
|
15
|
-
gflash :notice => 'Downloaded!'
|
16
41
|
redirect_to :back
|
17
42
|
end
|
18
43
|
end
|
44
|
+
|
45
|
+
def content_disposition is_image
|
46
|
+
if is_image
|
47
|
+
'inline'
|
48
|
+
else
|
49
|
+
'attachment'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_image content
|
54
|
+
Image.new(content, params[:width], params[:height]).resize
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_params
|
58
|
+
params.permit(:id, :filename)
|
59
|
+
end
|
19
60
|
end
|
20
61
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FlexaDownloadable
|
2
|
+
module DownloadHelper
|
3
|
+
def link_to_file(file)
|
4
|
+
link_to file.filename, file_path(file)
|
5
|
+
end
|
6
|
+
|
7
|
+
def image(file, **args)
|
8
|
+
image_tag file_path(file, args[:w], args[:h]), args
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_path(file, width = nil, height = nil)
|
12
|
+
flexa_downloadable.image_path(id: file.id, filename: file.filename, \
|
13
|
+
width: width, height: height)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
FlexaDownloadable::Engine.routes.draw do
|
2
2
|
get 'download/:id/:klass/:field' => 'downloads#download', as: 'flexa_download'
|
3
|
+
get 'download/:id/:filename' => 'downloads#by_id', as: 'by_id', \
|
4
|
+
constraints: { :filename => /[^\/]+/ }
|
5
|
+
get 'image/:id/:filename' => 'downloads#image', as: 'image', \
|
6
|
+
constraints: { :filename => /[^\/]+/ }
|
3
7
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FlexaDownloadable
|
2
|
+
class Image
|
3
|
+
def initialize image, width = nil, height = nil
|
4
|
+
@image = image
|
5
|
+
@with = width
|
6
|
+
@height = height
|
7
|
+
end
|
8
|
+
|
9
|
+
def resize
|
10
|
+
if (@width || @height)
|
11
|
+
image = MiniMagick::Image.read(@image)
|
12
|
+
resized = image.resize("#{@width}x#{@height}")
|
13
|
+
resized.to_blob
|
14
|
+
else
|
15
|
+
@image
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/flexa_downloadable.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexa_downloadable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gil Gomes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mini_magick
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: sqlite3
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,15 +68,10 @@ files:
|
|
54
68
|
- MIT-LICENSE
|
55
69
|
- README.md
|
56
70
|
- Rakefile
|
57
|
-
- app/assets/config/flexa_downloadable_manifest.js
|
58
|
-
- app/assets/javascripts/flexa_downloadable/application.js
|
59
|
-
- app/assets/stylesheets/flexa_downloadable/application.css
|
60
71
|
- app/controllers/flexa_downloadable/application_controller.rb
|
61
72
|
- app/controllers/flexa_downloadable/downloads_controller.rb
|
62
73
|
- app/helpers/flexa_downloadable/application_helper.rb
|
63
|
-
- app/
|
64
|
-
- app/mailers/flexa_downloadable/application_mailer.rb
|
65
|
-
- app/models/application_record.rb
|
74
|
+
- app/helpers/flexa_downloadable/download_helper.rb
|
66
75
|
- app/models/flexa_downloadable/application_record.rb
|
67
76
|
- app/models/flexa_downloadable/upload.rb
|
68
77
|
- app/views/layouts/flexa_downloadable/application.html.erb
|
@@ -70,6 +79,7 @@ files:
|
|
70
79
|
- db/migrate/20160324125419_create_flexa_downloadable_uploads.rb
|
71
80
|
- lib/flexa_downloadable.rb
|
72
81
|
- lib/flexa_downloadable/engine.rb
|
82
|
+
- lib/flexa_downloadable/image.rb
|
73
83
|
- lib/flexa_downloadable/version.rb
|
74
84
|
- lib/tasks/flexa_downloadable_tasks.rake
|
75
85
|
homepage: https://www.flexait.com.br
|
@@ -92,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
102
|
version: '0'
|
93
103
|
requirements: []
|
94
104
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.3
|
96
106
|
signing_key:
|
97
107
|
specification_version: 4
|
98
108
|
summary: Downloadable
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|