Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
markalinn committed Oct 5, 2011
0 parents commit 177dc00
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\#*
*~
.#*
.DS_Store
.idea
.project
tmp
nbproject
*.swp
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Rails Dog LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SpreeCartToggle
===============

Introduction goes here.


Example
=======

Example goes here.


Copyright (c) 2011 [name of extension creator], released under the New BSD License
75 changes: 75 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'

gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
require 'bundler'
ENV['BUNDLE_GEMFILE'] = gemfile
Bundler.setup

require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

require 'cucumber/rake/task'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format progress}
end
end

desc "Default Task"
task :default => [:spec, :cucumber ]

spec = eval(File.read('spree_cart_toggle.gemspec'))

Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end

desc "Default Task"
task :default => [ :spec ]

desc "Regenerates a rails 3 app for testing"
task :test_app do
require '../spree/lib/generators/spree/test_app_generator'
class SpreeCartToggleTestAppGenerator < Spree::Generators::TestAppGenerator

def install_gems
inside "test_app" do
run 'rake spree_core:install'
run 'rake spree_cart_toggle:install'
end
end

def migrate_db
run_migrations
end

protected
def full_path_for_local_gems
<<-gems
gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
gem 'spree_cart_toggle', :path => \'#{File.dirname(__FILE__)}\'
gems
end

end
SpreeCartToggleTestAppGenerator.start
end

namespace :test_app do
desc 'Rebuild test and cucumber databases'
task :rebuild_dbs do
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
end
end
9 changes: 9 additions & 0 deletions Versionfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file is used to designate compatibilty with different versions of Spree
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details

# Examples
#
# "0.50.x" => { :branch => "master" }
# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }


46 changes: 46 additions & 0 deletions app/views/admin/general_settings/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t('edit_general_settings') %></h1>

<%= form_tag(admin_general_settings_path, :method => :put) do %>
<p>
<label><%= t("site_name") %></label>
<%= text_field_tag('preferences[site_name]', Spree::Config[:site_name]) %>
</p>
<p>
<label><%= t("default_seo_title") %></label>
<%= text_field_tag('preferences[default_seo_title]', Spree::Config[:default_seo_title]) %>
</p>
<p>
<label><%= t('site_url') %></label>
<%= text_field_tag('preferences[site_url]', Spree::Config[:site_url])%>
</p>
<p>
<label>
<input name="preferences[allow_ssl_in_production]" type="hidden" value="0" />
<%= check_box_tag('preferences[allow_ssl_in_production]', "1", Spree::Config[:allow_ssl_in_production]) %>
<%= t('allow_ssl_to_be_used_when_in_production_mode') %>
</label>
</p>

<p>
<label>
<input name="preferences[allow_ssl_in_development_and_test]" type="hidden" value="0" />
<%= check_box_tag('preferences[allow_ssl_in_development_and_test]', "1", Spree::Config[:allow_ssl_in_development_and_test]) %>
<%= t('allow_ssl_to_be_used_when_in_developement_and_test_modes') %>
</label>
</p>

<p>
<label>
<input name="preferences[cart_enabled]" type="hidden" value="0" />
<%= check_box_tag('preferences[cart_enabled]', "1", Spree::Config[:cart_enabled] == "1") %>
<%= t('cart_enabled') %>
</label>
</p>

<p class="form-buttons">
<%= button t('update') %>
<%= t("or") %> <%= link_to t("cancel"), admin_general_settings_url %>
</p>
<% end %>
37 changes: 37 additions & 0 deletions app/views/admin/general_settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t("general_settings") %></h1>

<table>
<tr>
<th scope="row"><%= t("site_name") %>:</th>
<td><%= Spree::Config[:site_name] %></td>
</tr>
<tr>
<th scope="row"><%= t("default_seo_title") %>:</th>
<td><%= Spree::Config[:default_seo_title] %></td>
</tr>
<tr>
<th scope="row"><%= t("site_url") %>:</th>
<td><%= Spree::Config[:site_url] %></td>
</tr>
<tr>
<td colspan="2">
<%= (Spree::Config[:allow_ssl_in_production] ? t("ssl_will_be_used_in_production_mode") : t("ssl_will_not_be_used_in_production_mode")) %>
</td>
</tr>
<tr>
<td colspan="2">
<%= (Spree::Config[:allow_ssl_in_development_and_test] ? t("ssl_will_be_used_in_development_and_test_modes") : t("ssl_will_not_be_used_in_development_and_test_modes")) %>
</td>
</tr>
<tr>
<td colspan="2">
<%= (Spree::Config[:cart_enabled] == "1" ? t("cart_enabled") : t("cart_disabled")) %>
</td>
</tr>
</table>

