Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails3 #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
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.
File renamed without changes.
129 changes: 20 additions & 109 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,120 +1,31 @@
# I think this is the one that should be moved to the extension Rakefile template

# In rails 1.2, plugins aren't available in the path until they're loaded.
# Check to see if the rspec plugin is installed first and require
# it if it is. If not, use the gem version.

# Determine where the RSpec plugin is by loading the boot
unless defined? SPREE_ROOT
ENV["RAILS_ENV"] = "test"
case
when ENV["SPREE_ENV_FILE"]
require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
else
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
end
end
require File.expand_path('../../config/application', __FILE__)

require 'rubygems'
require 'rake'
require 'rake/rdoctask'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'

rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
require 'spec/rake/spectask'
# require 'spec/translator'

# Cleanup the SPREE_ROOT constant so specs will load the environment
Object.send(:remove_const, :SPREE_ROOT)

extension_root = File.expand_path(File.dirname(__FILE__))

task :default => :spec
task :stats => "spec:statsetup"
spec = eval(File.read('wishlist.gemspec'))

desc "Run all specs in spec directory"
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
t.spec_files = FileList["#{extension_root}/spec/**/*_spec.rb"]
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
end

namespace :spec do
desc "Run all specs in spec directory with RCov"
Spec::Rake::SpecTask.new(:rcov) do |t|
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
t.rcov = true
t.rcov_opts = ['--exclude', 'spec', '--rails']
end

desc "Print Specdoc for all specs"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['spec/**/*_spec.rb']
end

[:models, :controllers, :views, :helpers].each do |sub|
desc "Run the specs under spec/#{sub}"
Spec::Rake::SpecTask.new(sub) do |t|
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
end
end

# Hopefully no one has written their extensions in pre-0.9 style
# desc "Translate specs from pre-0.9 to 0.9 style"
# task :translate do
# translator = ::Spec::Translator.new
# dir = RAILS_ROOT + '/spec'
# translator.translate(dir, dir)
# end

# Setup specs for stats
task :statsetup do
require 'code_statistics'
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
::STATS_DIRECTORIES << %w(View\ specs spec/views)
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
::CodeStatistics::TEST_TYPES << "Model specs"
::CodeStatistics::TEST_TYPES << "View specs"
::CodeStatistics::TEST_TYPES << "Controller specs"
::CodeStatistics::TEST_TYPES << "Helper specs"
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
end

namespace :db do
namespace :fixtures do
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
task :load => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
end
end
end
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 'Generate documentation for the wishlist extension.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'WishlistExtension'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc "Default Task"
task :default => [ :spec ]

# For extensions that are in transition
desc 'Test the wishlist extension.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

# Load any custom rakefiles for extension
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
# require 'cucumber/rake/task'
# Cucumber::Rake::Task.new do |t|
# t.cucumber_opts = %w{--format pretty}
# end
Binary file added app/.DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions app/controllers/wished_products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class WishedProductsController < ApplicationController
class WishedProductsController < Spree::BaseController
resource_controller

# I'm sorry for this hack, but it is simplest way to make adding to wishlist after user logged in,
# because redirect_to can not make POST requests
def index
Expand Down
14 changes: 13 additions & 1 deletion app/controllers/wishlists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class WishlistsController < ApplicationController
class WishlistsController < Spree::BaseController
resource_controller
helper :products

Expand All @@ -11,6 +11,18 @@ class WishlistsController < ApplicationController
render :js => "alert('#{t :updated_successfully}');"
}

def email_to_friend
@wishlist = object
if request.post?
if params[:email].blank?
flash[:error] = t('email_address_missing')
else
WishlistMailer.email_wishlist_to_friend(current_user, @wishlist, params).deliver
flash[:notice] = t('wishlist_email_sent')
redirect_to wishlist_path(@wishlist)
end
end
end
private

def object
Expand Down
11 changes: 11 additions & 0 deletions app/models/wishlist_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class WishlistMailer < ActionMailer::Base
default_url_options[:host] = Spree::Config[:site_url]
default :from => Spree::Config[:mails_from]

