paperclip-qiniu 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paperclip-qiniu (0.0.3)
4
+ paperclip-qiniu (0.1.0)
5
5
  paperclip
6
6
  qiniu-rs (~> 3.0)
7
7
 
data/README.md CHANGED
@@ -43,11 +43,21 @@ for more information on `qiniu_host`, read http://docs.qiniutek.com/v2/sdk/ruby/
43
43
  ```ruby
44
44
  class Image < ActiveRecord::Base
45
45
  attr_accessible :file
46
- has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :path => ":class/:attachment/:id/:style/:basename.:extension"
46
+ has_attached_file :file, :path => ":class/:attachment/:id/:basename.:extension"
47
47
  validates :file, :attachment_presence => true
48
48
  end
49
49
  ```
50
50
 
51
+ * show image in your view
52
+
53
+ ```erb
54
+ <%= qiniu_image_tag @image.file.url, :thumbnail => '300x300>', :quality => 80 %>
55
+ or
56
+ <%= image_tag qiniu_image_path(@image.file.url, :thumbnail => '300x300>', :quality => 80) %>
57
+ ```
58
+
59
+ support options: `thumbnail`, `gravity`, `crop`, `quality`, `rotate`, `format`, `auto_orient`. for more information on these options, check the document: http://docs.qiniutek.com/v3/api/foimg/#fo-imageMogr
60
+
51
61
  ## Contributing
52
62
 
53
63
  1. Fork it
@@ -58,6 +68,11 @@ end
58
68
 
59
69
  ## CHANGELOG
60
70
 
71
+ ### 0.1.0 (2012-09-06)
72
+
73
+ * add view helper: qiniu_image_tag, qiniu_image_path
74
+ * update demo code, style is no longer needed.
75
+
61
76
  ### 0.0.3 (2012-09-06)
62
77
 
63
78
  * support qiniu api v3.
@@ -1,2 +1,4 @@
1
1
  require "paperclip-qiniu/version"
2
2
  require 'paperclip/storage/qiniu'
3
+ require 'paperclip/qiniu/action_view_extensions/qiniu_image_path' if defined?(ActionView)
4
+ require 'paperclip/qiniu/action_view_extensions/qiniu_image_tag' if defined?(ActionView)
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Qiniu
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require 'paperclip-qiniu'
@@ -0,0 +1,34 @@
1
+ module Paperclip
2
+ module Qiniu
3
+ module ActionViewExtensions
4
+ module QiniuImagePath
5
+ def qiniu_image_path(source, options={})
6
+ options = options.clone
7
+ thumbnail = options.delete(:thumbnail)
8
+ gravity = options.delete(:gravity)
9
+ crop = options.delete(:crop)
10
+ quality = options.delete(:quality)
11
+ rotate = options.delete(:rotate)
12
+ format = options.delete(:format)
13
+ auto_orient = options.delete(:auto_orient)
14
+ res = source
15
+ res += "?imageMogr"
16
+ res += "/thumbnail/#{CGI.escape thumbnail}" if thumbnail
17
+ res += "/gravity/#{CGI.escape gravity}" if gravity
18
+ res += "/crop/#{CGI.escape crop}" if crop
19
+ res += "/quality/#{CGI.escape quality.to_s}" if quality
20
+ res += "/rotate/#{CGI.escape rotate.to_s}" if rotate
21
+ res += "/format/#{CGI.escape format.to_s}" if format
22
+ res += "/auto-orient" if auto_orient
23
+ if res.end_with? '?imageMogr'
24
+ source
25
+ else
26
+ res
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ ActionView::Base.send :include, Paperclip::Qiniu::ActionViewExtensions::QiniuImagePath
@@ -0,0 +1,31 @@
1
+ module Paperclip
2
+ module Qiniu
3
+ module ActionViewExtensions
4
+ module QiniuImageTag
5
+ def qiniu_image_tag(source, options={})
6
+ options.symbolize_keys!
7
+
8
+ src = path_to_image(source)
9
+ options[:src] = qiniu_image_path(src, options)
10
+
11
+ unless src =~ /^(?:cid|data):/ || src.blank?
12
+ options[:alt] = options.fetch(:alt){ image_alt(src) }
13
+ end
14
+
15
+ if size = options.delete(:size)
16
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
17
+ end
18
+
19
+ if mouseover = options.delete(:mouseover)
20
+ options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
21
+ options[:onmouseout] = "this.src='#{options[:src]}'"
22
+ end
23
+
24
+ tag("img", options)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ ActionView::Base.send :include, Paperclip::Qiniu::ActionViewExtensions::QiniuImageTag
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -76,6 +76,9 @@ files:
76
76
  - lib/paperclip-qiniu.rb
77
77
  - lib/paperclip-qiniu/exceptions.rb
78
78
  - lib/paperclip-qiniu/version.rb
79
+ - lib/paperclip/qiniu.rb
80
+ - lib/paperclip/qiniu/action_view_extensions/qiniu_image_path.rb
81
+ - lib/paperclip/qiniu/action_view_extensions/qiniu_image_tag.rb
79
82
  - lib/paperclip/storage/qiniu.rb
80
83
  - paperclip-qiniu.gemspec
81
84
  - spec/lib/paperclip/storage/qiniu_spec.rb