attachinary 1.2.6 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -137,6 +137,14 @@ user.photo_urls = %w[ http://path/to/photo1.jpg http://path/to/photo2.jpg]
137
137
 
138
138
  # uploading by passing IO object (e.g. direct file upload)
139
139
  user.avatar = File.open("/path/to/file", 'r')
140
+
141
+ # if you want to provide additionals parameters from http://cloudinary.com/documentation/upload_images
142
+ # you need to use diffrent syntax
143
+ user.send(:avatar=, File.open("path/to/file", 'r'), :folder => Rails.env.to_s)
144
+
145
+ # # uploading photos by passing multiple urls and optional parameters that will be added to every file.
146
+ user.send(:photo_urls=, %w[ http://path/to/photo1.jpg http://path/to/photo2.jpg], folder: Rails.env.to_s, use_filename: true, image_metadata: true)
147
+
140
148
  ```
141
149
 
142
150
 
@@ -10,9 +10,13 @@
10
10
  <ul>
11
11
  <% for(var i=0; i<files.length; i++){ %>
12
12
  <li>
13
- <img
14
- src="<%= $.cloudinary.url(files[i].public_id, { "version": files[i].version, "format": 'jpg', "crop": 'fill', "width": 75, "height": 75 }) %>"
15
- alt="" width="75" height="75" />
13
+ <% if(files[i].resource_type == "raw") { %>
14
+ <div class="raw-file"></div>
15
+ <% } else { %>
16
+ <img
17
+ src="<%= $.cloudinary.url(files[i].public_id, { "version": files[i].version, "format": 'jpg', "crop": 'fill', "width": 75, "height": 75 }) %>"
18
+ alt="" width="75" height="75" />
19
+ <% } %>
16
20
  <a href="#" data-remove="<%= files[i].public_id %>">Remove</a>
17
21
  </li>
18
22
  <% } %>
@@ -39,7 +43,8 @@
39
43
  @files = @options.files
40
44
 
41
45
  @$form = @$input.closest('form')
42
- @$submit = @$form.find('input[type=submit]')
46
+ @$submit = @$form.find(@options.submit_selector ? 'input[type=submit]')
47
+ @$wrapper = @$input.closest(@options.wrapper_container_selector) if @options.wrapper_container_selector?
43
48
 
44
49
  @initFileUpload()
45
50
  @addFilesContainer()
@@ -65,13 +70,14 @@
65
70
  bindEventHandlers: ->
66
71
  @$input.bind 'fileuploadsend', (event, data) =>
67
72
  @$input.addClass 'uploading'
73
+ @$wrapper.addClass 'uploading' if @$wrapper?
68
74
  @$form.addClass 'uploading'
69
75
 
70
76
  @$input.prop 'disabled', true
71
77
  if @config.disableWith
72
78
  @$submit.each (index,input) =>
73
79
  $input = $(input)
74
- $input.data 'old-val', $input.val()
80
+ $input.data 'old-val', $input.val() unless $input.data('old-val')?
75
81
  @$submit.val @config.disableWith
76
82
  @$submit.prop 'disabled', true
77
83
 
@@ -89,6 +95,7 @@
89
95
 
90
96
  @$input.bind 'fileuploadalways', (event) =>
91
97
  @$input.removeClass 'uploading'
98
+ @$wrapper.removeClass 'uploading' if @$wrapper?
92
99
  @$form.removeClass 'uploading'
93
100
 
94
101
  @checkMaximum()
@@ -106,7 +113,7 @@
106
113
 
107
114
 
108
115
  addFile: (file) ->
109
- if !@options.accept || $.inArray(file.format, @options.accept) != -1
116
+ if !@options.accept || $.inArray(file.format, @options.accept) != -1 || $.inArray(file.resource_type, @options.accept) != -1
110
117
  @files.push file
111
118
  @redraw()
112
119
  @checkMaximum()
@@ -129,8 +136,10 @@
129
136
 
130
137
  checkMaximum: ->
131
138
  if @maximumReached()
139
+ @$wrapper.addClass 'disabled' if @$wrapper?
132
140
  @$input.prop('disabled', true)
133
141
  else
142
+ @$wrapper.removeClass 'disabled' if @$wrapper?
134
143
  @$input.prop('disabled', false)
135
144
 
136
145
  maximumReached: ->
@@ -139,8 +148,11 @@
139
148
 
140
149
 
141
150
  addFilesContainer: ->
142
- @$filesContainer = $('<div class="attachinary_container">')
143
- @$input.after @$filesContainer
151
+ if @options.files_container_selector? and $(@options.files_container_selector).length > 0
152
+ @$filesContainer = $(@options.files_container_selector)
153
+ else
154
+ @$filesContainer = $('<div class="attachinary_container">')
155
+ @$input.after @$filesContainer
144
156
 
145
157
  redraw: ->
146
158
  @$filesContainer.empty()
@@ -9,15 +9,23 @@ module Attachinary
9
9
 
10
10
  # has_many :photo_files, ...
11
11
  # has_many :image_files, ...
12
- has_many :"#{relation}",
13
- as: :attachinariable,
14
- class_name: '::Attachinary::File',
15
- conditions: { scope: options[:scope].to_s },
16
- dependent: :destroy
12
+ if Rails::VERSION::MAJOR == 3
13
+ has_many :"#{relation}",
14
+ as: :attachinariable,
15
+ class_name: '::Attachinary::File',
16
+ conditions: { scope: options[:scope].to_s },
17
+ dependent: :destroy
18
+ else
19
+ has_many :"#{relation}",
20
+ -> { where scope: options[:scope].to_s },
21
+ as: :attachinariable,
22
+ class_name: '::Attachinary::File',
23
+ dependent: :destroy
24
+ end
17
25
 
18
26
 
19
27
  # def photo=(file)
20
- # input = Attachinary::Utils.process_input(input)
28
+ # input = Attachinary::Utils.process_input(input, upload_options)
21
29
  # if input.blank?
22
30
  # photo_files.clear
23
31
  # else
@@ -25,8 +33,8 @@ module Attachinary
25
33
  # self.photo_files = files
26
34
  # end
27
35
  # end
28
- define_method "#{options[:scope]}=" do |input|
29
- input = Attachinary::Utils.process_input(input, options[:scope])
36
+ define_method "#{options[:scope]}=" do |input, upload_options = {}|
37
+ input = Attachinary::Utils.process_input(input, upload_options, options[:scope])
30
38
  if input.nil?
31
39
  send("#{relation}").clear
32
40
  else
@@ -20,7 +20,9 @@ module Attachinary
20
20
 
21
21
  # attr_accessible :photo
22
22
  # attr_accessible :images
23
- attr_accessible :"#{options[:scope]}" if options[:accessible]
23
+ if Rails::VERSION::MAJOR == 3
24
+ attr_accessible :"#{options[:scope]}" if options[:accessible]
25
+ end
24
26
 
25
27
  # def photo?
26
28
  # photo.present?
@@ -43,16 +45,18 @@ module Attachinary
43
45
  # def photo_url=(url)
44
46
  # ...
45
47
  # end
46
- define_method :"#{options[:scope]}_url=" do |url|
47
- send(:"#{options[:scope]}=", Cloudinary::Uploader.upload(url, resource_type: "auto"))
48
+ define_method :"#{options[:scope]}_url=" do |url, upload_options = {}|
49
+ upload_options.merge! resource_type: 'auto'
50
+ send(:"#{options[:scope]}=", Cloudinary::Uploader.upload(url, upload_options))
48
51
  end
49
52
 
50
53
  else
51
54
  # def image_urls=(urls)
52
55
  # ...
53
56
  # end
54
- define_method :"#{options[:singular]}_urls=" do |urls|
55
- send(:"#{options[:scope]}=", urls.map { |url| Cloudinary::Uploader.upload(url, resource_type: "auto") })
57
+ define_method :"#{options[:singular]}_urls=" do |urls, upload_options = {}|
58
+ upload_options.merge! resource_type: 'auto'
59
+ send(:"#{options[:scope]}=", urls.map { |url| Cloudinary::Uploader.upload(url, upload_options) })
56
60
  end
57
61
  end
58
62
 
@@ -2,7 +2,9 @@ module Attachinary
2
2
  module FileMixin
3
3
  def self.included(base)
4
4
  base.validates :public_id, :version, :resource_type, presence: true
5
- base.attr_accessible :public_id, :version, :width, :height, :format, :resource_type
5
+ if Rails::VERSION::MAJOR == 3
6
+ base.attr_accessible :public_id, :version, :width, :height, :format, :resource_type
7
+ end
6
8
  base.after_destroy :destroy_file
7
9
  base.after_create :remove_temporary_tag
8
10
  end
@@ -22,12 +24,17 @@ module Attachinary
22
24
 
23
25
  def fullpath(options={})
24
26
  format = options.delete(:format)
25
- Cloudinary::Utils.cloudinary_url(path(format), options)
27
+ Cloudinary::Utils.cloudinary_url(path(format), options.reverse_merge(:resource_type => resource_type))
26
28
  end
27
-
29
+
30
+ protected
31
+ def keep_remote?
32
+ Cloudinary.config.attachinary_keep_remote == true
33
+ end
34
+
28
35
  private
29
36
  def destroy_file
30
- Cloudinary::Uploader.destroy(public_id) if public_id
37
+ Cloudinary::Uploader.destroy(public_id) if public_id && !keep_remote?
31
38
  end
32
39
 
33
40
  def remove_temporary_tag
@@ -21,7 +21,7 @@ module Attachinary
21
21
 
22
22
  # alias_method "orig_photo=", "photo="
23
23
  # def photo=(input)
24
- # input = Attachinary::Utils.process_input(input)
24
+ # input = Attachinary::Utils.process_input(input, upload_options)
25
25
  # if input.nil?
26
26
  # super(nil)
27
27
  # else
@@ -30,8 +30,8 @@ module Attachinary
30
30
  # end
31
31
  # end
32
32
  alias_method "orig_#{options[:scope]}=", "#{options[:scope]}="
33
- define_method "#{options[:scope]}=" do |input|
34
- input = Attachinary::Utils.process_input(input)
33
+ define_method "#{options[:scope]}=" do |input, upload_options = {}|
34
+ input = Attachinary::Utils.process_input(input, upload_options)
35
35
  if !input.nil?
36
36
  input = [input].flatten
37
37
  input = (options[:single] ? input[0] : input)
@@ -11,25 +11,31 @@ module Attachinary
11
11
  if hash['id']
12
12
  Attachinary::File.find hash['id']
13
13
  else
14
- file = Attachinary::File.new hash.slice(*Attachinary::File.attr_accessible[:default].to_a)
14
+ file = if Rails::VERSION::MAJOR == 3
15
+ Attachinary::File.new hash.slice(*Attachinary::File.attr_accessible[:default].to_a)
16
+ else
17
+ permitted_params = ActionController::Parameters.new(hash).permit(:public_id, :version, :width, :height, :format, :resource_type)
18
+ Attachinary::File.new(permitted_params)
19
+ end
15
20
  file.scope = scope.to_s if scope && file.respond_to?(:scope=)
16
21
  file
17
22
  end
18
23
  end
19
24
 
20
25
 
21
- def self.process_input(input, scope=nil)
26
+ def self.process_input(input, upload_options, scope=nil)
22
27
  case input
23
28
  when :blank?.to_proc
24
29
  nil
25
30
  when lambda { |e| e.respond_to?(:read) }
26
- process_hash Cloudinary::Uploader.upload(input, resource_type: 'auto'), scope
31
+ upload_options.merge! resource_type: 'auto'
32
+ process_hash Cloudinary::Uploader.upload(input, upload_options), scope
27
33
  when String
28
34
  process_json(input, scope)
29
35
  when Hash
30
36
  process_hash(input, scope)
31
37
  when Array
32
- input = input.map{ |el| process_input(el, scope) }.flatten.compact
38
+ input = input.map{ |el| process_input(el, upload_options, scope) }.flatten.compact
33
39
  input = nil if input.empty?
34
40
  input
35
41
  else
@@ -1,3 +1,3 @@
1
1
  module Attachinary
2
- VERSION = "1.2.6"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attachinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,43 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70169716225900 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70169716225900
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: cloudinary
27
- requirement: &70169716220740 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: 1.0.41
37
+ version: 1.0.69
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70169716220740
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.69
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sqlite3
38
- requirement: &70169716234040 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,21 +53,31 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70169716234040
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec-rails
49
- requirement: &70169716076720 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
- - - ~>
67
+ - - ! '>='
53
68
  - !ruby/object:Gem::Version
54
- version: '2.5'
69
+ version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70169716076720
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: valid_attribute
60
- requirement: &70169716073180 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70169716073180
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: capybara
71
- requirement: &70169716070020 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70169716070020
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: capybara-webkit
82
- requirement: &70169716084860 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,21 +117,31 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70169716084860
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: factory_girl_rails
93
- requirement: &70169716081200 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
- - - ~>
131
+ - - ! '>='
97
132
  - !ruby/object:Gem::Version
98
- version: '3.0'
133
+ version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70169716081200
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: launchy
104
- requirement: &70169716242740 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70169716242740
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: database_cleaner
115
- requirement: &70169716323400 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *70169716323400
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: rb-fsevent
126
- requirement: &70169716357580 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ~>
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: 0.9.1
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *70169716357580
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 0.9.1
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: guard-rspec
137
- requirement: &70169716354420 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,7 +197,12 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *70169716354420
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  description: Attachments handler for Rails that uses Cloudinary for storage.
147
207
  email:
148
208
  - milovan.zogovic@gmail.com
@@ -188,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
248
  version: '0'
189
249
  segments:
190
250
  - 0
191
- hash: -870591186806322932
251
+ hash: -869452005892458433
192
252
  required_rubygems_version: !ruby/object:Gem::Requirement
193
253
  none: false
194
254
  requirements:
@@ -197,11 +257,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
257
  version: '0'
198
258
  segments:
199
259
  - 0
200
- hash: -870591186806322932
260
+ hash: -869452005892458433
201
261
  requirements: []
202
262
  rubyforge_project:
203
- rubygems_version: 1.8.11
263
+ rubygems_version: 1.8.24
204
264
  signing_key:
205
265
  specification_version: 3
206
- summary: attachinary-1.2.6
266
+ summary: attachinary-1.3.0
207
267
  test_files: []