spree_heroku 0.0.1 → 0.0.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.
@@ -1,3 +1,3 @@
1
1
  module SpreeHeroku
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/spree_heroku.rb CHANGED
@@ -1,4 +1,48 @@
1
+ require 'spree_core'
2
+
1
3
  module SpreeHeroku
4
+ class Engine < Rails::Engine
5
+ config.autoload_paths += %W(#{config.root}/lib)
6
+
7
+ def self.activate
8
+ aws_s3_file = File.join(::Rails.root.to_s, 'config', 'aws_s3.yml')
9
+ if File.exists?(aws_s3_file)
10
+ s3_options = {
11
+ :storage => "s3",
12
+ :s3_credentials => aws_s3_file
13
+ }
14
+ elsif ENV['S3_KEY'] && ENV['S3_SECRET'] && ENV['S3_BUCKET']
15
+ s3_options = {
16
+ :storage => "s3",
17
+ :s3_credentials => {
18
+ :access_key_id => ENV['S3_KEY'],
19
+ :secret_access_key => ENV['S3_SECRET']
20
+ },
21
+ :bucket => ENV['S3_BUCKET']
22
+ }
23
+ else
24
+ s3_options = {}
25
+ end
26
+
27
+
28
+ Taxon.class_eval do
29
+ has_attached_file :icon,
30
+ {:styles => { :mini => '32x32>', :normal => '128x128>' },
31
+ :default_style => :mini,
32
+ :path => "assets/taxons/:id/:style/:basename.:extension"}.merge(s3_options)
33
+ end
34
+
35
+ Image.class_eval do
36
+ has_attached_file :attachment,
37
+ {:styles => { :mini => '48x48>', :small => '100x100>', :product => '240x240>', :large => '600x600>' },
38
+ :default_style => :product,
39
+ :path => "assets/products/:id/:style/:basename.:extension"}.merge(s3_options)
40
+
41
+ end
42
+ end
43
+ config.to_prepare &method(:activate).to_proc
44
+ end
45
+
2
46
  module Rails
3
47
  class Railtie < ::Rails::Railtie
4
48
  console do
@@ -8,13 +52,7 @@ module SpreeHeroku
8
52
  end
9
53
 
10
54
  initializer "heroku" do
11
- aws_s3_file = File.join(File.dirname(__FILE__), '..', 'aws_s3.yml')
12
-
13
- if File.exists?(aws_s3_file)
14
- HEROKU_AWS_S3 = YAML.load_file(aws_s3_file)[Rails.env]
15
- else
16
- HEROKU_AWS_S3 = {}
17
- end
55
+
18
56
  end
19
57
 
20
58
 
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cody Swann
@@ -34,11 +34,10 @@ files:
34
34
  - MIT-LICENSE
35
35
  - README.markdown
36
36
  - Rakefile
37
- - app/models/image.rb
38
- - app/models/taxon.rb
39
37
  - aws_s3.yml.example
40
38
  - lib/spree_heroku.rb
41
39
  - lib/spree_heroku/version.rb
40
+ - pkg/spree_heroku-0.0.1.gem
42
41
  - spec/spec.opts
43
42
  - spec/spec_helper.rb
44
43
  - spree_heroku.gemspec
data/app/models/image.rb DELETED
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- class Image < Asset
3
- has_attached_file :attachment,
4
- :styles => { :mini => '48x48>', :small => '100x100>', :product => '240x240>', :large => '600x600>' },
5
- :default_style => :product,
6
- :path => "assets/products/:id/:style/:basename.:extension",
7
- :storage => "s3",
8
- :s3_credentials => {
9
- :access_key_id => ENV['S3_KEY'] || HEROKU_AWS_S3['access_key_id'],
10
- :secret_access_key => ENV['S3_SECRET'] || HEROKU_AWS_S3['secret_access_key']
11
- },
12
- :bucket => ENV['S3_BUCKET'] || HEROKU_AWS_S3['bucket']
13
-
14
- # save the w,h of the original image (from which others can be calculated)
15
- # we need to look at the write-queue for images which have not been saved yet
16
- after_post_process :find_dimensions
17
- def find_dimensions
18
- temporary = attachment.queued_for_write[:original]
19
- filename = temporary.path unless temporary.nil?
20
- filename = attachment.path if filename.blank?
21
- geometry = Paperclip::Geometry.from_file(filename)
22
- self.attachment_width = geometry.width
23
- self.attachment_height = geometry.height
24
- end
25
-
26
- # if there are errors from the plugin, then add a more meaningful message
27
- def validate
28
- unless attachment.errors.empty?
29
- # uncomment this to get rid of the less-than-useful interrim messages
30
- # errors.clear
31
- errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
32
- false
33
- end
34
- end
35
- end
data/app/models/taxon.rb DELETED
@@ -1,54 +0,0 @@
1
- class Taxon < ActiveRecord::Base
2
- acts_as_nested_set :dependent => :destroy
3
-
4
- belongs_to :taxonomy
5
- has_and_belongs_to_many :products
6
- before_create :set_permalink
7
- before_save :ensure_trailing_slash
8
-
9
- validates_presence_of :name
10
- has_attached_file :icon,
11
- :styles => { :mini => '32x32>', :normal => '128x128>' },
12
- :default_style => :mini,
13
- :path => "assets/taxons/:id/:style/:basename.:extension",
14
- :storage => "s3",
15
- :s3_credentials => {
16
- :access_key_id => ENV['S3_KEY'] || HEROKU_AWS_S3['access_key_id'],
17
- :secret_access_key => ENV['S3_SECRET'] || HEROKU_AWS_S3['secret_access_key']
18
- },
19
- :bucket => ENV['S3_BUCKET'] || HEROKU_AWS_S3['bucket']
20
-
21
- # indicate which filters should be used for a taxon
22
- # this method should be customized to your own site
23
- include ::ProductFilters # for detailed defs of filters
24
- def applicable_filters
25
- fs = []
26
- fs << ProductFilters.taxons_below(self)
27
- ## unless it's a root taxon? left open for demo purposes
28
- fs += [
29
- ProductFilters.price_filter,
30
- ProductFilters.brand_filter,
31
- ProductFilters.selective_brand_filter(self) ]
32
- end
33
-
34
- # Creates permalink based on .to_url method provided by stringx gem
35
- def set_permalink
36
- if parent_id.nil?
37
- self.permalink = name.to_url + "/" if self.permalink.blank?
38
- else
39
- parent_taxon = Taxon.find(parent_id)
40
- self.permalink = parent_taxon.permalink + (self.permalink.blank? ? name.to_url : self.permalink.split("/").last) + "/"
41
- end
42
- end
43
-
44
- private
45
- # obsolete, kept for backwards compat
46
- def escape(str)
47
- str.blank? ? "" : str.to_url
48
- end
49
-
50
- def ensure_trailing_slash
51
- set_permalink if self.permalink.blank?
52
- self.permalink += "/" unless self.permalink[-1..-1] == "/"
53
- end
54
- end