carrierwave-qiniu 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7999cef021897ad06f58b741d5746b9e54a141d
4
- data.tar.gz: f8ace825efc9890fa35e0b3028286497f8b8e24a
3
+ metadata.gz: 2969c9d64f8400822f65b783381740a8a0626774
4
+ data.tar.gz: 28b9f1f27b77d1325345e10abc750f127c6f5129
5
5
  SHA512:
6
- metadata.gz: 88d106c2209f5a679a0ab998294f82589bc22a4ef268948660c518ee7d08cdc1d3d33f7d0b6a8bc4e35bf83a736a7a1a86b74d003a7adc611b854be3d428b941
7
- data.tar.gz: 0b56be95a27fd44619f124406036eed66a4e097f6a91a61b37b39fafbb6168defd7c17cc9945fac4ae8957ff4fddf096fb1de0353fe58c42d250885443432c41
6
+ metadata.gz: d11c7c6cf9982b4afbe13ebd5751e54070bfd7dcb011d8b1d61223037942dbfe8ae46842464ccc0cbab5fcfc57da42d237262a32a20a76ffd68a4c9e5b78fc8d
7
+ data.tar.gz: 4dc11efc08ada1f331d57c49d5b0622514147f8339b165274e6b22c9626761063ffd932411cfad1babee078066981878771aeead0dde2602d41a3699c6109827
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  ## CHANGE LOG
3
3
 
4
+ ### v1.1.4
5
+
6
+ - 支持带样式的私有链接
7
+
8
+ https://github.com/huobazi/carrierwave-qiniu/pull/80
9
+
4
10
  ### v1.1.3
5
11
 
6
12
  新增参数 qiniu_delete_after_days
@@ -19,7 +25,7 @@ https://github.com/huobazi/carrierwave-qiniu/pull/78
19
25
  ### v1.1.0
20
26
 
21
27
  - Require carrierwave ~> 1.0
22
- -
28
+
23
29
  https://github.com/huobazi/carrierwave-qiniu/pull/73
24
30
 
25
31
  ### v1.0.1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carrierwave::Qiniu
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?1.1.3)](http://badge.fury.io/rb/carrierwave-qiniu)
3
+ [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?1.1.4)](http://badge.fury.io/rb/carrierwave-qiniu)
4
4
 
5
5
  This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
6
6
 
@@ -10,7 +10,7 @@ example: https://github.com/huobazi/carrierwave-qiniu-example
10
10
 
11
11
  Add the following to your application's Gemfile:
12
12
 
13
- gem 'carrierwave-qiniu', '~> 1.1.3'
13
+ gem 'carrierwave-qiniu', '~> 1.1.4'
14
14
  # If you need to use locales other than English
15
15
  gem 'carrierwave-i18n'
16
16
 
@@ -20,7 +20,7 @@ And then execute:
20
20
 
21
21
  Or install it yourself as:
22
22
 
23
- $ gem install carrierwave-qiniu -v 1.1.3
23
+ $ gem install carrierwave-qiniu -v 1.1.4
24
24
 
25
25
  ## Usage
26
26
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.4"
5
5
  end
6
6
  end
@@ -1,6 +1,8 @@
1
1
  module CarrierWave
2
2
  module Qiniu
3
3
  module Url
4
+
5
+ ##
4
6
  # === Examples:
5
7
  #
6
8
  # avatar.url(:version)
@@ -10,33 +12,33 @@ module CarrierWave
10
12
  def url(*args)
11
13
  return super if args.empty?
12
14
 
13
- # Usage: avatar.url(style: 'imageView/0/w/200')
14
- url = super({})
15
- return unless url
15
+ # return nil if blank
16
+ return if file.blank?
16
17
 
18
+ # Usage: avatar.url(style: 'imageView/0/w/200')
17
19
  if args.first.is_a? Hash
18
- options = args.first
19
- if options[:style]
20
- return "#{url}?#{options[:style]}"
20
+ if style = args.first[:style]
21
+ return file.url(style: style)
21
22
  end
22
23
  else
23
- # Usage: avatar.url(version, options)
24
+ # Usage: avatar.url(version, options)
24
25
  version = args.first.to_sym
25
- if styles.key? version.to_sym
26
+ if styles.has_key? version
26
27
  options = args.last
27
28
 
28
- # TODO: handle private url
29
29
  # Usage: avatar.url(:version, inline: true)
30
- if options.present? && options.is_a?(Hash) && options[:inline] && styles[version]
31
- return "#{url}?#{styles[version]}"
32
- else # Usage: avatar.url(:version)
33
- # inline mode
34
- if self.class.qiniu_style_inline && styles[version]
35
- return "#{url}?#{styles[version]}"
36
- else
37
- return "#{url}#{self.class.qiniu_style_separator}#{version}"
38
- end
39
- end
30
+ url_options = if options.present? && options.is_a?(Hash) && options[:inline] && styles[version]
31
+ { style: styles[version] }
32
+ else
33
+ # global inline mode
34
+ if self.class.qiniu_style_inline && styles[version]
35
+ { style: styles[version] }
36
+ else
37
+ # Usage: avatar.url(:version)
38
+ { version: version }
39
+ end
40
+ end
41
+ return file.url(url_options) if url_options
40
42
  end
41
43
  end
42
44
 
@@ -131,8 +131,19 @@ module CarrierWave
131
131
  @path
132
132
  end
133
133
 
134
- def url
135
- qiniu_connection.download_url(@path)
134
+ ##
135
+ # Return qiniu URl, maybe with style
136
+ #
137
+ # === Parameters
138
+ # [options (Hash)] optional options hash, 图片样式 { version: :thumb } 或者 { style: "imageView2/1/w/200" }
139
+ #
140
+ # === Returns
141
+ #
142
+ # [String]
143
+ #
144
+ def url(options = {})
145
+ path = options.present? ? path_with_style(options) : @path
146
+ qiniu_connection.download_url(path)
136
147
  end
137
148
 
138
149
  def store(file)
@@ -219,6 +230,18 @@ module CarrierWave
219
230
  @file_info ||= qiniu_connection.stat(@path)
220
231
  end
221
232
 
233
+ def path_with_style(options)
234
+ return @path unless options
235
+
236
+ if version = options[:version]
237
+ "#{@path}#{@uploader.class.qiniu_style_separator}#{version}"
238
+ elsif style = options[:style]
239
+ "#{@path}?#{style}"
240
+ else
241
+ @path
242
+ end
243
+ end
244
+
222
245
  end
223
246
 
224
247
  def store!(file)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu