From 42a37524004c92b1b0288bb5403f57bd855834c0 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Sun, 2 Nov 2008 22:51:40 +0100 Subject: [PATCH] Consolidation of work on slicefiying application with original app * This should get us to a point where we have a slice named MerbMart. We still need to do a fair amount of work to clean things up to get stuff working properly. Squashed commit of the following: commit 9b19f8b36148cdd0a266136fa522851a8a966d12 Author: Alex Coles Date: Sun Nov 2 22:48:21 2008 +0100 Normalize name of slice. Further consolidation of slice-attempt. * Cleanup naming conventions: MerbMart and merb_mart * Adding init.rb and router.rb files to allow for standalone running. commit b6257d682e71eb695f61561fe8f17453c20e77ce Author: Alex Coles Date: Sun Nov 2 22:33:40 2008 +0100 Re-removing incompatible license commit 137a488f76b17e4889eaec239b06d2855da47f00 Author: Alex Coles Date: Sun Nov 2 22:32:51 2008 +0100 Revert "Renaming project to Merb eMart" This reverts commit ec3649debc6349ee6e4e685c0578211147e8e639. Conflicts: README.markdown Rakefile commit eddc44217b247531ef20226ae4d5a20f2a0d8b53 Author: Alex Coles Date: Sun Nov 2 22:18:34 2008 +0100 Consolidation of attempt to slicify app. * Removing model classes that overlap between Ben's sliceified app, and the original monolithic app. * Updated and added in slice code to make it look like, and work as a merb 0.9.12 slice. * Some renaming of directories/files to account for rename back to merb_mart/MerbMart. --- INSTALL | 30 ++-- README | 6 +- README.markdown | 44 +++--- Rakefile | 93 +++++++----- TODO | 11 +- app/controllers/application.rb | 2 +- app/controllers/products.rb | 2 +- app/helpers/application_helper.rb | 8 +- app/models/abstract_upload.rb | 29 ---- app/models/address.rb | 1 - app/models/asset.rb | 5 - app/models/country.rb | 1 - app/models/orders/line_item.rb | 21 --- app/models/orders/status_code.rb | 14 -- app/models/store/product.rb | 21 --- app/models/store/product_image.rb | 16 --- app/models/tag.rb | 20 --- .../{merb_e_mart.html.erb => merb_mart.html.erb} | 8 +- config/init.rb | 43 ++++++ config/router.rb | 3 + examples/quick-E-mart/config/init.rb | 2 +- examples/quick-E-mart/config/router.rb | 2 +- lib/merb-E-mart.rb | 73 ---------- lib/merb-E-mart/exceptions/mixin_missing.rb | 7 - lib/merb-E-mart/merbtasks.rb | 159 --------------------- lib/merb-e-mart.rb | 6 - lib/merb_mart.rb | 91 ++++++++++++ lib/merb_mart/merbtasks.rb | 103 +++++++++++++ lib/merb_mart/slicetasks.rb | 18 +++ lib/merb_mart/spectasks.rb | 65 +++++++++ .../upload_processor/static_file_processor.rb | 2 +- spec/merb-E-mart_spec.rb | 80 ----------- spec/merb_mart_spec.rb | 88 ++++++++++++ spec/spec_helper.rb | 12 +- stubs/app/controllers/application.rb | 2 + stubs/app/controllers/main.rb | 2 + 36 files changed, 535 insertions(+), 555 deletions(-) rewrite Rakefile (82%) delete mode 100644 app/models/abstract_upload.rb delete mode 100644 app/models/asset.rb delete mode 100644 app/models/orders/line_item.rb delete mode 100644 app/models/orders/status_code.rb delete mode 100644 app/models/store/product.rb delete mode 100644 app/models/store/product_image.rb delete mode 100644 app/models/tag.rb rename app/views/layout/{merb_e_mart.html.erb => merb_mart.html.erb} (75%) create mode 100644 config/init.rb create mode 100644 config/router.rb delete mode 100644 lib/merb-E-mart.rb delete mode 100644 lib/merb-E-mart/exceptions/mixin_missing.rb delete mode 100644 lib/merb-E-mart/merbtasks.rb delete mode 100644 lib/merb-e-mart.rb create mode 100644 lib/merb_mart.rb create mode 100644 lib/merb_mart/merbtasks.rb create mode 100644 lib/merb_mart/slicetasks.rb create mode 100644 lib/merb_mart/spectasks.rb rename lib/{merb-E-mart => merb_mart}/upload_processor/static_file_processor.rb (87%) delete mode 100644 spec/merb-E-mart_spec.rb create mode 100644 spec/merb_mart_spec.rb create mode 100644 stubs/app/controllers/application.rb create mode 100644 stubs/app/controllers/main.rb diff --git a/INSTALL b/INSTALL index 0153e6b..0a5d082 100644 --- a/INSTALL +++ b/INSTALL @@ -7,11 +7,11 @@ file: config/init.rb # add the slice as a regular dependency -dependency 'merb-E-mart' +dependency 'merb_mart' # if needed, configure which slices to load and in which order -Merb::Plugins.config[:merb_slices] = { :queue => ["MerbEMart", ...] } +Merb::Plugins.config[:merb_slices] = { :queue => ["MerbMart", ...] } # optionally configure the plugins in a before_app_loads callback @@ -23,21 +23,21 @@ end file: config/router.rb -# example: /merb-E-mart/:controller/:action/:id +# example: /merb_mart/:controller/:action/:id -r.add_slice(:MerbEMart) +r.add_slice(:MerbMart) # example: /foo/:controller/:action/:id -r.add_slice(:MerbEMart, 'foo') # same as :path => 'foo' +r.add_slice(:MerbMart, 'foo') # same as :path => 'foo' # example: /:lang/:controller/:action/:id (with :a param set) -r.add_slice(:MerbEMart, :path => ':lang', :params => { :a => 'b' }) +r.add_slice(:MerbMart, :path => ':lang', :params => { :a => 'b' }) # example: /:controller/:action/:id -r.slice(:MerbEMart) +r.slice(:MerbMart) Normally you should also run the following rake task: @@ -47,23 +47,23 @@ rake slices:merb_E_mart:install You can put your application-level overrides in: -host-app/slices/merb-E-mart/app - controllers, models, views ... +host-app/slices/merb_mart/app - controllers, models, views ... Templates are located in this order: -1. host-app/slices/merb-E-mart/app/views/* -2. gems/merb-E-mart/app/views/* +1. host-app/slices/merb_mart/app/views/* +2. gems/merb_mart/app/views/* 3. host-app/app/views/* You can use the host application's layout by configuring the -merb-E-mart slice in a before_app_loads block: +merb_mart slice in a before_app_loads block: Merb::Slices.config[:merb_E_mart] = { :layout => :application } By default :merb_E_mart is used. If you need to override stylesheets or javascripts, just specify your own files in your layout instead/in addition to the ones supplied (if any) in -host-app/public/slices/merb-E-mart. +host-app/public/slices/merb_mart. In any case don't edit those files directly as they may be clobbered any time rake merb_E_mart:install is run. @@ -71,11 +71,11 @@ rake merb_E_mart:install is run. Dependencies ------------ -Merb eMart master branch is being built on the cutting-edge Merb framework, and +MerbMart master branch is being built on the cutting-edge Merb framework, and the bleeding edge DataMapper framework. As such, you'll have to get yourself -setup with those gems before you get the chance to play with Merb eMart. +setup with those gems before you get the chance to play with MerbMart. -Dependencies for Merb eMart: +Dependencies for MerbMart: * **DataMapper 0.9** - 'edge' development * *DataObjects* diff --git a/README b/README index 1437005..271d387 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ -MerbEMart -========= +MerbMart +======== -Merb eMart is an *open-source e-commerce engine* slice for the Merb framework. +MerbMart is an *open-source e-commerce engine* slice for the Merb framework. Please see README.markdown. diff --git a/README.markdown b/README.markdown index 6924b2d..21042ec 100644 --- a/README.markdown +++ b/README.markdown @@ -1,7 +1,7 @@ -Merb eMart README -================= +MerbMart README +=============== -Merb eMart is an *open-source e-commerce engine*, developed on top of the recent +MerbMart is an *open-source e-commerce engine*, developed on top of the recent Ruby-language, Merb MVC framework. It takes advantage of the Merb's slices plugin, allowing you to incorporate the engine into a customized e-commerce solution. @@ -11,11 +11,11 @@ Performance _Mom and Pop?.. or Big Box?_ -A key goal for the Merb eMart engine is performance. Although Merb eMart is -designed for e-commerce sites of all sizes, the speed and scalability of the +A key goal for the MerbMart engine is performance. Although MerbMart is +designed for e-commerce sites of all sizes, the speed and scalability of the Merb and DataMapper frameworks make it scalable even for large online vendors. -The following technologies and frameworks provide a foundation for Merb eMart: +The following technologies and frameworks provide a foundation for MerbMart: * **Merb**, for Model-View-Controller. * **DataMapper**, for object relation mapping (ORM) and persistence. @@ -25,9 +25,9 @@ The following technologies and frameworks provide a foundation for Merb eMart: See INSTALL or the project wiki for a full list of dependencies. -Merb eMart is inspired by other, Rails based e-commerce applications, including -[Substruct][substruct] and [Spree][spree]. Although Merb eMart started out as a -project to port Substruct to Merb, the initial 0.1 release of Merb eMart will +MerbMart is inspired by other, Rails based e-commerce applications, including +[Substruct][substruct] and [Spree][spree]. Although MerbMart started out as a +project to port Substruct to Merb, the initial 0.1 release of MerbMart will instead be a its own implementation of an e-commerce engine, trying to match the feature sets other e-commerce applications, but taking advantages of the unique features of Merb and DataMapper. @@ -70,21 +70,21 @@ Please see the INSTALL file for details on getting up and running with Merb eMar Developer Notes --------------- -**WARNING** : Merb eMart is at a very early development stages. At this stage, +**WARNING** : MerbMart is at a very early development stages. At this stage, the application should be considered only for consumption by advanced Ruby and Merb developers. If you're looking for something for production consumption, -or not yet ready to jump from Ruby on Rails, then we would strongly advise +or not yet ready to jump from Ruby on Rails, then we would strongly advise trying [Substruct][substruct] or [Spree][spree]. -**REQUEST** : Your development support is very much appreciated. Please -contact us below if you're interested in lending a hand with the development +**REQUEST** : Your development support is very much appreciated. Please +contact us below if you're interested in lending a hand with the development of this project. Or alternatively, clone the code, fork it, create some patches and let us know when you're done. Getting the Source ------------------ -Performing a git clone on either of the following repositories will get you +Performing a git clone on either of the following repositories will get you the latest source: git clone git://github.com/myabc/merb_mart.git @@ -98,7 +98,7 @@ The following additional mirrors are available: Copyright and License --------------------- -Merb eMart is licensed under the **GNU Public License (GPL)**: +MerbMart is licensed under the **GNU Public License (GPL)**: > Copyright (C) 2008 Alex Coles @@ -121,20 +121,20 @@ the distribution. Support ------- -**WARNING REPEATED** : Merb eMart is still at a very early stage of its -development. You should not use this code unless you're reasonably secure with -the Ruby language, and the DataMapper and Merb frameworks. That said, _please -do get involved_ - and if you're happy to contribute back with bug reports and +**WARNING REPEATED** : MerbMart is still at a very early stage of its +development. You should not use this code unless you're reasonably secure with +the Ruby language, and the DataMapper and Merb frameworks. That said, _please +do get involved_ - and if you're happy to contribute back with bug reports and patches, then we'll be happy to help you get the application up and running. Your best source for support currently is either the wiki, IRC or the mailing list: - * **Merb eMart Wiki** (this is its temporary residence): + * **MerbMart Wiki** (this is its temporary residence): http://github.com/myabc/merb_mart/wikis - * **Merb eMart mailing list**: + * **MerbMart mailing list**: - * **Merb eMart homepage**: _coming soon_ + * **MerbMart homepage**: _coming soon_ * Contact the developers directly: - | myabc on #datamapper, #merb IRC diff --git a/Rakefile b/Rakefile dissimilarity index 82% index b21597c..88dd54a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,38 +1,55 @@ -require 'rake/gempackagetask' -require 'spec/rake/spectask' -require 'merb-core/version' -require 'merb-core/test/tasks/spectasks' - -spec = Gem::Specification.new do |s| - s.name = 'merb_e_mart' - s.version = '0.0.1' - s.platform = Gem::Platform::RUBY - s.has_rdoc = true - s.extra_rdoc_files = ["README.markdown", "GPL-LICENSE", 'TODO'] - s.summary = 'An open-source e-commerce engine slice for the Merb framework' - s.description = s.summary - s.author = 'Alex Coles' - s.email = 'alex@alexcolesportfolio.com' - s.homepage = 'http://github.com/myabc/merb_mart/tree/master' - s.require_path = 'lib' - s.files = %w(GPL-LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec,app,public}/**/*") - s.add_dependency('merb-slices', '>= 0.9.4') -end - -Rake::GemPackageTask.new(spec) do |pkg| - pkg.gem_spec = spec -end - -desc "Install MerbEMart as a gem" -task :install => [:package] do - sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources --local} -end - -namespace :jruby do - - desc "Run :package and install the resulting .gem with jruby" - task :install => :package do - sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{VERSION}.gem --no-rdoc --no-ri} - end - -end +require 'rubygems' +require 'rake/gempackagetask' + +require 'merb-core' +require 'merb-core/tasks/merb' + +GEM_NAME = "merb_mart" +AUTHOR = "Alex Coles" +EMAIL = "alex@alexcolesportfolio.com" +HOMEPAGE = "http://github.com/myabc/merb_mart/tree/master" +SUMMARY = "An open-source e-commerce engine slice for the Merb framework'" +GEM_VERSION = "0.9.12" + +spec = Gem::Specification.new do |s| + s.rubyforge_project = 'merb' + s.name = GEM_NAME + s.version = GEM_VERSION + s.platform = Gem::Platform::RUBY + s.has_rdoc = true + s.extra_rdoc_files = ["README.markdown", "GPL-LICENSE", 'TODO'] + s.summary = SUMMARY + s.description = s.summary + s.author = AUTHOR + s.email = EMAIL + s.homepage = HOMEPAGE + s.add_dependency('merb-slices', '>= 0.9.12') + s.require_path = 'lib' + s.files = %w(GPL-LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*") +end + +Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec +end + +desc "Install the gem" +task :install do + Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION) +end + +desc "Uninstall the gem" +task :uninstall do + Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION) +end + +desc "Create a gemspec file" +task :gemspec do + File.open("#{GEM_NAME}.gemspec", "w") do |file| + file.puts spec.to_ruby + end +end + +require 'spec/rake/spectask' +require 'merb-core/test/tasks/spectasks' +desc 'Default: run spec examples' +task :default => 'spec' diff --git a/TODO b/TODO index e717fa2..dcd2903 100644 --- a/TODO +++ b/TODO @@ -1,14 +1,15 @@ TODO: -- Fix MerbEMart.description and MerbEMart.version +- Fix MerbMart.description and MerbMart.version - Fix LICENSE with your name - Fix Rakefile with your name and contact info -- Add your code to lib/merb_e_mart.rb -- Add your Merb rake tasks to lib/merb_e_mart/merbtasks.rb +- Add your code to lib/merb_mart.rb +- Add your Merb rake tasks to lib/merb_mart/merbtasks.rb Remove anything that you don't need: -- app/controllers/main.rb MerbEMart::Main controller -- app/views/layout/merb_e_mart.html.erb +- app/controllers/main.rb MerbMart::Main controller +- app/views/layout/merb_mart.html.erb - spec/controllers/main_spec.rb controller specs - public/* any public files +- stubs/* any stub files diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 49347c9..f7dd7ed 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -1,4 +1,4 @@ -class MerbEMart::Application < Merb::Controller +class MerbMart::Application < Merb::Controller controller_for_slice diff --git a/app/controllers/products.rb b/app/controllers/products.rb index cdeb3e6..4ca1c45 100644 --- a/app/controllers/products.rb +++ b/app/controllers/products.rb @@ -1,4 +1,4 @@ -class MerbEMart::Products < MerbEMart::Application +class MerbMart::Products < MerbMart::Application def index @products = Product.all diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0f152f1..8b65af3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module Merb - module MerbEMart + module MerbMart module ApplicationHelper # @param *segments Path segments to append. @@ -34,7 +34,7 @@ module Merb # @return # A path relative to the public directory, with added segments. def public_path_for(type, *segments) - File.join(::MerbEMart.public_dir_for(type), *segments) + ::MerbMart.public_path_for(type, *segments) end # Construct an app-level path. @@ -45,7 +45,7 @@ module Merb # @return # A path within the host application, with added segments. def app_path_for(type, *segments) - File.join(::MerbEMart.app_dir_for(type), *segments) + ::MerbMart.app_path_for(type, *segments) end # Construct a slice-level path. @@ -56,7 +56,7 @@ module Merb # @return # A path within the slice source (Gem), with added segments. def slice_path_for(type, *segments) - File.join(::MerbEMart.dir_for(type), *segments) + ::MerbMart.slice_path_for(type, *segments) end end diff --git a/app/models/abstract_upload.rb b/app/models/abstract_upload.rb deleted file mode 100644 index d50da4f..0000000 --- a/app/models/abstract_upload.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'dm-validations' - -module Mart - class AbstractUpload - - include DataMapper::Resource - - property :id, Integer, :serial => true - property :filename, String - property :created_on, DateTime - property :content_type, String - property :thumbnail, String - property :size, Integer - property :type, Class # single-table inheritance - - def filename_base - filename.split('.').first - end - - def extension - filename.split('.').last - end - - def relative_path - filename # TODO - end - - end -end diff --git a/app/models/address.rb b/app/models/address.rb index 2ab7918..9b5be52 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -28,5 +28,4 @@ class Address def name "#{self.first_name} #{self.last_name}" end - end diff --git a/app/models/asset.rb b/app/models/asset.rb deleted file mode 100644 index fd97043..0000000 --- a/app/models/asset.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Mart - class Asset < AbstractUpload - - end -end diff --git a/app/models/country.rb b/app/models/country.rb index 2e11f72..45eda31 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -11,5 +11,4 @@ class Country has n, :states alias :provinces :states - end diff --git a/app/models/orders/line_item.rb b/app/models/orders/line_item.rb deleted file mode 100644 index 23af928..0000000 --- a/app/models/orders/line_item.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "bigdecimal" - -module Mart - module Orders - class LineItem - - include DataMapper::Resource - - property :id, Integer, :serial => true - property :quantity, Integer, :default => 0, :nullable => false - property :unit_price, BigDecimal, :default => 0.0, :nullable => false - property :name, String - property :product_id, Integer ## FIXME: should not be both product_id + store_item_id - property :store_item_id, Integer # foreign-key - - belongs_to :product ## FIXME: should not be both product_id + store_item_id - belongs_to :store_item - - end - end -end diff --git a/app/models/orders/status_code.rb b/app/models/orders/status_code.rb deleted file mode 100644 index 4384c18..0000000 --- a/app/models/orders/status_code.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Mart - module Orders - class StatusCode - - include DataMapper::Resource - - property :id, Integer, :serial => true - property :name, String, :length => 30, :nullable => false - - has n, :orders - - end - end -end diff --git a/app/models/store/product.rb b/app/models/store/product.rb deleted file mode 100644 index 240b0f9..0000000 --- a/app/models/store/product.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Mart - module Store - class Product < AbstractItem - - #has n, {:images => :product_images}, - # :class_name => 'Mart::Store::ProductImage'#, - #:order => :rank.desc - - has n, :variations, :order => [:name.asc] - - #many_to_many :related_products, - # :class_name => 'Product' #, - #:join_table => 'related_products', - #:association_foreign_key => 'related_id', - #:foreign_key => 'product_id' - - #many_to_many :tags - - end - end -end diff --git a/app/models/store/product_image.rb b/app/models/store/product_image.rb deleted file mode 100644 index 16a7abf..0000000 --- a/app/models/store/product_image.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Mart - module Store - class ProductImage - - include DataMapper::Resource - - property :product_id, Integer # foreign-key - property :image_id, Integer # foreign-key - property :rank, Integer - - belongs_to :product, :class_name => 'Mart::Store::Product' - belongs_to :image, :class_name => 'Mart::Image' - - end - end -end diff --git a/app/models/tag.rb b/app/models/tag.rb deleted file mode 100644 index 3b19c36..0000000 --- a/app/models/tag.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'dm-validations' -# -# A free-form, flat taxonomoy. -# -class Tag - - include DataMapper::Resource - - property :id, Integer, :serial => true - property :name, String, :length => 100, :nullable => false, :key => :unique - property :rank, Integer - - validates_present :name - validates_is_unique :rank - - def self.all_ordered - all(:order => [ :name.asc ]) - end - -end diff --git a/app/views/layout/merb_e_mart.html.erb b/app/views/layout/merb_mart.html.erb similarity index 75% rename from app/views/layout/merb_e_mart.html.erb rename to app/views/layout/merb_mart.html.erb index 7ada2b3..000b1b7 100644 --- a/app/views/layout/merb_e_mart.html.erb +++ b/app/views/layout/merb_mart.html.erb @@ -2,14 +2,14 @@ - Fresh MerbEMart Slice + Fresh MerbMart Slice - - + +
-