def email_wishlist_to_friend(user, wishlist, email)
subject = email[:subject].blank? ? 'Wishlist' : email[:subject]
@mail = email
@wishlist = wishlist
mail(:to => email[:email], :subject => subject)
end
end
2 changes: 1 addition & 1 deletion app/views/products/_wishlist_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="wishlist-form">
<% form_for WishedProduct.new, :html => {:method => :get} do |f| %>
<%= form_for WishedProduct.new, :html => {:method => :get} do |f| %>
<%= f.hidden_field :variant_id, :value => @product.master.id %>
<button type='submit' class='large primary'>
<%= image_tag('/images/add-to-cart.png') + t('add_to_wishlist') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/wishlists/_accessibility.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% form_for @wishlist, :html => {:class => 'ajax_form', :id => 'change_wishlist_accessibility'} do |f| %>
<%= form_for @wishlist, :html => {:class => 'ajax_form', :id => 'change_wishlist_accessibility'} do |f| %>
<%= f.radio_button :is_private, true %>&nbsp;<%= t(:private) %>
<%= f.radio_button :is_private, false %>&nbsp;<%= t(:public) %>
<% end -%>
14 changes: 14 additions & 0 deletions app/views/wishlists/email_to_friend.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1><%= t("email_to_friend") %></h1>
<%= form_tag do %>
<%= label_tag :email, t(:email) %><br />
<%= text_field_tag :email, params[:email] %><br />
<%= label_tag :subject, t(:subject) %><br />
<%= text_field_tag :subject, params[:subject] %><br />
<%= label_tag :wishlist_sender_name, t(:wishlist_sender_name) %><br />
<%= text_field_tag :sender_name, params[:sender_name] %><br />
<%= label_tag :wishlist_recipients_name, t(:wishlist_recipients_name) %><br />
<%= text_field_tag :recipients_name, params[:recipients_name] %><br />
<%= label_tag :message, t(:message) %><br />
<%= text_area_tag :message, params[:message], :rows => 10, :cols => 25 %><br />
<%= submit_tag t(:send_wishlist) %>
<% end -%>
6 changes: 3 additions & 3 deletions app/views/wishlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
<% if @wishlist.user == current_user %>
<td>
<%= link_to t("remove_from_wishlist"), wish, :method => :delete %>
<% form_for :order, :url => orders_url do |f| %>
<%= form_for :order, :url => populate_orders_url do |f| %>
<%= hidden_field_tag "variants[#{variant.id}]", 1, :size => 3 %>
<%= link_to t(:add_to_cart), '#', :onclick => "$(this).parent().submit(); return false;" %>
<% end -%>
<%= t("move_to_another_wishlist") %>:
<% form_for wish do |f| %>
<%= form_for wish do |f| %>
<%= f.select :wishlist_id, current_user.wishlists.map{|wl| [wl.name, wl.id]} %>
<%= f.submit t(:move) %>
<% end -%>
Expand Down Expand Up @@ -72,7 +72,7 @@
<% end -%>
</tbody>
</table>
<% hook :wishlist_footer_links do %>
<%= hook :wishlist_footer_links do %>
<div class='footer_links'>
<% if @wishlist.user == current_user %>
<%= link_to t("create_new_wishlist"), new_wishlist_path %>
Expand Down
35 changes: 35 additions & 0 deletions config/locales/de-CH.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
de-CH:
add_to_wishlist: "Für die Wunschliste"
"Are you sure, that you want to delete this wishlist?": "Sind sie sicher, dass sie diese Wunschliste löschen wollen?"
availability: "Verfügbarkeit"
create_new_wishlist: "Neue Wunschliste erstellen"
creating_wishlist: "Wunschliste erstellen"
date_added: "Hinzugefügt am"
delete_wishlist: "Wunschliste löschen"
edit_wishlist: "Wunschliste ändern"
editing_wishlist: "Ändere Wunschliste"
in_stock: "Verfügbar"
is_default: "ist voreingstellt"
is_private: "ist privat"
item_view: "Bild"
move: "Verschieben"
move_to_another_wishlist: "Verschiebe in"
my_wishlists: "Meine Wuschlisten"
private_wishlist: "Private Wunschlisten"
private: "Privat"
public_wishlist: "Öffentliche Wunschlisten"
public: "Öffentlich"
remove_from_wishlist: "Von Wunschliste entfernen"
wishlist_actions: ""
your_wishlist_is_empty: "Deine Wunschliste ist leer"
update_quantity: "Ändere Menge"
item_added_to_wishlist: "Artikel wurde zur Wunschliste hinzugefügt"
email_to_friend: "Wunschliste an einen Freund verschicken"
wishlist_email_sent: 'Wunschliste wurde an einen Freund versand.'
send_wishlist: Senden
email_address_missing: 'Email ist erforderlich.'
message: Nachricht
wishlist_sender_name: 'Dein Name'
wishlist_recipients_name: 'Name des Freundes'
subject: 'Betreff'
quantity: 'Menge'
35 changes: 35 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
de:
add_to_wishlist: "Für die Wunschliste"
"Are you sure, that you want to delete this wishlist?": "Sind sie sicher, dass sie diese Wunschliste löschen wollen?"
availability: "Verfügbarkeit"
create_new_wishlist: "Neue Wunschliste erstellen"
creating_wishlist: "Wunschliste erstellen"
date_added: "Hinzugefügt am"
delete_wishlist: "Wunschliste löschen"
edit_wishlist: "Wunschliste ändern"
editing_wishlist: "Ändere Wunschliste"
in_stock: "Verfügbar"
is_default: "ist voreingstellt"
is_private: "ist privat"
item_view: "Bild"
move: "Verschieben"
move_to_another_wishlist: "Verschiebe in"
my_wishlists: "Meine Wuschlisten"
private_wishlist: "Private Wunschlisten"
private: "Privat"
public_wishlist: "Öffentliche Wunschlisten"
public: "Öffentlich"
remove_from_wishlist: "Von Wunschliste entfernen"
wishlist_actions: ""
your_wishlist_is_empty: "Deine Wunschliste ist leer"
update_quantity: "Ändere Menge"
item_added_to_wishlist: "Artikel wurde zur Wunschliste hinzugefügt"
email_to_friend: "Wunschliste an einen Freund verschicken"
wishlist_email_sent: 'Wunschliste wurde an einen Freund versand.'
send_wishlist: Senden
email_address_missing: 'Email ist erforderlich.'
message: Nachricht
wishlist_sender_name: 'Dein Name'
wishlist_recipients_name: 'Name des Freundes'
subject: 'Betreff'
quantity: 'Menge'
11 changes: 11 additions & 0 deletions config/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ en:
remove_from_wishlist: "Remove from wishlist"
wishlist_actions: "Actions"
your_wishlist_is_empty: "Your wishlist is empty"
update_quantity: "Update quantity"
item_added_to_wishlist: "Item added to wishlist"
email_to_friend: "Email to a friend"
wishlist_email_sent: 'Your wishlist was successfully sent to your friend.'
send_wishlist: Send
email_address_missing: 'Email is required.'
message: Message
wishlist_sender_name: 'Your name'
wishlist_recipients_name: 'The name of your friend'
subject: 'Subject'

11 changes: 6 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Put your extension routes here.

map.resources :wishlists
map.resources :wished_products
map.default_wishlist '/wishlist', :controller => :wishlists, :action => 'show'
Rails.application.routes.draw do
resources :wishlists
resources :wished_products
match '/wishlist', :controller => :wishlists, :action => 'show', :as => "default_wishlist"
match '/wishlists/email_to_friend/:id', :controller => :wishlists, :action => 'email_to_friend', :as => "email_to_friend"
end
Binary file added lib/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions lib/spree_wishlist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spree_core'
require 'spree_wishlist_hooks'

module SpreeWishlist
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
User.class_eval do
has_many :wishlists

def wishlist
default_wishlist = self.wishlists.first(:conditions => ["is_default = ?", true])
default_wishlist ||= self.wishlists.first
default_wishlist ||= self.wishlists.create(:name => "My wishlist", :is_default => true)
default_wishlist.update_attribute(:is_default, true) unless default_wishlist.is_default?
default_wishlist
end
end

end

config.to_prepare &method(:activate).to_proc
end
end
Loading