<p><%= link_to_with_icon 'edit', t("edit"), edit_admin_general_settings_path, :id => 'admin_general_settings_link' %></p>


56 changes: 56 additions & 0 deletions app/views/products/_cart_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<%= form_for :order, :url => populate_orders_url do |f| %>
<%= hook :inside_product_cart_form do %>

<% if product_price(@product) %>
<%= hook :product_price do %>
<p class="prices">
<%= t("price") %>
<br />
<span class="price selling"><%= product_price(@product) %></span>
</p>
<% end %>
<% end %>

<% if @product.has_variants? %>
<div id="product-variants">
<h2><%= t('variants') %></h2>
<ul>
<% has_checked = false
@product.variants.active.each_with_index do |v,index|
next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
has_checked = true if checked %>
<li>
<label>
<%= radio_button_tag "products[#{@product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %>
<span class="variant-description">
<%= variant_options v %>
</span>
<% if variant_price_diff v %>
<span class="price diff"><%= variant_price_diff v %></span>
<% end %>
</label>
</li>
<% end%>
</ul>
</div>
<% end%>
<% if @product.has_stock? || Spree::Config[:allow_backorders] %>
<% if Spree::Config[:allow_backorders] =="1" %>
<%= text_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"),
1, :class => "title", :size => 3 %>
&nbsp;
<button type='submit' class='large primary'>
<%= image_tag('/images/add-to-cart.png') + t('add_to_cart') %>
</button>
<% end %>
<% else %>
<%= content_tag('strong', t('out_of_stock')) %>
<% end %>

<% end %>
<% end %>

<% content_for :head do %>
<%= javascript_include_tag 'product' %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/shared/_store_menu.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<li><%= link_to t("home") , root_path %></li>
<% if Spree::Config[:allow_backorders] =="1" %>
<li class="cart-indicator"><%= link_to_cart %></li>
<% end %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rails.application.routes.draw do
# Add your extension routes here
end
17 changes: 17 additions & 0 deletions lib/spree_cart_toggle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spree_core'
require 'spree_cart_toggle_hooks'

module SpreeCartToggle
class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
end

config.to_prepare &method(:activate).to_proc
end
end
3 changes: 3 additions & 0 deletions lib/spree_cart_toggle_hooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SpreeCartToggleHooks < Spree::ThemeSupport::HookListener
# custom hooks go here
end
25 changes: 25 additions & 0 deletions lib/tasks/install.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace :spree_cart_toggle do
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
task :install do
Rake::Task['spree_cart_toggle:install:migrations'].invoke
Rake::Task['spree_cart_toggle:install:assets'].invoke
end

namespace :install do
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
task :migrations do
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
destination = File.join(Rails.root, 'db')
Spree::FileUtilz.mirror_files(source, destination)
end

desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
task :assets do
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
destination = File.join(Rails.root, 'public')
puts "INFO: Mirroring assets from #{source} to #{destination}"
Spree::FileUtilz.mirror_files(source, destination)
end
end

end
1 change: 1 addition & 0 deletions lib/tasks/spree_cart_toggle.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# add custom rake tasks here
30 changes: 30 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../test_app/config/environment", __FILE__)
require 'rspec/rails'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

config.fixture_path = "#{::Rails.root}/spec/fixtures"

#config.include Devise::TestHelpers, :type => :controller
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end

@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
20 changes: 20 additions & 0 deletions spree_cart_toggle.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_cart_toggle'
s.version = '0.60.0'
s.summary = 'Spree Cart On/Off'
s.description = 'Addition to Spree general settings to disable cart and add buttons'
s.required_ruby_version = '>= 1.8.7'

s.author = 'Mark Linn'
s.email = '[email protected]'
# s.homepage = 'http://www.rubyonrails.org'
# s.rubyforge_project = 'actionmailer'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency('spree_core', '>= 0.60.0')
end

0 comments on commit 177dc00

Please sign in to comment.