spree_banner 1.1.1 → 1.1.2

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.
@@ -22,6 +22,6 @@ module Spree
22
22
 
23
23
  end
24
24
  end
25
-
25
+
26
26
  end
27
27
  end
@@ -5,13 +5,13 @@ module Spree
5
5
  has_attached_file :attachment,
6
6
  :url => "/spree/banner/:id/:style_:basename.:extension",
7
7
  :path => ":rails_root/public/spree/banner/:id/:style_:basename.:extension",
8
- #:default_url => "/missing/:style.jpg",
9
- :styles => lambda {|a|
10
- :thumbnail => "80x80#",
11
- :custom => "#{a.instance.attachment_width}x#{a.instance.attachment_height}#"
12
- },
8
+ :styles => lambda {|a| {
9
+ :thumbnail => "80x80#",
10
+ :custom => "#{a.instance.attachment_width}x#{a.instance.attachment_height}#"
11
+ }},
13
12
  :convert_options => {
14
- :thumbnail => "-gravity center"
13
+ :thumbnail => "-gravity center",
14
+ :custom => "-gravity center"
15
15
  }
16
16
 
17
17
  after_post_process :find_dimensions
@@ -22,27 +22,22 @@ module Spree
22
22
 
23
23
  scope :enable, lambda { |category| {:conditions => {:enabled => true, :category => category}} }
24
24
 
25
- # Load S3 settings
26
- if (FileTest.exist?(Rails.root.join('config', 's3.yml')) && !YAML.load_file(Rails.root.join('config', 's3.yml'))[Rails.env].blank?)
27
- S3_OPTIONS = {
28
- :storage => 's3',
29
- :s3_credentials => Rails.root.join('config', 's3.yml')
30
- }
31
- elsif (FileTest.exist?(Rails.root.join('config', 's3.yml')) && ENV['S3_KEY'] && ENV['S3_SECRET'] && ENV['S3_BUCKET'])
32
- S3_OPTIONS = {
33
- :storage => 's3',
34
- :s3_credentials => {
35
- :access_key_id => ENV['S3_KEY'],
36
- :secret_access_key => ENV['S3_SECRET']
37
- },
38
- :bucket => ENV['S3_BUCKET']
39
- }
40
- else
41
- S3_OPTIONS = { :storage => 'filesystem' }
25
+ # Load user defined paperclip settings
26
+ if Spree::Config[:use_s3]
27
+ s3_creds = { :access_key_id => Spree::Config[:s3_access_key], :secret_access_key => Spree::Config[:s3_secret], :bucket => Spree::Config[:s3_bucket] }
28
+ Spree::Banner.attachment_definitions[:attachment][:storage] = :s3
29
+ Spree::Banner.attachment_definitions[:attachment][:s3_credentials] = s3_creds
30
+ Spree::Banner.attachment_definitions[:attachment][:s3_headers] = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
31
+ Spree::Banner.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket]
32
+ Spree::Banner.attachment_definitions[:attachment][:s3_protocol] = Spree::Config[:s3_protocol] unless Spree::Config[:s3_protocol].blank?
42
33
  end
43
-
44
- attachment_definitions[:attachment] = (attachment_definitions[:attachment] || {}).merge(S3_OPTIONS)
45
-
34
+
35
+ Spree::Banner.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
36
+ Spree::Banner.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path]
37
+ Spree::Banner.attachment_definitions[:attachment][:url] = Spree::Config[:attachment_url]
38
+ Spree::Banner.attachment_definitions[:attachment][:default_url] = Spree::Config[:attachment_default_url]
39
+ Spree::Banner.attachment_definitions[:attachment][:default_style] = Spree::Config[:attachment_default_style]
40
+
46
41
  def initialize(*args)
47
42
  super(*args)
48
43
  last_banner = Banner.last
@@ -50,12 +45,14 @@ module Spree
50
45
  end
51
46
 
52
47
  def find_dimensions
53
- temporary = attachment.queued_for_write[:original]
54
- filename = temporary.path unless temporary.nil?
55
- filename = attachment.path if filename.blank?
56
- geometry = Paperclip::Geometry.from_file(filename)
57
- self.attachment_width = geometry.width
58
- self.attachment_height = geometry.height
48
+ if self.attachment_width.blank? && self.attachment_height.blank?
49
+ temporary = attachment.queued_for_write[:original]
50
+ filename = temporary.path unless temporary.nil?
51
+ filename = attachment.path if filename.blank?
52
+ geometry = Paperclip::Geometry.from_file(filename)
53
+ self.attachment_width = geometry.width
54
+ self.attachment_height = geometry.height
55
+ end
59
56
  end
60
57
 
61
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_banner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-22 00:00:00.000000000 Z
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core