MerbEMart Slice

+

MerbMart Slice

<%= catch_content :for_layout %>
diff --git a/config/init.rb b/config/init.rb new file mode 100644 index 0000000..4d23458 --- /dev/null +++ b/config/init.rb @@ -0,0 +1,43 @@ +# +# ==== Standalone MerbMart configuration +# +# This configuration/environment file is only loaded by bin/slice, which can be +# used during development of the slice. It has no effect on this slice being +# loaded in a host application. To run your slice in standalone mode, just +# run 'slice' from its directory. The 'slice' command is very similar to +# the 'merb' command, and takes all the same options, including -i to drop +# into an irb session for example. +# +# The usual Merb configuration directives and init.rb setup methods apply, +# including use_orm and before_app_loads/after_app_loads. +# +# If you need need different configurations for different environments you can +# even create the specific environment file in config/environments/ just like +# in a regular Merb application. +# +# In fact, a slice is no different from a normal # Merb application - it only +# differs by the fact that seamlessly integrates into a so called 'host' +# application, which in turn can override or finetune the slice implementation +# code and views. +# + +Merb::Config.use do |c| + + # Sets up a custom session id key which is used for the session persistence + # cookie name. If not specified, defaults to '_session_id'. + # c[:session_id_key] = '_session_id' + + # The session_secret_key is only required for the cookie session store. + c[:session_secret_key] = 'b9e47a2804f909011ae34c9cb64d3ff3d32a6479' + + # There are various options here, by default Merb comes with 'cookie', + # 'memory', 'memcache' or 'container'. + # You can of course use your favorite ORM instead: + # 'datamapper', 'sequel' or 'activerecord'. + c[:session_store] = 'cookie' + + # When running a slice standalone, you're usually developing it, + # so enable template reloading by default. + c[:reload_templates] = true + +end \ No newline at end of file diff --git a/config/router.rb b/config/router.rb new file mode 100644 index 0000000..e23cf7f --- /dev/null +++ b/config/router.rb @@ -0,0 +1,3 @@ +Merb::Router.prepare do + default_routes +end \ No newline at end of file diff --git a/examples/quick-E-mart/config/init.rb b/examples/quick-E-mart/config/init.rb index 20e37ff..8461399 100644 --- a/examples/quick-E-mart/config/init.rb +++ b/examples/quick-E-mart/config/init.rb @@ -6,4 +6,4 @@ Gem.path.unshift(Merb.root / "gems") require 'merb-haml' require 'merb-slices' -require "merb-E-mart" \ No newline at end of file +require "merb_mart" \ No newline at end of file diff --git a/examples/quick-E-mart/config/router.rb b/examples/quick-E-mart/config/router.rb index e28fdf9..1a68674 100644 --- a/examples/quick-E-mart/config/router.rb +++ b/examples/quick-E-mart/config/router.rb @@ -21,5 +21,5 @@ Merb.logger.info("Compiling routes...") Merb::Router.prepare do |r| - r.add_slice(:MerbEMart, 'admin') + r.add_slice(:MerbMart, 'admin') end \ No newline at end of file diff --git a/lib/merb-E-mart.rb b/lib/merb-E-mart.rb deleted file mode 100644 index 5927b50..0000000 --- a/lib/merb-E-mart.rb +++ /dev/null @@ -1,73 +0,0 @@ -if defined?(Merb::Plugins) - - require 'merb-slices' - require 'merb-haml' - require 'dm-validations' - require 'dm-types' - - require 'lib/merb-E-mart/exceptions/mixin_missing' - Merb::Plugins.add_rakefiles "merb-E-mart/merbtasks" - - # Register the Slice for the current host application - Merb::Slices::register(__FILE__) - - # Slice configuration - set this in a before_app_loads callback. - # By default a Slice uses its own layout, so you can swicht to - # the main application layout or no layout at all if needed. - # - # Configuration options: - # :layout - the layout to use; defaults to :merb_E_mart - # :mirror - which path component types to use on copy operations; defaults to all - Merb::Slices::config[:merb_E_mart] = { :layout => :merb_E_mart } - - # All Slice code is expected to be namespaced inside a module - module MerbEMart - - # Slice metadata - self.description = "MerbEMart is a chunky Merb slice!" - self.version = "0.0.1" - self.author = "YOUR NAME" - - # Initialization hook - runs before AfterAppLoads BootLoader - def self.init - end - - # Activation hook - runs after AfterAppLoads BootLoader - def self.activate - end - - # Deactivation hook - triggered by Merb::Slices#deactivate - def self.deactivate - end - - # Setup routes inside the host application - # - # @param scope - # Routes will be added within this scope (namespace). In fact, any - # router behaviour is a valid namespace, so you can attach - # routes at any level of your router setup. - def self.setup_router(scope) - scope.namespace(:admin) do |admin| - admin.to(:controller => 'products') do |products| - products.match('/products').to.name(:products) - end - end - end - - end - - # Setup the slice layout for MerbEMart - # - # Use MerbEMart.push_path and MerbEMart.push_app_path - # to set paths to merb-E-mart-level and app-level paths. Example: - # - MerbEMart.push_path(:application, MerbEMart.root) - MerbEMart.push_app_path(:application, Merb.root / 'slices' / 'merb-E-mart') - # ... - # - # Any component path that hasn't been set will default to MerbEMart.root - # - # Or just call setup_default_structure! to setup a basic Merb MVC structure. - MerbEMart.setup_default_structure! - -end \ No newline at end of file diff --git a/lib/merb-E-mart/exceptions/mixin_missing.rb b/lib/merb-E-mart/exceptions/mixin_missing.rb deleted file mode 100644 index 8243622..0000000 --- a/lib/merb-E-mart/exceptions/mixin_missing.rb +++ /dev/null @@ -1,7 +0,0 @@ -class MixinMissing < Exception - attr_accessor :klass, :method, :responsibility - - def initialize(klass, method, responsibility) - @klass, @method, @responsibility = klass, method, responsibility - end -end \ No newline at end of file diff --git a/lib/merb-E-mart/merbtasks.rb b/lib/merb-E-mart/merbtasks.rb deleted file mode 100644 index 8a985ab..0000000 --- a/lib/merb-E-mart/merbtasks.rb +++ /dev/null @@ -1,159 +0,0 @@ -$SLICED_APP=true # we're running inside the host application context - -namespace :slices do - namespace :merb_e_mart do - - desc "Install MerbEMart" - task :install => [:preflight, :setup_directories, :copy_assets, :migrate] - - desc "Test for any dependencies" - task :preflight do - # implement this to test for structural/code dependencies - # like certain directories or availability of other files - end - - desc "Setup directories" - task :setup_directories do - puts "Creating directories for host application" - MerbEMart.mirrored_components.each do |type| - if File.directory?(MerbEMart.dir_for(type)) - if !File.directory?(dst_path = MerbEMart.app_dir_for(type)) - relative_path = dst_path.relative_path_from(Merb.root) - puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}" - mkdir_p(dst_path) - end - end - end - end - - desc "Copy public assets to host application" - task :copy_assets do - puts "Copying assets for MerbEMart - resolves any collisions" - copied, preserved = MerbEMart.mirror_public! - puts "- no files to copy" if copied.empty? && preserved.empty? - copied.each { |f| puts "- copied #{f}" } - preserved.each { |f| puts "! preserved override as #{f}" } - end - - desc "Migrate the database" - task :migrate do - # implement this to perform any database related setup steps - end - - desc "Freeze MerbEMart into your app (only merb_e_mart/app)" - task :freeze => [ "freeze:app" ] - - namespace :freeze do - - desc "Freezes MerbEMart by installing the gem into application/gems using merb-freezer" - task :gem do - begin - Object.const_get(:Freezer).freeze(ENV["GEM"] || "merb_e_mart", ENV["UPDATE"], ENV["MODE"] || 'rubygems') - rescue NameError - puts "! dependency 'merb-freezer' missing" - end - end - - desc "Freezes MerbEMart by copying all files from merb_e_mart/app to your application" - task :app do - puts "Copying all merb_e_mart/app files to your application - resolves any collisions" - copied, preserved = MerbEMart.mirror_app! - puts "- no files to copy" if copied.empty? && preserved.empty? - copied.each { |f| puts "- copied #{f}" } - preserved.each { |f| puts "! preserved override as #{f}" } - end - - desc "Freeze all views into your application for easy modification" - task :views do - puts "Copying all view templates to your application - resolves any collisions" - copied, preserved = MerbEMart.mirror_files_for :view - puts "- no files to copy" if copied.empty? && preserved.empty? - copied.each { |f| puts "- copied #{f}" } - preserved.each { |f| puts "! preserved override as #{f}" } - end - - desc "Freeze all models into your application for easy modification" - task :models do - puts "Copying all models to your application - resolves any collisions" - copied, preserved = MerbEMart.mirror_files_for :model - puts "- no files to copy" if copied.empty? && preserved.empty? - copied.each { |f| puts "- copied #{f}" } - preserved.each { |f| puts "! preserved override as #{f}" } - end - - desc "Freezes MerbEMart as a gem and copies over merb_e_mart/app" - task :app_with_gem => [:gem, :app] - - desc "Freezes MerbEMart by unpacking all files into your application" - task :unpack do - puts "Unpacking MerbEMart files to your application - resolves any collisions" - copied, preserved = MerbEMart.unpack_slice! - puts "- no files to copy" if copied.empty? && preserved.empty? - copied.each { |f| puts "- copied #{f}" } - preserved.each { |f| puts "! preserved override as #{f}" } - end - - end - - desc "Run slice specs within the host application context" - task :spec => [ "spec:explain", "spec:default" ] - - namespace :spec do - - slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) - - task :explain do - puts "\nNote: By running MerbEMart specs inside the application context any\n" + - "overrides could break existing specs. This isn't always a problem,\n" + - "especially in the case of views. Use these spec tasks to check how\n" + - "well your application conforms to the original slice implementation." - end - - Spec::Rake::SpecTask.new('default') do |t| - t.spec_opts = ["--format", "specdoc", "--colour"] - t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort - end - - desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel" - Spec::Rake::SpecTask.new('model') do |t| - t.spec_opts = ["--format", "specdoc", "--colour"] - if(ENV['MODEL']) - t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort - else - t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort - end - end - - desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController" - Spec::Rake::SpecTask.new('controller') do |t| - t.spec_opts = ["--format", "specdoc", "--colour"] - if(ENV['CONTROLLER']) - t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort - else - t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort - end - end - - desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)" - Spec::Rake::SpecTask.new('view') do |t| - t.spec_opts = ["--format", "specdoc", "--colour"] - if(ENV['CONTROLLER'] and ENV['VIEW']) - t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort - elsif(ENV['CONTROLLER']) - t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort - else - t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort - end - end - - desc "Run all specs and output the result in html" - Spec::Rake::SpecTask.new('html') do |t| - t.spec_opts = ["--format", "html"] - t.libs = ['lib', 'server/lib' ] - t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort - end - - end - - end -end \ No newline at end of file diff --git a/lib/merb-e-mart.rb b/lib/merb-e-mart.rb deleted file mode 100644 index c62ebdd..0000000 --- a/lib/merb-e-mart.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Mart - - - - -end diff --git a/lib/merb_mart.rb b/lib/merb_mart.rb new file mode 100644 index 0000000..a289305 --- /dev/null +++ b/lib/merb_mart.rb @@ -0,0 +1,91 @@ +if defined?(Merb::Plugins) + + $:.unshift File.dirname(__FILE__) + + load_dependency 'merb-slices' + #require 'merb-haml' + #require 'dm-validations' + #require 'dm-types' + + Merb::Plugins.add_rakefiles "merb_mart/merbtasks", "merb_mart/slicetasks", "merb_mart/spectasks" + + # Register the Slice for the current host application + Merb::Slices::register(__FILE__) + + # Slice configuration - set this in a before_app_loads callback. + # By default a Slice uses its own layout, so you can swicht to + # the main application layout or no layout at all if needed. + # + # Configuration options: + # :layout - the layout to use; defaults to :merb_mart + # :mirror - which path component types to use on copy operations; defaults to all + Merb::Slices::config[:merb_mart][:layout] ||= :merb_mart + + # All Slice code is expected to be namespaced inside a module + module MerbMart + + # Slice metadata + self.description = "MerbMart is a chunky Merb slice!" + self.version = "0.0.1" + self.author = "YOUR NAME" + + # Stub classes loaded hook - runs before LoadClasses BootLoader + # right after a slice's classes have been loaded internally. + def self.loaded + end + + # Initialization hook - runs before AfterAppLoads BootLoader + def self.init + end + + # Activation hook - runs after AfterAppLoads BootLoader + def self.activate + end + + # Deactivation hook - triggered by Merb::Slices.deactivate(MerbMart) + def self.deactivate + end + + # Setup routes inside the host application + # + # @param scope + # Routes will be added within this scope (namespace). In fact, any + # router behaviour is a valid namespace, so you can attach + # routes at any level of your router setup. + # + # @note prefix your named routes with :merb_mart_ + # to avoid potential conflicts with global named routes. + def self.setup_router(scope) + scope.namespace(:admin) do |admin| + admin.to(:controller => 'products') do |products| + products.match('/products').to.name(:products) + end + end + # example of a named route + scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index) + # the slice is mounted at /merb_mart - note that it comes before default_routes + scope.match('/').to(:controller => 'main', :action => 'index').name(:home) + # enable slice-level default routes by default + scope.default_routes + end + + end + + # Setup the slice layout for MerbMart + # + # Use MerbMart.push_path and MerbMart.push_app_path + # to set paths to merb_mart-level and app-level paths. Example: + # + # MerbMart.push_path(:application, MerbMart.root) + # MerbMart.push_app_path(:application, Merb.root / 'slices' / 'merb_mart') + # ... + # + # Any component path that hasn't been set will default to MerbMart.root + # + # Or just call setup_default_structure! to setup a basic Merb MVC structure. + MerbMart.setup_default_structure! + + # Add dependencies for other MerbMart classes below. Example: + # dependency "merb_mart/other" + +end diff --git a/lib/merb_mart/merbtasks.rb b/lib/merb_mart/merbtasks.rb new file mode 100644 index 0000000..b73cf61 --- /dev/null +++ b/lib/merb_mart/merbtasks.rb @@ -0,0 +1,103 @@ +namespace :slices do + namespace :merb_mart do + + desc "Install MerbMart" + task :install => [:preflight, :setup_directories, :copy_assets, :migrate] + + desc "Test for any dependencies" + task :preflight do # see slicetasks.rb + end + + desc "Setup directories" + task :setup_directories do + puts "Creating directories for host application" + MerbMart.mirrored_components.each do |type| + if File.directory?(MerbMart.dir_for(type)) + if !File.directory?(dst_path = MerbMart.app_dir_for(type)) + relative_path = dst_path.relative_path_from(Merb.root) + puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}" + mkdir_p(dst_path) + end + end + end + end + + desc "Copy stub files to host application" + task :stubs do + puts "Copying stubs for MerbMart - resolves any collisions" + copied, preserved = MerbMart.mirror_stubs! + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + desc "Copy stub files and views to host application" + task :patch => [ "stubs", "freeze:views" ] + + desc "Copy public assets to host application" + task :copy_assets do + puts "Copying assets for MerbMart - resolves any collisions" + copied, preserved = MerbMart.mirror_public! + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + desc "Migrate the database" + task :migrate do # see slicetasks.rb + end + + desc "Freeze MerbMart into your app (only merb_mart/app)" + task :freeze => [ "freeze:app" ] + + namespace :freeze do + + desc "Freezes MerbMart by installing the gem into application/gems" + task :gem do + ENV["GEM"] ||= "merb_mart" + Rake::Task['slices:install_as_gem'].invoke + end + + desc "Freezes MerbMart by copying all files from merb_mart/app to your application" + task :app do + puts "Copying all merb_mart/app files to your application - resolves any collisions" + copied, preserved = MerbMart.mirror_app! + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + desc "Freeze all views into your application for easy modification" + task :views do + puts "Copying all view templates to your application - resolves any collisions" + copied, preserved = MerbMart.mirror_files_for :view + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + desc "Freeze all models into your application for easy modification" + task :models do + puts "Copying all models to your application - resolves any collisions" + copied, preserved = MerbMart.mirror_files_for :model + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + desc "Freezes MerbMart as a gem and copies over merb_mart/app" + task :app_with_gem => [:gem, :app] + + desc "Freezes MerbMart by unpacking all files into your application" + task :unpack do + puts "Unpacking MerbMart files to your application - resolves any collisions" + copied, preserved = MerbMart.unpack_slice! + puts "- no files to copy" if copied.empty? && preserved.empty? + copied.each { |f| puts "- copied #{f}" } + preserved.each { |f| puts "! preserved override as #{f}" } + end + + end + + end +end diff --git a/lib/merb_mart/slicetasks.rb b/lib/merb_mart/slicetasks.rb new file mode 100644 index 0000000..aa1fd96 --- /dev/null +++ b/lib/merb_mart/slicetasks.rb @@ -0,0 +1,18 @@ +namespace :slices do + namespace :merb_mart do + + # add your own merb_mart tasks here + + # implement this to test for structural/code dependencies + # like certain directories or availability of other files + desc "Test for any dependencies" + task :preflight do + end + + # implement this to perform any database related setup steps + desc "Migrate the database" + task :migrate do + end + + end +end \ No newline at end of file diff --git a/lib/merb_mart/spectasks.rb b/lib/merb_mart/spectasks.rb new file mode 100644 index 0000000..37986ce --- /dev/null +++ b/lib/merb_mart/spectasks.rb @@ -0,0 +1,65 @@ +namespace :slices do + namespace :merb_mart do + + desc "Run slice specs within the host application context" + task :spec => [ "spec:explain", "spec:default" ] + + namespace :spec do + + slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) + + task :explain do + puts "\nNote: By running MerbMart specs inside the application context any\n" + + "overrides could break existing specs. This isn't always a problem,\n" + + "especially in the case of views. Use these spec tasks to check how\n" + + "well your application conforms to the original slice implementation." + end + + Spec::Rake::SpecTask.new('default') do |t| + t.spec_opts = ["--format", "specdoc", "--colour"] + t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort + end + + desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel" + Spec::Rake::SpecTask.new('model') do |t| + t.spec_opts = ["--format", "specdoc", "--colour"] + if(ENV['MODEL']) + t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort + else + t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort + end + end + + desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController" + Spec::Rake::SpecTask.new('controller') do |t| + t.spec_opts = ["--format", "specdoc", "--colour"] + if(ENV['CONTROLLER']) + t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort + else + t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort + end + end + + desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)" + Spec::Rake::SpecTask.new('view') do |t| + t.spec_opts = ["--format", "specdoc", "--colour"] + if(ENV['CONTROLLER'] and ENV['VIEW']) + t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort + elsif(ENV['CONTROLLER']) + t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort + else + t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort + end + end + + desc "Run all specs and output the result in html" + Spec::Rake::SpecTask.new('html') do |t| + t.spec_opts = ["--format", "html"] + t.libs = ['lib', 'server/lib' ] + t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort + end + + end + + end +end \ No newline at end of file diff --git a/lib/merb-E-mart/upload_processor/static_file_processor.rb b/lib/merb_mart/upload_processor/static_file_processor.rb similarity index 87% rename from lib/merb-E-mart/upload_processor/static_file_processor.rb rename to lib/merb_mart/upload_processor/static_file_processor.rb index 43a4098..3c87adf 100644 --- a/lib/merb-E-mart/upload_processor/static_file_processor.rb +++ b/lib/merb_mart/upload_processor/static_file_processor.rb @@ -1,4 +1,4 @@ -class MerbEMart::StaticFileProcessor +class MerbMart::StaticFileProcessor attr_accessor :temp_file, :raw_data def process diff --git a/spec/merb-E-mart_spec.rb b/spec/merb-E-mart_spec.rb deleted file mode 100644 index 704e84b..0000000 --- a/spec/merb-E-mart_spec.rb +++ /dev/null @@ -1,80 +0,0 @@ -require File.dirname(__FILE__) + '/spec_helper' - -describe "MerbEMart (module)" do - - it "should have proper specs" - - # Feel free to remove the specs below - - it "should be registered in Merb::Slices.slices" do - Merb::Slices.slices.should include(MerbEMart) - end - - it "should have an :identifier property" do - MerbEMart.identifier.should == "merb-E-mart" - end - - it "should have an :identifier_sym property" do - MerbEMart.identifier_sym.should == :merb_E_mart - end - - it "should have a :root property" do - MerbEMart.root.should == current_slice_root - MerbEMart.root_path('app').should == current_slice_root / 'app' - end - - it "should have metadata properties" do - MerbEMart.description.should == "MerbEMart is a chunky Merb slice!" - MerbEMart.version.should == "0.0.1" - MerbEMart.author.should == "YOUR NAME" - end - - it "should have a config property (Hash)" do - MerbEMart.config.should be_kind_of(Hash) - end - - it "should have a :layout config option set" do - MerbEMart.config[:layout].should == :merb_E_mart - end - - it "should have a dir_for method" do - app_path = MerbEMart.dir_for(:application) - app_path.should == current_slice_root / 'app' - [:view, :model, :controller, :helper, :mailer, :part].each do |type| - MerbEMart.dir_for(type).should == app_path / "#{type}s" - end - public_path = MerbEMart.dir_for(:public) - public_path.should == current_slice_root / 'public' - [:stylesheet, :javascript, :image].each do |type| - MerbEMart.dir_for(type).should == public_path / "#{type}s" - end - end - - it "should have a app_dir_for method" do - root_path = MerbEMart.app_dir_for(:root) - root_path.should == Merb.root / 'slices' / 'merb-E-mart' - app_path = MerbEMart.app_dir_for(:application) - app_path.should == root_path / 'app' - [:view, :model, :controller, :helper, :mailer, :part].each do |type| - MerbEMart.app_dir_for(type).should == app_path / "#{type}s" - end - public_path = MerbEMart.app_dir_for(:public) - public_path.should == Merb.dir_for(:public) / 'slices' / 'merb-E-mart' - [:stylesheet, :javascript, :image].each do |type| - MerbEMart.app_dir_for(type).should == public_path / "#{type}s" - end - end - - it "should have a public_dir_for method" do - public_path = MerbEMart.public_dir_for(:public) - public_path.should == '/slices' / 'merb-E-mart' - [:stylesheet, :javascript, :image].each do |type| - MerbEMart.public_dir_for(type).should == public_path / "#{type}s" - end - end - - it "should keep a list of path component types to use when copying files" do - (MerbEMart.mirrored_components & MerbEMart.slice_paths.keys).length.should == MerbEMart.mirrored_components.length - end - -end \ No newline at end of file diff --git a/spec/merb_mart_spec.rb b/spec/merb_mart_spec.rb new file mode 100644 index 0000000..155b041 --- /dev/null +++ b/spec/merb_mart_spec.rb @@ -0,0 +1,88 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe "MerbMart (module)" do + + it "should have proper specs" + + # To spec MerbMart you need to hook it up to the router like this: + + # before :all do + # Merb::Router.prepare { add_slice(:MerbMart) } if standalone? + # end + # + # after :all do + # Merb::Router.reset! if standalone? + # end + + it "should be registered in Merb::Slices.slices" do + Merb::Slices.slices.should include(MerbMart) + end + + it "should have an :identifier property" do + MerbMart.identifier.should == "merb_mart" + end + + it "should have an :identifier_sym property" do + MerbMart.identifier_sym.should == :merb_E_mart + end + + it "should have a :root property" do + MerbMart.root.should == current_slice_root + MerbMart.root_path('app').should == current_slice_root / 'app' + end + + it "should have metadata properties" do + MerbMart.description.should == "MerbMart is a chunky Merb slice!" + MerbMart.version.should == "0.0.1" + MerbMart.author.should == "YOUR NAME" + end + + it "should have a config property (Hash)" do + MerbMart.config.should be_kind_of(Hash) + end + + it "should have a :layout config option set" do + MerbMart.config[:layout].should == :merb_E_mart + end + + it "should have a dir_for method" do + app_path = MerbMart.dir_for(:application) + app_path.should == current_slice_root / 'app' + [:view, :model, :controller, :helper, :mailer, :part].each do |type| + MerbMart.dir_for(type).should == app_path / "#{type}s" + end + public_path = MerbMart.dir_for(:public) + public_path.should == current_slice_root / 'public' + [:stylesheet, :javascript, :image].each do |type| + MerbMart.dir_for(type).should == public_path / "#{type}s" + end + end + + it "should have a app_dir_for method" do + root_path = MerbMart.app_dir_for(:root) + root_path.should == Merb.root / 'slices' / 'merb_mart' + app_path = MerbMart.app_dir_for(:application) + app_path.should == root_path / 'app' + [:view, :model, :controller, :helper, :mailer, :part].each do |type| + MerbMart.app_dir_for(type).should == app_path / "#{type}s" + end + public_path = MerbMart.app_dir_for(:public) + public_path.should == Merb.dir_for(:public) / 'slices' / 'merb_mart' + [:stylesheet, :javascript, :image].each do |type| + MerbMart.app_dir_for(type).should == public_path / "#{type}s" + end + end + + it "should have a public_dir_for method" do + public_path = MerbMart.public_dir_for(:public) + public_path.should == '/slices' / 'merb_mart' + [:stylesheet, :javascript, :image].each do |type| + MerbMart.public_dir_for(type).should == public_path / "#{type}s" + end + end + + it "should keep a list of path component types to use when copying files" do + (MerbMart.mirrored_components & MerbMart.slice_paths.keys).length.should == MerbMart.mirrored_components.length + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0f22b8..dd0f218 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,23 +1,23 @@ require 'rubygems' require 'merb-core' +require 'merb-slices' require 'spec' -require 'data_mapper' require 'can_has_fixtures' -# Add the dependency in a before_app_loads hook -Merb::BootLoader.before_app_loads { require(File.join(File.dirname(__FILE__), '..', 'lib', 'merb-E-mart')) } +# Add merb_mart.rb to the search path +Merb::Plugins.config[:merb_slices][:auto_register] = true +Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb_mart.rb') DataMapper.setup(:default, 'sqlite3::memory:') # Using Merb.root below makes sure that the correct root is set for # - testing standalone, without being installed as a gem and no host application # - testing from within the host application; its root will be used - Merb.start_environment( :testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test', - :merb_root => Merb.root + :session_store => 'memory' ) module Merb @@ -31,7 +31,7 @@ module Merb # Whether the specs are being run from a host application or standalone def standalone? - not $SLICED_APP + Merb.root == ::MerbMart.root end end diff --git a/stubs/app/controllers/application.rb b/stubs/app/controllers/application.rb new file mode 100644 index 0000000..050b2cd --- /dev/null +++ b/stubs/app/controllers/application.rb @@ -0,0 +1,2 @@ +class MerbMart::Application < Merb::Controller +end \ No newline at end of file diff --git a/stubs/app/controllers/main.rb b/stubs/app/controllers/main.rb new file mode 100644 index 0000000..7f4d0ac --- /dev/null +++ b/stubs/app/controllers/main.rb @@ -0,0 +1,2 @@ +class MerbMart::Main < MerbMart::Application +end \ No newline at end of file -- 2.11.4.GIT