spree_heroku 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gems ADDED
@@ -0,0 +1,17 @@
1
+ rails -v '2.3.5'
2
+ highline -v '1.5.1'
3
+ authlogic -v '>=2.1.2'
4
+ authlogic-oid -v '1.0.4'
5
+ activemerchant -v '1.5.1'
6
+ activerecord-tableless -v '0.1.0'
7
+ less -v '1.2.20'
8
+ stringex -v '1.0.3'
9
+ chronic -v '0.2.3'
10
+ whenever -v '0.3.7'
11
+ searchlogic -v '2.3.5'
12
+ will_paginate -v '2.3.11'
13
+ faker -v '0.3.1'
14
+ paperclip -v '>=2.3.1.1'
15
+ state_machine -v '0.8.0'
16
+ aws-s3 -v '>=0.6.2'
17
+ spree -v '0.10.2'
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ *~
3
+ config/aws_s3.yml
4
+ .rvmrc*
data/Gemfile ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Casper Fabricius
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,88 @@
1
+ # Spree on Heroku
2
+
3
+ This is an extension for Spree, allowing the e-commerce system to run on Heroku - http://heroku.com.
4
+
5
+ The major constraint on Heroku is that we can't write files to disk, so this extension disables all disk caching, fixes a few issues and changes Spree to store on Amazon S3.
6
+
7
+ # Requirements
8
+
9
+ A Heroku account and an Amazon S3 account with a bucket.
10
+
11
+ # Installation and configuration
12
+
13
+ Make a Spree application:
14
+
15
+ <pre>
16
+ spree myapp
17
+ </pre>
18
+
19
+ Install this extension:
20
+
21
+ <pre>
22
+ cd myapp
23
+ script/extension install git://github.com/RSpace/spree-heroku.git
24
+ </pre>
25
+
26
+ Copy the .gems manifest to the root of your application:
27
+
28
+ <pre>
29
+ cp vendor/extensions/heroku/.gems ./
30
+ </pre>
31
+
32
+ Configure the extension with your S3 information.
33
+
34
+ You can either specify the S3 credentials via Heroku's environment variables (recommended):
35
+
36
+ <pre>
37
+ heroku config:add S3_KEY=[your S3 key]
38
+ heroku config:add S3_SECRET=[your S3 secret]
39
+ heroku config:add S3_BUCKET=[your S3 bucket]
40
+ </pre>
41
+
42
+ - or you can use a YAML file:
43
+
44
+ <pre>
45
+ cp vendor/extensions/heroku/config/aws_s3.yml.example vendor/extensions/heroku/config/aws_s3.yml
46
+ </pre>
47
+
48
+ Enter your S3 configuration to vendor/extensions/heroku/config/aws_s3.yml
49
+
50
+ Create a Heroku application and deploy it:
51
+
52
+ <pre>
53
+ git init
54
+ git add .
55
+ git commit -m 'Initial create'
56
+ heroku create --stack bamboo-ree-1.8.7 myapp
57
+ git push heroku master
58
+ </pre>
59
+
60
+ Enable SSL, since Spree uses SSL for administration and payment flow in its standard setup:
61
+
62
+ <pre>
63
+ heroku addons:add "Piggyback SSL"
64
+ </pre>
65
+
66
+ Bootstrap the database locally (not possible in Heroku, because the rake task attempts to copy files), and transfer it to Heroku:
67
+
68
+ <pre>
69
+ rake db:bootstrap
70
+ heroku db:push
71
+ </pre>
72
+
73
+ Please note that if you choose to load sample data, images will be missing for all products. Spree's bootstrap task copies the images locally, but it doesn't put them on S3, where this extension configures Spree to look for images.
74
+
75
+ That's it - you're done! :)
76
+
77
+ # Troubleshooting
78
+
79
+ This extension has been tested with Spree 0.10.2. If you have problems using the extension with a newer version of Spree, it could be due to Spree's gem dependencies having changed. The gems in the heroku .gems manifest must mach the gems and versions required by Spree. This page shows the current dependencies of the newest version of Spree: http://gemcutter.org/gems/spree
80
+
81
+ # Copyright and license
82
+
83
+ Copyright (c) 2009 Casper Fabricius, released under the MIT license
84
+
85
+ Contributors:
86
+
87
+ * Pavel Chipiga
88
+ * Andrey Voronkov
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,54 @@
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
@@ -0,0 +1,11 @@
1
+ common: &common
2
+ access_key_id: your_access_key
3
+ secret_access_key: secret_access_key
4
+
5
+ development:
6
+ bucket: spree_development
7
+ <<: *common
8
+
9
+ production:
10
+ bucket: spree_production
11
+ <<: *common
@@ -0,0 +1,3 @@
1
+ module SpreeHeroku
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ module SpreeHeroku
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ console do
5
+ end
6
+
7
+ rake_tasks do
8
+ end
9
+
10
+ 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
18
+ end
19
+
20
+
21
+ config.generators do |g|
22
+ end
23
+
24
+ config.after_initialize do
25
+ config.action_controller.perform_caching = false
26
+ end
27
+
28
+ config.app_middleware do |m|
29
+ end
30
+
31
+ config.before_configuration do
32
+ end
33
+
34
+ config.before_eager_load do
35
+ end
36
+
37
+ config.before_initialize do
38
+ end
39
+
40
+ config.to_prepare do
41
+ end
42
+
43
+ end
44
+ end
45
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,37 @@
1
+ unless defined? SPREE_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["SPREE_ENV_FILE"]
5
+ require ENV["SPREE_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{SPREE_ROOT}/spec/spec_helper"
13
+
14
+ if File.directory?(File.dirname(__FILE__) + "/scenarios")
15
+ Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
16
+ end
17
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
18
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
19
+ end
20
+
21
+ Spec::Runner.configure do |config|
22
+ # config.use_transactional_fixtures = true
23
+ # config.use_instantiated_fixtures = false
24
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
25
+
26
+ # You can declare fixtures for each behaviour like this:
27
+ # describe "...." do
28
+ # fixtures :table_a, :table_b
29
+ #
30
+ # Alternatively, if you prefer to declare them only once, you can
31
+ # do so here, like so ...
32
+ #
33
+ # config.global_fixtures = :table_a, :table_b
34
+ #
35
+ # If you declare global fixtures, be aware that they will be declared
36
+ # for all of your examples, even those that don't use them.
37
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_heroku/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spree_heroku"
7
+ s.version = SpreeHeroku::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Cody Swann"]
10
+ s.email = ["developers@gunnertech.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{This is an extension for Spree, allowing the e-commerce system to run on Heroku - http://heroku.com.}
13
+ s.description = %q{The major constraint on Heroku is that we can't write files to disk, so this extension disables all disk caching, fixes a few issues and changes Spree to store on Amazon S3.}
14
+
15
+ s.rubyforge_project = "spree_heroku"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ Spree::FileUtilz.class_eval do
3
+ class << self
4
+ # Patch mirror_files method to be silent when using r/o Heroku FS
5
+ alias_method :mirror_files_old, :mirror_files
6
+ def mirror_files(source, destination, create_backups = false)
7
+ #return mirror_files_old(source, destination, create_backups) unless Rails.env == 'production'
8
+ mirror_files_old(source, destination, create_backups) rescue true
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_heroku
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Cody Swann
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-25 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: The major constraint on Heroku is that we can't write files to disk, so this extension disables all disk caching, fixes a few issues and changes Spree to store on Amazon S3.
22
+ email:
23
+ - developers@gunnertech.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gems
32
+ - .gitignore
33
+ - Gemfile
34
+ - MIT-LICENSE
35
+ - README.markdown
36
+ - Rakefile
37
+ - app/models/image.rb
38
+ - app/models/taxon.rb
39
+ - aws_s3.yml.example
40
+ - lib/spree_heroku.rb
41
+ - lib/spree_heroku/version.rb
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ - spree_heroku.gemspec
45
+ - vendor/plugins/file_utils_patch/init.rb
46
+ has_rdoc: true
47
+ homepage: ""
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project: spree_heroku
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: This is an extension for Spree, allowing the e-commerce system to run on Heroku - http://heroku.com.
78
+ test_files:
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb