Skip to content

Commit

Permalink
Move core controllers+views to frontend; move models to core
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Feb 7, 2013
1 parent 2cc0f62 commit e1e175c
Show file tree
Hide file tree
Showing 1,035 changed files with 622 additions and 318 deletions.
8 changes: 0 additions & 8 deletions common_spree_dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
# gem 'debugger'
end

if Dir.pwd =~ /spree$/
testing_support_path = 'testing_support'
else
testing_support_path = '../testing_support'
end

gem 'spree_testing_support', :path => testing_support_path

gemspec


3 changes: 0 additions & 3 deletions core/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb'))

gem 'spree_models', :path => '../models'
gem 'spree_api', :path => '../api'

gemspec
2 changes: 1 addition & 1 deletion core/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'spree/core/testing_support/common_rake'
require 'spree/testing_support/common_rake'

Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Image < Asset
# we need to look at the write-queue for images which have not been saved yet
after_post_process :find_dimensions

include Spree::Models::S3Support
include Spree::Core::S3Support
supports_s3 :attachment

Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spree/models/validators/email'
require 'spree/core/validators/email'
require 'spree/order/checkout'

module Spree
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Spree
class ShippingMethod < ActiveRecord::Base
include Spree::Models::CalculatedAdjustments
include Spree::Core::CalculatedAdjustments
DISPLAY = [:both, :front_end, :back_end]

default_scope where(:deleted_at => nil)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def validate(record)

module Spree
class TaxRate < ActiveRecord::Base
include Spree::Models::CalculatedAdjustments
include Spree::Core::CalculatedAdjustments
belongs_to :zone, :class_name => "Spree::Zone"
belongs_to :tax_category, :class_name => "Spree::TaxCategory"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Taxon < ActiveRecord::Base
:path => ':rails_root/public/spree/taxons/:id/:style/:basename.:extension',
:default_url => '/assets/default_taxon.png'

include Spree::Models::S3Support
include Spree::Core::S3Support
supports_s3 :icon

include Spree::Models::ProductFilters # for detailed defs of filters
include Spree::Core::ProductFilters # for detailed defs of filters

# indicate which filters should be used for a taxon
# this method should be customized to your own site
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails/generators/rails/app/app_generator"
require 'active_support/core_ext/hash'
require 'spree/models/version'
require 'spree/core/version'

module Spree
class DummyGenerator < Rails::Generators::Base
Expand Down
93 changes: 39 additions & 54 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,48 @@
#++
# Copyright (c) 2007-2013, Spree Commerce, Inc. and other contributors
# All rights reserved.
#
# 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 Spree Commerce, Inc. 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.
#--
require 'rails/all'
require 'rails/generators'
require 'jquery-rails'
require 'deface'
require 'cancan'
require 'select2-rails'
require 'spree/money'
require 'rabl'
require 'state_machine'
require 'paperclip'
require 'kaminari'
require 'awesome_nested_set'
require 'acts_as_list'
require 'active_merchant'
require 'ransack'

require 'spree/models'
module Spree

require 'spree/core/responder'
require 'spree/core/ssl_requirement'
require 'spree/core/store_helpers'
require 'spree/core/mail_settings'
require 'spree/core/mail_interceptor'
require 'spree/core/middleware/redirect_legacy_product_url'
require 'spree/core/middleware/seo_assist'
require 'spree/core/s3_support'
mattr_accessor :user_class

require 'spree/core/version'

require 'spree/core/engine'
require 'generators/spree/dummy/dummy_generator'
def self.user_class
if @@user_class.is_a?(Class)
raise "Spree.user_class MUST be a String object, not a Class object."
elsif @@user_class.is_a?(String)
@@user_class.constantize
end
end

if defined?(ActionView)
require 'awesome_nested_set/helper'
ActionView::Base.class_eval do
include CollectiveIdea::Acts::NestedSet::Helper
# Used to configure Spree.
#
# Example:
#
# Spree.config do |config|
# config.site_name = "An awesome Spree site"
# end
#
# This method is defined within the core gem on purpose.
# Some people may only wish to use the Core part of Spree.
def self.config(&block)
yield(Spree::Config)
end
end

ActiveSupport.on_load(:action_view) do
include Spree::Core::StoreHelpers
require 'spree/core/version'
require 'spree/core/engine'

require 'spree/core/delegate_belongs_to'
require 'spree/core/ext/active_record'
require 'spree/core/permalinks'
require 'spree/core/token_resource'
require 'spree/core/calculated_adjustments'

ActiveRecord::Base.class_eval do
include CollectiveIdea::Acts::NestedSet
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
module CalculatedAdjustments
def self.included(klass)
klass.class_eval do
Expand Down
File renamed without changes.
60 changes: 33 additions & 27 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'rabl'

module Spree
def self.table_name_prefix
"spree_"
end

module Core
class Engine < ::Rails::Engine
isolate_namespace Spree
engine_name 'spree'

config.middleware.use "Spree::Core::Middleware::SeoAssist"
config.middleware.use "Spree::Core::Middleware::RedirectLegacyProductUrl"
engine_name 'spree_core'

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

Expand All @@ -26,34 +26,40 @@ class Engine < ::Rails::Engine
end
end

