merb-slices 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@ Merb-Slices
2
2
  ===========
3
3
 
4
4
  Merb-Slices is a Merb plugin for using and creating application 'slices' which
5
- help you modularize your application. Usually these are reuseable extractions
5
+ help you modularize your application. Usually these are reusable extractions
6
6
  from your main app. In effect, a Slice is just like a regular Merb MVC
7
7
  application, both in functionality as well as in structure.
8
8
 
@@ -19,7 +19,7 @@ mount a Slice multiple times and give extra parameters to customize an
19
19
  instance's behaviour.
20
20
 
21
21
  A Slice's Application controller uses controller_for_slice to setup slice
22
- specific behaviour, which mainly affects cascaded view handling. Additionaly,
22
+ specific behaviour, which mainly affects cascaded view handling. Additionally,
23
23
  this method is available to any kind of controller, so it can be used for
24
24
  Merb Mailer too for example.
25
25
 
@@ -1,4 +1,4 @@
1
- Copyright (c) <%= Time.now.year %> Engine Yard
1
+ Copyright (c) <%= Time.now.year %> Your Name
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -22,17 +22,17 @@ namespace :slices do
22
22
  end
23
23
  end
24
24
 
25
- desc "Copy stub files to host application"
26
- task :stubs do
27
- puts "Copying stubs for <%= module_name %> - resolves any collisions"
28
- copied, preserved = <%= module_name %>.mirror_stubs!
29
- puts "- no files to copy" if copied.empty? && preserved.empty?
30
- copied.each { |f| puts "- copied #{f}" }
31
- preserved.each { |f| puts "! preserved override as #{f}" }
32
- end
25
+ # desc "Copy stub files to host application"
26
+ # task :stubs do
27
+ # puts "Copying stubs for <%= module_name %> - resolves any collisions"
28
+ # copied, preserved = <%= module_name %>.mirror_stubs!
29
+ # puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ # copied.each { |f| puts "- copied #{f}" }
31
+ # preserved.each { |f| puts "! preserved override as #{f}" }
32
+ # end
33
33
 
34
- desc "Copy stub files and views to host application"
35
- task :patch => [ "stubs", "freeze:views" ]
34
+ # desc "Copy stub files and views to host application"
35
+ # task :patch => [ "stubs", "freeze:views" ]
36
36
 
37
37
  desc "Copy public assets to host application"
38
38
  task :copy_assets do
@@ -52,11 +52,11 @@ namespace :slices do
52
52
 
53
53
  namespace :freeze do
54
54
 
55
- desc "Freezes <%= module_name %> by installing the gem into application/gems"
56
- task :gem do
57
- ENV["GEM"] ||= "<%= base_name %>"
58
- Rake::Task['slices:install_as_gem'].invoke
59
- end
55
+ # desc "Freezes <%= module_name %> by installing the gem into application/gems"
56
+ # task :gem do
57
+ # ENV["GEM"] ||= "<%= base_name %>"
58
+ # Rake::Task['slices:install_as_gem'].invoke
59
+ # end
60
60
 
61
61
  desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application"
62
62
  task :app do
@@ -3,16 +3,18 @@ namespace :slices do
3
3
 
4
4
  # add your own <%= base_name %> tasks here
5
5
 
6
- # implement this to test for structural/code dependencies
7
- # like certain directories or availability of other files
8
- desc "Test for any dependencies"
9
- task :preflight do
10
- end
11
-
12
- # implement this to perform any database related setup steps
13
- desc "Migrate the database"
14
- task :migrate do
15
- end
6
+ # # Uncomment the following lines and edit the pre defined tasks
7
+ #
8
+ # # implement this to test for structural/code dependencies
9
+ # # like certain directories or availability of other files
10
+ # desc "Test for any dependencies"
11
+ # task :preflight do
12
+ # end
13
+ #
14
+ # # implement this to perform any database related setup steps
15
+ # desc "Migrate the database"
16
+ # task :migrate do
17
+ # end
16
18
 
17
19
  end
18
20
  end
@@ -30,25 +30,13 @@ namespace :slices do
30
30
  end
