fileclip 0.2.4 → 0.3.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 +4 -4
- data/Gemfile +0 -3
- data/Gemfile.lock +32 -5
- data/README.md +2 -1
- data/TODO.md +0 -2
- data/fileclip.gemspec +2 -0
- data/lib/fileclip.rb +14 -2
- data/lib/fileclip/action_view/helpers.rb +1 -1
- data/lib/fileclip/configuration.rb +6 -1
- data/lib/fileclip/jobs/sidekiq.rb +11 -0
- data/lib/fileclip/version.rb +1 -1
- data/spec/fileclip_spec.rb +21 -3
- data/spec/spec_helper.rb +3 -0
- data/vendor/assets/javascripts/fileclip.js.coffee.erb +38 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0676c859073d216852c397b109a24de44013b53f
|
4
|
+
data.tar.gz: 6d017f9ac5d01e0b750144009c432c2583f5192a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae6c1d30f895d8071d07f693e3913ebb011c0c4dd9455d99af9fb97fd25572c7550680710ca2564132158c424cdab6d3d91d723de87df4961088a86bc8291a06
|
7
|
+
data.tar.gz: 13c7805036a72919a2060226c9a5440ab65411b6dc8716825bd74531eef12b16aa05b7474392cf7905948eef2f7476cb48ee548c12241fa0810af7b0a2c47239
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fileclip (0.2.
|
4
|
+
fileclip (0.2.4)
|
5
5
|
paperclip
|
6
6
|
paperclip (>= 3.5.1)
|
7
7
|
railties (>= 3.0)
|
@@ -39,11 +39,21 @@ GEM
|
|
39
39
|
multi_json (~> 1.0)
|
40
40
|
arel (3.0.2)
|
41
41
|
builder (3.0.4)
|
42
|
+
celluloid (0.15.2)
|
43
|
+
timers (~> 1.1.0)
|
42
44
|
climate_control (0.0.3)
|
43
45
|
activesupport (>= 3.0)
|
44
|
-
cocaine (0.5.
|
46
|
+
cocaine (0.5.3)
|
45
47
|
climate_control (>= 0.0.3, < 1.0)
|
48
|
+
connection_pool (1.2.0)
|
49
|
+
coveralls (0.7.0)
|
50
|
+
multi_json (~> 1.3)
|
51
|
+
rest-client
|
52
|
+
simplecov (>= 0.7)
|
53
|
+
term-ansicolor
|
54
|
+
thor
|
46
55
|
diff-lcs (1.2.4)
|
56
|
+
docile (1.1.0)
|
47
57
|
erubis (2.7.0)
|
48
58
|
hike (1.2.3)
|
49
59
|
i18n (0.6.4)
|
@@ -55,10 +65,10 @@ GEM
|
|
55
65
|
mime-types (1.23)
|
56
66
|
mono_logger (1.1.0)
|
57
67
|
multi_json (1.7.7)
|
58
|
-
paperclip (3.5.
|
68
|
+
paperclip (3.5.2)
|
59
69
|
activemodel (>= 3.0.0)
|
60
70
|
activesupport (>= 3.0.0)
|
61
|
-
cocaine (~> 0.5.
|
71
|
+
cocaine (~> 0.5.3)
|
62
72
|
mime-types
|
63
73
|
polyglot (0.3.3)
|
64
74
|
rack (1.4.5)
|
@@ -107,6 +117,17 @@ GEM
|
|
107
117
|
rspec-expectations (2.14.0)
|
108
118
|
diff-lcs (>= 1.1.3, < 2.0)
|
109
119
|
rspec-mocks (2.14.1)
|
120
|
+
sidekiq (2.14.0)
|
121
|
+
celluloid (>= 0.14.1)
|
122
|
+
connection_pool (>= 1.0.0)
|
123
|
+
json
|
124
|
+
redis (>= 3.0.4)
|
125
|
+
redis-namespace
|
126
|
+
simplecov (0.8.2)
|
127
|
+
docile (~> 1.1.0)
|
128
|
+
multi_json
|
129
|
+
simplecov-html (~> 0.8.0)
|
130
|
+
simplecov-html (0.8.0)
|
110
131
|
sinatra (1.4.3)
|
111
132
|
rack (~> 1.4)
|
112
133
|
rack-protection (~> 1.4)
|
@@ -117,8 +138,12 @@ GEM
|
|
117
138
|
rack (~> 1.0)
|
118
139
|
tilt (~> 1.1, != 1.3.0)
|
119
140
|
sqlite3 (1.3.7)
|
141
|
+
term-ansicolor (1.2.2)
|
142
|
+
tins (~> 0.8)
|
120
143
|
thor (0.18.1)
|
121
144
|
tilt (1.4.1)
|
145
|
+
timers (1.1.0)
|
146
|
+
tins (0.13.1)
|
122
147
|
treetop (1.4.14)
|
123
148
|
polyglot
|
124
149
|
polyglot (>= 0.3.1)
|
@@ -130,8 +155,10 @@ PLATFORMS
|
|
130
155
|
ruby
|
131
156
|
|
132
157
|
DEPENDENCIES
|
158
|
+
coveralls
|
133
159
|
fileclip!
|
134
|
-
rails
|
160
|
+
rails
|
135
161
|
resque
|
136
162
|
rspec
|
163
|
+
sidekiq
|
137
164
|
sqlite3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FileClip [](https://travis-ci.org/ScotterC/fileclip)
|
1
|
+
FileClip [](https://travis-ci.org/ScotterC/fileclip) [](https://coveralls.io/r/ScotterC/fileclip?branch=master)
|
2
2
|
========
|
3
3
|
|
4
4
|
A FilePicker / PaperClip mashup. Use Filepicker for uploads and paperclip to process them.
|
@@ -33,6 +33,7 @@ FileClip.configure do |config|
|
|
33
33
|
config.storage_path = "/assets/" # Defaults to "/fileclip/"
|
34
34
|
config.mime_types = "images/jpeg" # Defaults to "images/*"
|
35
35
|
config.file_access = "private" # Defaults to "public"
|
36
|
+
config.excluded_environments = [] # Defaults to ["test"]
|
36
37
|
end
|
37
38
|
````
|
38
39
|
|
data/TODO.md
CHANGED
@@ -7,13 +7,11 @@ Backend:
|
|
7
7
|
* Normalize filenames
|
8
8
|
|
9
9
|
Frontend:
|
10
|
-
* Loader for filepicker js only if needed
|
11
10
|
* Eliminate need for jQuery
|
12
11
|
* make it a form builder function that can accept a different url name
|
13
12
|
|
14
13
|
Extra features:
|
15
14
|
* Work with DelayedJob
|
16
|
-
* Work with Sidekiq
|
17
15
|
* Fallback to filepicker url if paperclip url doesn't exist
|
18
16
|
* Filepicker converts to match paperclip styles
|
19
17
|
* FilePicker droppane support
|
data/fileclip.gemspec
CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'sqlite3'
|
25
25
|
s.add_development_dependency "rails"
|
26
26
|
s.add_development_dependency 'resque'
|
27
|
+
s.add_development_dependency 'sidekiq'
|
28
|
+
s.add_development_dependency 'coveralls'
|
27
29
|
s.add_runtime_dependency(%q<railties>, [">= 3.0"])
|
28
30
|
|
29
31
|
s.add_runtime_dependency "paperclip"
|
data/lib/fileclip.rb
CHANGED
@@ -4,6 +4,7 @@ require 'fileclip/validators'
|
|
4
4
|
require 'fileclip/engine'
|
5
5
|
require 'fileclip/railtie'
|
6
6
|
require 'fileclip/jobs/resque'
|
7
|
+
require 'fileclip/jobs/sidekiq'
|
7
8
|
require 'rest-client'
|
8
9
|
|
9
10
|
# TODO: make fileclip methods only load on fileclipped models
|
@@ -26,6 +27,10 @@ module FileClip
|
|
26
27
|
!!(defined? Resque)
|
27
28
|
end
|
28
29
|
|
30
|
+
def sidekiq_enabled?
|
31
|
+
!!(defined? Sidekiq)
|
32
|
+
end
|
33
|
+
|
29
34
|
def change_keys
|
30
35
|
@@change_keys ||= [:filepicker_url]
|
31
36
|
end
|
@@ -72,18 +77,25 @@ module FileClip
|
|
72
77
|
if update_from_filepicker?
|
73
78
|
if FileClip.resque_enabled?
|
74
79
|
# TODO: self.class.name is webrick ???
|
75
|
-
|
80
|
+
process_with_resque!
|
81
|
+
elsif FileClip.sidekiq_enabled?
|
82
|
+
process_with_sidekiq!
|
76
83
|
else
|
77
84
|
process_from_filepicker
|
78
85
|
end
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|
82
|
-
def
|
89
|
+
def process_with_resque!
|
83
90
|
update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
|
84
91
|
::Resque.enqueue(FileClip::Jobs::Resque, self.class.name, self.id)
|
85
92
|
end
|
86
93
|
|
94
|
+
def process_with_sidekiq!
|
95
|
+
update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
|
96
|
+
FileClip::Jobs::Sidekiq.perform_async(self.class.name, self.id)
|
97
|
+
end
|
98
|
+
|
87
99
|
def process_from_filepicker
|
88
100
|
self.class.skip_callback :commit, :after, :update_from_filepicker!
|
89
101
|
self.send(:"#{attachment_name}=", URI.parse(filepicker_url))
|
@@ -2,7 +2,8 @@ module FileClip
|
|
2
2
|
class Configuration
|
3
3
|
attr_writer :filepicker_key, :services,
|
4
4
|
:max_size, :storage_path,
|
5
|
-
:mime_types, :file_access
|
5
|
+
:mime_types, :file_access,
|
6
|
+
:excluded_environments
|
6
7
|
|
7
8
|
def filepicker_key
|
8
9
|
@filepicker_key or raise "Set Filepicker api_key"
|
@@ -28,6 +29,10 @@ module FileClip
|
|
28
29
|
@file_access or "public"
|
29
30
|
end
|
30
31
|
|
32
|
+
def excluded_environments
|
33
|
+
@excluded_environments or ["test"]
|
34
|
+
end
|
35
|
+
|
31
36
|
end
|
32
37
|
|
33
38
|
class << self
|
data/lib/fileclip/version.rb
CHANGED
data/spec/fileclip_spec.rb
CHANGED
@@ -60,6 +60,17 @@ describe FileClip do
|
|
60
60
|
FileClip.resque_enabled?.should be_true
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
describe "sidekiq_enabled?" do
|
65
|
+
it "returns false by default" do
|
66
|
+
FileClip.sidekiq_enabled?.should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns true if resque exists" do
|
70
|
+
stub_const "Sidekiq", Class.new
|
71
|
+
FileClip.sidekiq_enabled?.should be_true
|
72
|
+
end
|
73
|
+
end
|
63
74
|
end
|
64
75
|
|
65
76
|
describe "instance methods" do
|
@@ -82,7 +93,7 @@ describe FileClip do
|
|
82
93
|
|
83
94
|
context "#update_from_filepicker!" do
|
84
95
|
|
85
|
-
context "without
|
96
|
+
context "without a background queue" do
|
86
97
|
before :each do
|
87
98
|
image.filepicker_url = filepicker_url
|
88
99
|
image.stub_chain(:previous_changes, :keys).and_return ["filepicker_url"]
|
@@ -96,17 +107,24 @@ describe FileClip do
|
|
96
107
|
end
|
97
108
|
end
|
98
109
|
|
99
|
-
context "with
|
110
|
+
context "with a background queue" do
|
100
111
|
before :each do
|
101
112
|
image.filepicker_url = filepicker_url
|
102
113
|
image.stub_chain(:previous_changes, :keys).and_return ["filepicker_url"]
|
103
114
|
end
|
104
115
|
|
105
|
-
it "enqueues job" do
|
116
|
+
it "enqueues job with Resque" do
|
106
117
|
stub_const "Resque", Class.new
|
107
118
|
Resque.should_receive(:enqueue).with(FileClip::Jobs::Resque, "Image", nil)
|
108
119
|
image.update_from_filepicker!
|
109
120
|
end
|
121
|
+
|
122
|
+
it "enqueues job with Sidekiq" do
|
123
|
+
stub_const "Sidekiq", Class.new
|
124
|
+
stub_const "Sidekiq::Worker", Class.new
|
125
|
+
FileClip::Jobs::Sidekiq.should_receive(:perform_async).with("Image", nil)
|
126
|
+
image.update_from_filepicker!
|
127
|
+
end
|
110
128
|
end
|
111
129
|
|
112
130
|
context "with delayed paperclip" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
class window.FileClip
|
2
2
|
_clicked_button: ""
|
3
3
|
|
4
|
+
@env = ->
|
5
|
+
"<%= Rails.env %>"
|
6
|
+
|
4
7
|
constructor: ->
|
8
|
+
excludedEnvs = <%= FileClip.configuration.excluded_environments %>
|
9
|
+
if @inArray(excludedEnvs, FileClip.env()) != -1
|
10
|
+
return false
|
11
|
+
|
12
|
+
@loadFilepicker()
|
5
13
|
filepicker.setKey('<%= FileClip.configuration.filepicker_key %>');
|
6
14
|
|
7
15
|
# For filepicker_helper
|
@@ -53,5 +61,35 @@ class window.FileClip
|
|
53
61
|
|
54
62
|
callback(file, @_clicked_button) if callback
|
55
63
|
|
64
|
+
loadFilepicker: ->
|
65
|
+
((a) ->
|
66
|
+
return if window.filepicker
|
67
|
+
b = a.createElement("script")
|
68
|
+
b.type = "text/javascript"
|
69
|
+
b.async = not 0
|
70
|
+
b.src = ((if "https:" is a.location.protocol then "https:" else "http:")) + "//api.filepicker.io/v1/filepicker.js"
|
71
|
+
c = a.getElementsByTagName("script")[0]
|
72
|
+
c.parentNode.insertBefore b, c
|
73
|
+
d = {}
|
74
|
+
d._queue = []
|
75
|
+
e = "pick,pickMultiple,pickAndStore,read,write,writeUrl,export,convert,store,storeUrl,remove,stat,setKey,constructWidget,makeDropPane".split(",")
|
76
|
+
f = (a, b) ->
|
77
|
+
->
|
78
|
+
b.push [a, arguments]
|
79
|
+
|
80
|
+
g = 0
|
81
|
+
|
82
|
+
while g < e.length
|
83
|
+
d[e[g]] = f(e[g], d._queue)
|
84
|
+
g++
|
85
|
+
window.filepicker = d
|
86
|
+
) document
|
56
87
|
|
88
|
+
inArray: (array, value) ->
|
89
|
+
return array.indexOf(value) if array.indexOf
|
90
|
+
i = 0
|
57
91
|
|
92
|
+
while i < array.length
|
93
|
+
return i if array[i] is value
|
94
|
+
i++
|
95
|
+
-1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fileclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Carleton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paperclip
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sidekiq
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: railties
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +175,7 @@ files:
|
|
147
175
|
- lib/fileclip/configuration.rb
|
148
176
|
- lib/fileclip/engine.rb
|
149
177
|
- lib/fileclip/jobs/resque.rb
|
178
|
+
- lib/fileclip/jobs/sidekiq.rb
|
150
179
|
- lib/fileclip/railtie.rb
|
151
180
|
- lib/fileclip/validators.rb
|
152
181
|
- lib/fileclip/version.rb
|