# We need to reload the routes here due to how Spree sets them up.
# The different facets of Spree (auth, promo, etc.) append/prepend routes to Core
# *after* Core has been loaded.
#
# So we wait until after initialization is complete to do one final reload.
# This then makes the appended/prepended routes available to the application.
config.after_initialize do
Rails.application.routes_reloader.reload!
initializer "spree.environment", :before => :load_config_initializers do |app|
app.config.spree = Spree::Core::Environment.new
Spree::Config = app.config.spree.preferences #legacy access
end

# filter sensitive information during logging
initializer "spree.params.filter" do |app|
app.config.filter_parameters += [:password, :password_confirmation, :number]
initializer "spree.load_preferences", :before => "spree.environment" do
::ActiveRecord::Base.send :include, Spree::Preferences::Preferable
end

# sets the manifests / assets to be precompiled, even when initialize_on_precompile is false
initializer "spree.assets.precompile", :group => :all do |app|
app.config.assets.precompile += %w[
store/all.*
admin/all.*
admin/orders/edit_form.js
admin/address_states.js
jqPlot/excanvas.min.js
admin/images/new.js
jquery.jstree/themes/apple/*
]
initializer "spree.register.calculators" do |app|
app.config.spree.calculators.shipping_methods = [
Spree::Calculator::FlatPercentItemTotal,
Spree::Calculator::FlatRate,
Spree::Calculator::FlexiRate,
Spree::Calculator::PerItem,
Spree::Calculator::PriceSack]

app.config.spree.calculators.tax_rates = [
Spree::Calculator::DefaultTax]
end

initializer "spree.register.payment_methods" do |app|
app.config.spree.payment_methods = [
Spree::Gateway::Bogus,
Spree::Gateway::BogusSimple,
Spree::PaymentMethod::Check ]
end

initializer "spree.mail.settings" do |app|
if Spree::MailMethod.table_exists?
Spree::Core::MailSettings.init
Mail.register_interceptor(Spree::Core::MailInterceptor)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
class Environment
include EnvironmentExtension

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
class Environment
class Calculators
include EnvironmentExtension
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
module EnvironmentExtension
extend ActiveSupport::Concern

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
class GatewayError < RuntimeError; end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# See http://railscasts.com/episodes/206-action-mailer-in-rails-3 for more details.
module Spree
module Models
module Core
class MailInterceptor

def self.delivering_email(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
module MailSettings

# Override the Rails application mail settings based on preference.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'stringex'

module Spree
module Models
module Core
module Permalinks
extend ActiveSupport::Concern

Expand Down Expand Up @@ -55,5 +55,5 @@ def save_permalink(permalink_value=self.to_param)
end
end

ActiveRecord::Base.send :include, Spree::Models::Permalinks
ActiveRecord::Relation.send :include, Spree::Models::Permalinks
ActiveRecord::Base.send :include, Spree::Core::Permalinks
ActiveRecord::Relation.send :include, Spree::Core::Permalinks
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
# THIS FILE SHOULD BE OVER-RIDDEN IN YOUR SITE EXTENSION!
# the exact code probably won't be useful, though you're welcome to modify and reuse
# the current contents are mainly for testing and documentation
Expand Down Expand Up @@ -57,7 +57,7 @@ module ProductFilters
# below scope would be something like ["$10 - $15", "$15 - $18", "$18 - $20"]
#
Spree::Product.add_search_scope :price_range_any do |*opts|
conds = opts.map {|o| Spree::Models::ProductFilters.price_filter[:conds][o]}.reject {|c| c.nil?}
conds = opts.map {|o| Spree::Core::ProductFilters.price_filter[:conds][o]}.reject {|c| c.nil?}
scope = conds.shift
conds.each do |new_scope|
scope = scope.or(new_scope)
Expand Down Expand Up @@ -172,7 +172,7 @@ def ProductFilters.selective_brand_filter(taxon = nil)
# This scope selects products in any of the active taxons or their children.
#
def ProductFilters.taxons_below(taxon)
return Spree::Models::ProductFilters.all_taxons if taxon.nil?
return Spree::Core::ProductFilters.all_taxons if taxon.nil?
{ :name => "Taxons under " + taxon.name,
:scope => :taxons_id_in_tree_any,
:labels => taxon.children.sort_by(&:position).map {|t| [t.name, t.id]},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
# This module exists to reduce duplication in S3 settings between
# the Image and Taxon models in Spree
module S3Support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
module Models
module Core
module TokenResource
module ClassMethods
def token_resource
Expand All @@ -23,5 +23,5 @@ def self.included(receiver)
end
end

ActiveRecord::Base.class_eval { include Spree::Models::TokenResource }
ActiveRecord::Base.class_eval { include Spree::Core::TokenResource }

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Its pretty difficult to test this module in isolation b/c it needs to work in conjunction with an actual class that
# extends ActiveRecord::Base and has a corresponding table in the database. So we'll just test it using Order and
# ShippingMethod instead since those classes are including the module.
describe Spree::Models::CalculatedAdjustments do
describe Spree::Core::CalculatedAdjustments do

let(:calculator) { mock_model(Spree::Calculator, :compute => 10, :[]= => nil) }

Expand Down
Loading

0 comments on commit e1e175c

Please sign in to comment.