31
31
  end
32
32
 
33
- desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
34
- Spec::Rake::SpecTask.new('controller') do |t|
33
+ desc "Run all request specs, run a spec for a specific request with REQUEST=MyRequest"
34
+ Spec::Rake::SpecTask.new('request') do |t|
35
35
  t.spec_opts = ["--format", "specdoc", "--colour"]
36
- if(ENV['CONTROLLER'])
37
- t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
36
+ if(ENV['REQUEST'])
37
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/#{ENV['REQUEST']}_spec.rb"].sort
38
38
  else
39
- t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
40
- end
41
- end
42
-
43
- desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
44
- Spec::Rake::SpecTask.new('view') do |t|
45
- t.spec_opts = ["--format", "specdoc", "--colour"]
46
- if(ENV['CONTROLLER'] and ENV['VIEW'])
47
- t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
48
- elsif(ENV['CONTROLLER'])
49
- t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
50
- else
51
- t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
39
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/*_spec.rb"].sort
52
40
  end
53
41
  end
54
42
 
@@ -4,60 +4,6 @@
4
4
  A slice for the Merb framework.
5
5
 
6
6
  ------------------------------------------------------------------------------
7
-
8
- <%= base_name %>
9
- |-- LICENSE
10
- |-- README
11
- |-- Rakefile [1]
12
- |-- TODO
13
- |-- app [2]
14
- | |-- controllers
15
- | | |-- application.rb
16
- | | `-- main.rb
17
- | |-- helpers
18
- | | `-- application_helper.rb
19
- | `-- views
20
- | |-- layout
21
- | | `-- <%= base_name %>.html.erb [3]
22
- | `-- main
23
- | `-- index.html.erb
24
- |-- lib
25
- | |-- <%= base_name %>
26
- | | |-- merbtasks.rb [4]
27
- | | `-- slicetasks.rb [5]
28
- | `-- <%= base_name %>.rb [6]
29
- |-- log
30
- | `-- merb_test.log
31
- |-- public [7]
32
- | |-- javascripts
33
- | | `-- master.js
34
- | `-- stylesheets
35
- | `-- master.css
36
- |-- spec [8]
37
- | |-- <%= base_name %>_spec.rb
38
- | |-- controllers
39
- | | `-- main_spec.rb
40
- | `-- spec_helper.rb
41
- `-- stubs [9]
42
- `-- app
43
- `-- controllers
44
- |-- application.rb
45
- `-- main.rb
46
-
47
-
48
- 1. Rake tasks to package/install the gem - edit this to modify the manifest.
49
- 2. The slice application: controllers, models, helpers, views.
50
- 3. The default layout, as specified in Merb::Slices::config[:<%= symbol_name %>][:layout]
51
- change this to :application to use the app's layout.
52
- 4. Standard rake tasks available to your application.
53
- 5. Your custom application rake tasks.
54
- 6. The main slice file - contains all slice setup logic/config.
55
- 7. Public assets you (optionally) install using rake slices:<%= symbol_name %>:install
56
- 8. Specs for basis slice behaviour - you usually adapt these for your slice.
57
- 9. Stubs of classes/views/files for the end-user to override - usually these
58
- mimic the files in app/ and/or public/; use rake slices:<%= symbol_name %>:stubs to
59
- get started with the override stubs. Also, slices:<%= symbol_name %>:patch will
60
- copy over views to override in addition to the files found in /stubs.
61
7
 
62
8
 
63
9
  To see all available tasks for <%= module_name %> run:
@@ -92,10 +38,6 @@ file: config/router.rb
92
38
 
93
39
  add_slice(:<%= module_name %>)
94
40
 
95
- # example: /foo/:controller/:action/:id
96
-
97
- add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
98
-
99
41
  # example: /:lang/:controller/:action/:id
100
42
 
101
43
  add_slice(:<%= module_name %>, :path => ':lang')
@@ -131,40 +73,4 @@ instead/in addition to the ones supplied (if any) in
131
73
  host-app/public/slices/<%= base_name %>.
132
74
 
133
75
  In any case don't edit those files directly as they may be clobbered any time
134
- rake <%= symbol_name %>:install is run.
135
-
136
- ------------------------------------------------------------------------------
137
-
138
- About Slices
139
- ============
140
-
141
- Merb-Slices is a Merb plugin for using and creating application 'slices' which
142
- help you modularize your application. Usually these are reuseable extractions
143
- from your main app. In effect, a Slice is just like a regular Merb MVC
144
- application, both in functionality as well as in structure.
145
-
146
- When you generate a Slice stub structure, a module is setup to serve as a
147
- namespace for your controller, models, helpers etc. This ensures maximum
148
- encapsulation. You could say a Slice is a mixture between a Merb plugin (a
149
- Gem) and a Merb application, reaping the benefits of both.
150
-
151
- A host application can 'mount' a Slice inside the router, which means you have
152
- full over control how it integrates. By default a Slice's routes are prefixed
153
- by its name (a router :namespace), but you can easily provide your own prefix
154
- or leave it out, mounting it at the root of your url-schema. You can even
155
- mount a Slice multiple times and give extra parameters to customize an
156
- instance's behaviour.
157
-
158
- A Slice's Application controller uses controller_for_slice to setup slice
159
- specific behaviour, which mainly affects cascaded view handling. Additionaly,
160
- this method is available to any kind of controller, so it can be used for
161
- Merb Mailer too for example.
162
-
163
- There are many ways which let you customize a Slice's functionality and
164
- appearance without ever touching the Gem-level code itself. It's not only easy
165
- to add template/layout overrides, you can also add/modify controllers, models
166
- and other runtime code from within the host application.
167
-
168
- To create your own Slice run this (somewhere outside of your merb app):
169
-
170
- $ merb-gen slice <your-lowercase-slice-name>
76
+ rake <%= symbol_name %>:install is run.
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "<%= base_name %>/merbtasks", "<%= base_name %>/slicetasks", "<%= base_name %>/spectasks"
7
7
 
8
8
  # Register the Slice for the current host application
@@ -4,8 +4,6 @@ describe "<%= module_name %> (module)" do
4
4
 
5
5
  # Implement your <%= module_name %> specs here
6
6
 
7
- it "should have proper specs"
8
-
9
7
  # To spec <%= module_name %> you need to hook it up to the router like this:
10
8
 
11
9
  # before :all do
@@ -15,5 +13,8 @@ describe "<%= module_name %> (module)" do
15
13
  # after :all do
16
14
  # Merb::Router.reset! if standalone?
17
15
  # end
16
+ #
17
+ #
18
+ # it "should have proper specs"
18
19
 
19
20
  end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+
3
+ describe "/<%= base_name %>/" do
4
+
5
+ before(:all) do
6
+ mount_slice
7
+ end
8
+
9
+ describe "GET /" do
10
+
11
+ before(:each) do
12
+ @response = request("/<%= base_name %>/")
13
+ end
14
+
15
+ it "should be successful" do
16
+ @response.status.should be_successful
17
+ end
18
+
19
+ # This is just an example of what you can do
20
+ # You can also use the other webrat methods to click links,
21
+ # fill up forms etc...
22
+ it "should render the default slice layout" do
23
+ @response.should have_tag(:h1, :content => "<%= module_name %> Slice")
24
+ @response.should have_selector("div#container div#main")
25
+ @response.should have_xpath("//div[@id='container']/div[@id='main']")
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -43,4 +43,16 @@ Spec::Runner.configure do |config|
43
43
  config.include(Merb::Test::RouteHelper)
44
44
  config.include(Merb::Test::ControllerHelper)
45
45
  config.include(Merb::Test::SliceHelper)
46
+ end
47
+
48
+ # You can add your own helpers here
49
+ #
50
+ Merb::Test.add_helpers do
51
+ def mount_slice
52
+ Merb::Router.prepare { add_slice(:<%= module_name %>, "<%= base_name %>") } if standalone?
53
+ end
54
+
55
+ def dismount_slice
56
+ Merb::Router.reset! if standalone?
57
+ end
46
58
  end
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "<%= base_name %>/merbtasks", "<%= base_name %>/slicetasks"
7
7
 
8
8
  # Register the Slice for the current host application
@@ -18,7 +18,7 @@ if defined?(Merb::Plugins)
18
18
  # Slice metadata
19
19
  self.description = "<%= module_name %> is a thin Merb slice!"
20
20
  self.version = "0.0.1"
21
- self.author = "Engine Yard"
21
+ self.author = "Your Name"
22
22
 
23
23
  # Stub classes loaded hook - runs before LoadClasses BootLoader
24
24
  # right after a slice's classes have been loaded internally.
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "<%= base_name %>/merbtasks", "<%= base_name %>/slicetasks"
7
7
 
8
8
  # Register the Slice for the current host application
@@ -17,7 +17,7 @@ if defined?(Merb::Plugins)
17
17
  # Slice metadata
18
18
  self.description = "<%= module_name %> is a very thin Merb slice!"
19
19
  self.version = "0.0.1"
20
- self.author = "Engine Yard"
20
+ self.author = "Your Name"
21
21
 
22
22
  # Stub classes loaded hook - runs before LoadClasses BootLoader
23
23
  # right after a slice's classes have been loaded internally.
@@ -30,8 +30,8 @@ describe Merb::Generators::FullSliceGenerator do
30
30
  "testing/LICENSE", "testing/public", "testing/public/javascripts",
31
31
  "testing/public/javascripts/master.js", "testing/public/stylesheets",
32
32
  "testing/public/stylesheets/master.css", "testing/Rakefile",
33
- "testing/README", "testing/spec", "testing/spec/controllers",
34
- "testing/spec/controllers/main_spec.rb", "testing/spec/spec_helper.rb",
33
+ "testing/README", "testing/spec", "testing/spec/requests",
34
+ "testing/spec/requests/main_spec.rb", "testing/spec/spec_helper.rb",
35
35
  "testing/spec/testing_spec.rb", "testing/stubs", "testing/stubs/app",
36
36
  "testing/stubs/app/controllers", "testing/stubs/app/controllers/application.rb",
37
37
  "testing/stubs/app/controllers/main.rb", "testing/TODO"
@@ -4,19 +4,19 @@ describe Merb::Generators::SliceGenerator do
4
4
 
5
5
  it "should invoke the full generator by default" do
6
6
  generator = Merb::Generators::SliceGenerator.new('/tmp', { :pretend => true }, 'testing')
7
- generator.invoke!
7
+ #generator.invoke!
8
8
  generator.invocations.first.class.should == Merb::Generators::FullSliceGenerator
9
9
  end
10
10
 
11
11
  it "should invoke the flat generator if --thin is set" do
12
12
  generator = Merb::Generators::SliceGenerator.new('/tmp', { :pretend => true, :thin => true }, 'testing')
13
- generator.invoke!
13
+ #generator.invoke!
14
14
  generator.invocations.first.class.should == Merb::Generators::ThinSliceGenerator
15
15
  end
16
16
 
17
17
  it "should invoke the very flat generator if --very-thin is set" do
18
18
  generator = Merb::Generators::SliceGenerator.new('/tmp', { :pretend => true, :very_thin => true }, 'testing')
19
- generator.invoke!
19
+ #generator.invoke!
20
20
  generator.invocations.first.class.should == Merb::Generators::VeryThinSliceGenerator
21
21
  end
22
22
 
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "full-test-slice/merbtasks", "full-test-slice/slicetasks", "full-test-slice/spectasks"
7
7
 
8
8
  # Register the Slice for the current host application
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "thin-test-slice/merbtasks", "thin-test-slice/slicetasks"
7
7
 
8
8
  # Register the Slice for the current host application
@@ -2,7 +2,7 @@ if defined?(Merb::Plugins)
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)
4
4
 
5
- load_dependency 'merb-slices'
5
+ dependency 'merb-slices', :immediate => true
6
6
  Merb::Plugins.add_rakefiles "very-thin-test-slice/merbtasks", "very-thin-test-slice/slicetasks"
7
7
 
8
8
  # Register the Slice for the current host application
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-slices
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien Franzen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-08 00:00:00 -08:00
12
+ date: 2008-12-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.0.4
23
+ version: 1.0.5
24
24
  version:
25
25
  description: Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application.
26
26
  email: info@fabien.be
@@ -78,8 +78,8 @@ files:
78
78
  - lib/generators/templates/full/README
79
79
  - lib/generators/templates/full/spec
80
80
  - lib/generators/templates/full/spec/%base_name%_spec.rb
81
- - lib/generators/templates/full/spec/controllers
82
- - lib/generators/templates/full/spec/controllers/main_spec.rb
81
+ - lib/generators/templates/full/spec/requests
82
+ - lib/generators/templates/full/spec/requests/main_spec.rb
83
83
  - lib/generators/templates/full/spec/spec_helper.rb
84
84
  - lib/generators/templates/full/stubs
85
85
  - lib/generators/templates/full/stubs/app
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe "<%= module_name %>::Main (controller)" do
4
-
5
- # Feel free to remove the specs below
6
-
7
- before :all do
8
- Merb::Router.prepare { add_slice(:<%= module_name %>) } if standalone?
9
- end
10
-
11
- after :all do
12
- Merb::Router.reset! if standalone?
13
- end
14
-
15
- it "should have access to the slice module" do
16
- controller = dispatch_to(<%= module_name %>::Main, :index)
17
- controller.slice.should == <%= module_name %>
18
- controller.slice.should == <%= module_name %>::Main.slice
19
- end
20
-
21
- it "should have an index action" do
22
- controller = dispatch_to(<%= module_name %>::Main, :index)
23
- controller.status.should == 200
24
- controller.body.should contain('<%= module_name %>')
25
- end
26
-
27
- it "should work with the default route" do
28
- controller = get("/<%= base_name %>/main/index")
29
- controller.should be_kind_of(<%= module_name %>::Main)
30
- controller.action_name.should == 'index'
31
- end
32
-
33
- it "should work with the example named route" do
34
- controller = get("/<%= base_name %>/index.html")
35
- controller.should be_kind_of(<%= module_name %>::Main)
36
- controller.action_name.should == 'index'
37
- end
38
-
39
- it "should have a slice_url helper method for slice-specific routes" do
40
- controller = dispatch_to(<%= module_name %>::Main, 'index')
41
-
42
- url = controller.url(:<%= symbol_name %>_default, :controller => 'main', :action => 'show', :format => 'html')
43
- url.should == "/<%= base_name %>/main/show.html"
44
- controller.slice_url(:controller => 'main', :action => 'show', :format => 'html').should == url
45
-
46
- url = controller.url(:<%= symbol_name %>_index, :format => 'html')
47
- url.should == "/<%= base_name %>/index.html"
48
- controller.slice_url(:index, :format => 'html').should == url
49
-
50
- url = controller.url(:<%= symbol_name %>_home)
51
- url.should == "/<%= base_name %>/"
52
- controller.slice_url(:home).should == url
53
- end
54
-
55
- it "should have helper methods for dealing with public paths" do
56
- controller = dispatch_to(<%= module_name %>::Main, :index)
57
- controller.public_path_for(:image).should == "/slices/<%= base_name %>/images"
58
- controller.public_path_for(:javascript).should == "/slices/<%= base_name %>/javascripts"
59
- controller.public_path_for(:stylesheet).should == "/slices/<%= base_name %>/stylesheets"
60
-
61
- controller.image_path.should == "/slices/<%= base_name %>/images"
62
- controller.javascript_path.should == "/slices/<%= base_name %>/javascripts"
63
- controller.stylesheet_path.should == "/slices/<%= base_name %>/stylesheets"
64
- end
65
-
66
- it "should have a slice-specific _template_root" do
67
- <%= module_name %>::Main._template_root.should == <%= module_name %>.dir_for(:view)
68
- <%= module_name %>::Main._template_root.should == <%= module_name %>::Application._template_root
69
- end
70
-
71
- end