diff --git a/merb-slices/README b/merb-slices/README index ef79456d..51a973ee 100644 --- a/merb-slices/README +++ b/merb-slices/README @@ -2,7 +2,7 @@ Merb-Slices =========== Merb-Slices is a Merb plugin for using and creating application 'slices' which -help you modularize your application. Usually these are reuseable extractions +help you modularize your application. Usually these are reusable extractions from your main app. In effect, a Slice is just like a regular Merb MVC application, both in functionality as well as in structure. @@ -19,7 +19,7 @@ mount a Slice multiple times and give extra parameters to customize an instance's behaviour. A Slice's Application controller uses controller_for_slice to setup slice -specific behaviour, which mainly affects cascaded view handling. Additionaly, +specific behaviour, which mainly affects cascaded view handling. Additionally, this method is available to any kind of controller, so it can be used for Merb Mailer too for example. diff --git a/merb-slices/lib/generators/templates/common/LICENSE b/merb-slices/lib/generators/templates/common/LICENSE index f28ba1b0..d9573211 100644 --- a/merb-slices/lib/generators/templates/common/LICENSE +++ b/merb-slices/lib/generators/templates/common/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) <%= Time.now.year %> Engine Yard +Copyright (c) <%= Time.now.year %> Your Name Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/merb-slices/lib/generators/templates/common/lib/%base_name%/merbtasks.rb b/merb-slices/lib/generators/templates/common/lib/%base_name%/merbtasks.rb index d2906fdf..bc909526 100644 --- a/merb-slices/lib/generators/templates/common/lib/%base_name%/merbtasks.rb +++ b/merb-slices/lib/generators/templates/common/lib/%base_name%/merbtasks.rb @@ -22,17 +22,17 @@ end end - desc "Copy stub files to host application" - task :stubs do - puts "Copying stubs for <%= module_name %> - resolves any collisions" - copied, preserved = <%= module_name %>.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 to host application" + # task :stubs do + # puts "Copying stubs for <%= module_name %> - resolves any collisions" + # copied, preserved = <%= module_name %>.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 stub files and views to host application" + # task :patch => [ "stubs", "freeze:views" ] desc "Copy public assets to host application" task :copy_assets do @@ -52,11 +52,11 @@ namespace :freeze do - desc "Freezes <%= module_name %> by installing the gem into application/gems" - task :gem do - ENV["GEM"] ||= "<%= base_name %>" - Rake::Task['slices:install_as_gem'].invoke - end + # desc "Freezes <%= module_name %> by installing the gem into application/gems" + # task :gem do + # ENV["GEM"] ||= "<%= base_name %>" + # Rake::Task['slices:install_as_gem'].invoke + # end desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application" task :app do diff --git a/merb-slices/lib/generators/templates/common/lib/%base_name%/slicetasks.rb b/merb-slices/lib/generators/templates/common/lib/%base_name%/slicetasks.rb index 1bdf65b1..1c8c80fe 100644 --- a/merb-slices/lib/generators/templates/common/lib/%base_name%/slicetasks.rb +++ b/merb-slices/lib/generators/templates/common/lib/%base_name%/slicetasks.rb @@ -3,16 +3,18 @@ # add your own <%= base_name %> 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 + # # Uncomment the following lines and edit the pre defined tasks + # + # # 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/merb-slices/lib/generators/templates/common/lib/%base_name%/spectasks.rb b/merb-slices/lib/generators/templates/common/lib/%base_name%/spectasks.rb index c8606745..20a0fdb1 100644 --- a/merb-slices/lib/generators/templates/common/lib/%base_name%/spectasks.rb +++ b/merb-slices/lib/generators/templates/common/lib/%base_name%/spectasks.rb @@ -30,25 +30,13 @@ end end - desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController" - Spec::Rake::SpecTask.new('controller') do |t| + desc "Run all request specs, run a spec for a specific request with REQUEST=MyRequest" + Spec::Rake::SpecTask.new('request') do |t| t.spec_opts = ["--format", "specdoc", "--colour"] - if(ENV['CONTROLLER']) - t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort + if(ENV['REQUEST']) + t.spec_files = Dir["#{slice_root}/spec/requests/**/#{ENV['REQUEST']}_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 + t.spec_files = Dir["#{slice_root}/spec/requests/**/*_spec.rb"].sort end end diff --git a/merb-slices/lib/generators/templates/full/README b/merb-slices/lib/generators/templates/full/README index 1422c69b..e102d6f6 100644 --- a/merb-slices/lib/generators/templates/full/README +++ b/merb-slices/lib/generators/templates/full/README @@ -4,60 +4,6 @@ A slice for the Merb framework. ------------------------------------------------------------------------------ - -<%= base_name %> -|-- LICENSE -|-- README -|-- Rakefile [1] -|-- TODO -|-- app [2] -| |-- controllers -| | |-- application.rb -| | `-- main.rb -| |-- helpers -| | `-- application_helper.rb -| `-- views -| |-- layout -| | `-- <%= base_name %>.html.erb [3] -| `-- main -| `-- index.html.erb -|-- lib -| |-- <%= base_name %> -| | |-- merbtasks.rb [4] -| | `-- slicetasks.rb [5] -| `-- <%= base_name %>.rb [6] -|-- log -| `-- merb_test.log -|-- public [7] -| |-- javascripts -| | `-- master.js -| `-- stylesheets -| `-- master.css -|-- spec [8] -| |-- <%= base_name %>_spec.rb -| |-- controllers -| | `-- main_spec.rb -| `-- spec_helper.rb -`-- stubs [9] - `-- app - `-- controllers - |-- application.rb - `-- main.rb - - -1. Rake tasks to package/install the gem - edit this to modify the manifest. -2. The slice application: controllers, models, helpers, views. -3. The default layout, as specified in Merb::Slices::config[:<%= symbol_name %>][:layout] - change this to :application to use the app's layout. -4. Standard rake tasks available to your application. -5. Your custom application rake tasks. -6. The main slice file - contains all slice setup logic/config. -7. Public assets you (optionally) install using rake slices:<%= symbol_name %>:install -8. Specs for basis slice behaviour - you usually adapt these for your slice. -9. Stubs of classes/views/files for the end-user to override - usually these - mimic the files in app/ and/or public/; use rake slices:<%= symbol_name %>:stubs to - get started with the override stubs. Also, slices:<%= symbol_name %>:patch will - copy over views to override in addition to the files found in /stubs. To see all available tasks for <%= module_name %> run: @@ -92,10 +38,6 @@ file: config/router.rb add_slice(:<%= module_name %>) -# example: /foo/:controller/:action/:id - -add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo' - # example: /:lang/:controller/:action/:id add_slice(:<%= module_name %>, :path => ':lang') @@ -131,40 +73,4 @@ instead/in addition to the ones supplied (if any) in host-app/public/slices/<%= base_name %>. In any case don't edit those files directly as they may be clobbered any time -rake <%= symbol_name %>:install is run. - ------------------------------------------------------------------------------- - -About Slices -============ - -Merb-Slices is a Merb plugin for using and creating application 'slices' which -help you modularize your application. Usually these are reuseable extractions -from your main app. In effect, a Slice is just like a regular Merb MVC -application, both in functionality as well as in structure. - -When you generate a Slice stub structure, a module is setup to serve as a -namespace for your controller, models, helpers etc. This ensures maximum -encapsulation. You could say a Slice is a mixture between a Merb plugin (a -Gem) and a Merb application, reaping the benefits of both. - -A host application can 'mount' a Slice inside the router, which means you have -full over control how it integrates. By default a Slice's routes are prefixed -by its name (a router :namespace), but you can easily provide your own prefix -or leave it out, mounting it at the root of your url-schema. You can even -mount a Slice multiple times and give extra parameters to customize an -instance's behaviour. - -A Slice's Application controller uses controller_for_slice to setup slice -specific behaviour, which mainly affects cascaded view handling. Additionaly, -this method is available to any kind of controller, so it can be used for -Merb Mailer too for example. - -There are many ways which let you customize a Slice's functionality and -appearance without ever touching the Gem-level code itself. It's not only easy -to add template/layout overrides, you can also add/modify controllers, models -and other runtime code from within the host application. - -To create your own Slice run this (somewhere outside of your merb app): - -$ merb-gen slice \ No newline at end of file +rake <%= symbol_name %>:install is run. \ No newline at end of file diff --git a/merb-slices/lib/generators/templates/full/spec/%base_name%_spec.rb b/merb-slices/lib/generators/templates/full/spec/%base_name%_spec.rb index 1012a5dc..ca541648 100644 --- a/merb-slices/lib/generators/templates/full/spec/%base_name%_spec.rb +++ b/merb-slices/lib/generators/templates/full/spec/%base_name%_spec.rb @@ -4,8 +4,6 @@ # Implement your <%= module_name %> specs here - it "should have proper specs" - # To spec <%= module_name %> you need to hook it up to the router like this: # before :all do @@ -15,5 +13,8 @@ # after :all do # Merb::Router.reset! if standalone? # end + # + # + # it "should have proper specs" end \ No newline at end of file diff --git a/merb-slices/lib/generators/templates/full/spec/controllers/main_spec.rb b/merb-slices/lib/generators/templates/full/spec/controllers/main_spec.rb deleted file mode 100644 index 9b53ac72..00000000 --- a/merb-slices/lib/generators/templates/full/spec/controllers/main_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe "<%= module_name %>::Main (controller)" do - - # Feel free to remove the specs below - - before :all do - Merb::Router.prepare { add_slice(:<%= module_name %>) } if standalone? - end - - after :all do - Merb::Router.reset! if standalone? - end - - # it "should have access to the slice module" do - # controller = dispatch_to(<%= module_name %>::Main, :index) - # controller.slice.should == <%= module_name %> - # controller.slice.should == <%= module_name %>::Main.slice - # end - # - # it "should have an index action" do - # controller = dispatch_to(<%= module_name %>::Main, :index) - # controller.status.should == 200 - # controller.body.should contain('<%= module_name %>') - # end - # - # it "should work with the default route" do - # controller = get("/<%= base_name %>/main/index") - # controller.should be_kind_of(<%= module_name %>::Main) - # controller.action_name.should == 'index' - # end - # - # it "should work with the example named route" do - # controller = get("/<%= base_name %>/index.html") - # controller.should be_kind_of(<%= module_name %>::Main) - # controller.action_name.should == 'index' - # end - # - # it "should have a slice_url helper method for slice-specific routes" do - # controller = dispatch_to(<%= module_name %>::Main, 'index') - # - # url = controller.url(:<%= symbol_name %>_default, :controller => 'main', :action => 'show', :format => 'html') - # url.should == "/<%= base_name %>/main/show.html" - # controller.slice_url(:controller => 'main', :action => 'show', :format => 'html').should == url - # - # url = controller.url(:<%= symbol_name %>_index, :format => 'html') - # url.should == "/<%= base_name %>/index.html" - # controller.slice_url(:index, :format => 'html').should == url - # - # url = controller.url(:<%= symbol_name %>_home) - # url.should == "/<%= base_name %>/" - # controller.slice_url(:home).should == url - # end - # - # it "should have helper methods for dealing with public paths" do - # controller = dispatch_to(<%= module_name %>::Main, :index) - # controller.public_path_for(:image).should == "/slices/<%= base_name %>/images" - # controller.public_path_for(:javascript).should == "/slices/<%= base_name %>/javascripts" - # controller.public_path_for(:stylesheet).should == "/slices/<%= base_name %>/stylesheets" - # - # controller.image_path.should == "/slices/<%= base_name %>/images" - # controller.javascript_path.should == "/slices/<%= base_name %>/javascripts" - # controller.stylesheet_path.should == "/slices/<%= base_name %>/stylesheets" - # end - # - # it "should have a slice-specific _template_root" do - # <%= module_name %>::Main._template_root.should == <%= module_name %>.dir_for(:view) - # <%= module_name %>::Main._template_root.should == <%= module_name %>::Application._template_root - # end - -end \ No newline at end of file diff --git a/merb-slices/lib/generators/templates/full/spec/requests/main_spec.rb b/merb-slices/lib/generators/templates/full/spec/requests/main_spec.rb new file mode 100644 index 00000000..6fa81f90 --- /dev/null +++ b/merb-slices/lib/generators/templates/full/spec/requests/main_spec.rb @@ -0,0 +1,30 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb') + +describe "/<%= base_name %>/" do + + before(:all) do + mount_slice + end + + describe "GET /<%= base_name %>/" do + + before(:each) do + @response = request("/") + end + + it "should be successful" do + @response.status.should be_successful + end + + # This is just an example of what you can do + # You can also use the other webrat methods to click links, + # fill up forms etc... + it "should render the default slice layout" do + @response.should have_tag(:h1, :content => "<%= module_name %> Slice") + @response.should have_selector("div#container div#main") + @response.should have_xpath("//div[@id='container']/div[@id='main']") + end + + end + +end \ No newline at end of file diff --git a/merb-slices/lib/generators/templates/full/spec/spec_helper.rb b/merb-slices/lib/generators/templates/full/spec/spec_helper.rb index f6dbdbfb..fc4a6947 100644 --- a/merb-slices/lib/generators/templates/full/spec/spec_helper.rb +++ b/merb-slices/lib/generators/templates/full/spec/spec_helper.rb @@ -43,4 +43,16 @@ def standalone? config.include(Merb::Test::RouteHelper) config.include(Merb::Test::ControllerHelper) config.include(Merb::Test::SliceHelper) +end + +# You can add your own helpers here +# +Merb::Test.add_helpers do + def mount_slice + Merb::Router.prepare { add_slice(:<%= module_name %>, "<%= base_name %>") } if standalone? + end + + def dismount_slice + Merb::Router.reset! if standalone? + end end \ No newline at end of file diff --git a/merb-slices/spec/full_slice_generator_spec.rb b/merb-slices/spec/full_slice_generator_spec.rb index 825b249d..35dffe02 100644 --- a/merb-slices/spec/full_slice_generator_spec.rb +++ b/merb-slices/spec/full_slice_generator_spec.rb @@ -30,8 +30,8 @@ "testing/LICENSE", "testing/public", "testing/public/javascripts", "testing/public/javascripts/master.js", "testing/public/stylesheets", "testing/public/stylesheets/master.css", "testing/Rakefile", - "testing/README", "testing/spec", "testing/spec/controllers", - "testing/spec/controllers/main_spec.rb", "testing/spec/spec_helper.rb", + "testing/README", "testing/spec", "testing/spec/requests", + "testing/spec/requests/main_spec.rb", "testing/spec/spec_helper.rb", "testing/spec/testing_spec.rb", "testing/stubs", "testing/stubs/app", "testing/stubs/app/controllers", "testing/stubs/app/controllers/application.rb", "testing/stubs/app/controllers/main.rb", "testing/TODO"