1 $SLICED_APP=true # we're running inside the host application context
4 namespace :merb_e_mart do
6 desc "Install MerbEMart"
7 task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
9 desc "Test for any dependencies"
11 # implement this to test for structural/code dependencies
12 # like certain directories or availability of other files
15 desc "Setup directories"
16 task :setup_directories do
17 puts "Creating directories for host application"
18 MerbEMart.mirrored_components.each do |type|
19 if File.directory?(MerbEMart.dir_for(type))
20 if !File.directory?(dst_path = MerbEMart.app_dir_for(type))
21 relative_path = dst_path.relative_path_from(Merb.root)
22 puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
29 desc "Copy public assets to host application"
31 puts "Copying assets for MerbEMart - resolves any collisions"
32 copied, preserved = MerbEMart.mirror_public!
33 puts "- no files to copy" if copied.empty? && preserved.empty?
34 copied.each { |f| puts "- copied #{f}" }
35 preserved.each { |f| puts "! preserved override as #{f}" }
38 desc "Migrate the database"
40 # implement this to perform any database related setup steps
43 desc "Freeze MerbEMart into your app (only merb_e_mart/app)"
44 task :freeze => [ "freeze:app" ]
48 desc "Freezes MerbEMart by installing the gem into application/gems using merb-freezer"
51 Object.const_get(:Freezer).freeze(ENV["GEM"] || "merb_e_mart", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
53 puts "! dependency 'merb-freezer' missing"
57 desc "Freezes MerbEMart by copying all files from merb_e_mart/app to your application"
59 puts "Copying all merb_e_mart/app files to your application - resolves any collisions"
60 copied, preserved = MerbEMart.mirror_app!
61 puts "- no files to copy" if copied.empty? && preserved.empty?
62 copied.each { |f| puts "- copied #{f}" }
63 preserved.each { |f| puts "! preserved override as #{f}" }
66 desc "Freeze all views into your application for easy modification"
68 puts "Copying all view templates to your application - resolves any collisions"
69 copied, preserved = MerbEMart.mirror_files_for :view
70 puts "- no files to copy" if copied.empty? && preserved.empty?
71 copied.each { |f| puts "- copied #{f}" }
72 preserved.each { |f| puts "! preserved override as #{f}" }
75 desc "Freeze all models into your application for easy modification"
77 puts "Copying all models to your application - resolves any collisions"
78 copied, preserved = MerbEMart.mirror_files_for :model
79 puts "- no files to copy" if copied.empty? && preserved.empty?
80 copied.each { |f| puts "- copied #{f}" }
81 preserved.each { |f| puts "! preserved override as #{f}" }
84 desc "Freezes MerbEMart as a gem and copies over merb_e_mart/app"
85 task :app_with_gem => [:gem, :app]
87 desc "Freezes MerbEMart by unpacking all files into your application"
89 puts "Unpacking MerbEMart files to your application - resolves any collisions"
90 copied, preserved = MerbEMart.unpack_slice!
91 puts "- no files to copy" if copied.empty? && preserved.empty?
92 copied.each { |f| puts "- copied #{f}" }
93 preserved.each { |f| puts "! preserved override as #{f}" }
98 desc "Run slice specs within the host application context"
99 task :spec => [ "spec:explain", "spec:default" ]
103 slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
106 puts "\nNote: By running MerbEMart specs inside the application context any\n" +
107 "overrides could break existing specs. This isn't always a problem,\n" +
108 "especially in the case of views. Use these spec tasks to check how\n" +
109 "well your application conforms to the original slice implementation."
112 Spec::Rake::SpecTask.new('default') do |t|
113 t.spec_opts = ["--format", "specdoc", "--colour"]
114 t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
117 desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
118 Spec::Rake::SpecTask.new('model') do |t|
119 t.spec_opts = ["--format", "specdoc", "--colour"]
121 t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
123 t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
127 desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
128 Spec::Rake::SpecTask.new('controller') do |t|
129 t.spec_opts = ["--format", "specdoc", "--colour"]
130 if(ENV['CONTROLLER'])
131 t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
133 t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
137 desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
138 Spec::Rake::SpecTask.new('view') do |t|
139 t.spec_opts = ["--format", "specdoc", "--colour"]
140 if(ENV['CONTROLLER'] and ENV['VIEW'])
141 t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
142 elsif(ENV['CONTROLLER'])
143 t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
145 t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
149 desc "Run all specs and output the result in html"
150 Spec::Rake::SpecTask.new('html') do |t|
151 t.spec_opts = ["--format", "html"]
152 t.libs = ['lib', 'server/lib' ]
153 t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort