merb-slices 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Generators +4 -0
- data/LICENSE +20 -0
- data/README +102 -0
- data/Rakefile +65 -0
- data/TODO +0 -0
- data/lib/generators/base.rb +21 -0
- data/lib/generators/full.rb +21 -0
- data/lib/generators/templates/full/LICENSE +20 -0
- data/lib/generators/templates/full/README +170 -0
- data/lib/generators/templates/full/Rakefile +48 -0
- data/lib/generators/templates/full/TODO +15 -0
- data/lib/generators/templates/full/app/controllers/application.rb +5 -0
- data/lib/generators/templates/full/app/controllers/main.rb +7 -0
- data/lib/generators/templates/full/app/helpers/application_helper.rb +64 -0
- data/lib/generators/templates/full/app/views/layout/%symbol_name%.html.erb +16 -0
- data/lib/generators/templates/full/app/views/main/index.html.erb +1 -0
- data/lib/generators/templates/full/lib/%base_name%.rb +78 -0
- data/lib/generators/templates/full/lib/%base_name%/merbtasks.rb +166 -0
- data/lib/generators/templates/full/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/templates/full/public/javascripts/master.js +0 -0
- data/lib/generators/templates/full/public/stylesheets/master.css +2 -0
- data/lib/generators/templates/full/spec/%base_name%_spec.rb +130 -0
- data/lib/generators/templates/full/spec/controllers/main_spec.rb +61 -0
- data/lib/generators/templates/full/spec/spec_helper.rb +44 -0
- data/lib/generators/templates/full/stubs/app/controllers/application.rb +2 -0
- data/lib/generators/templates/full/stubs/app/controllers/main.rb +2 -0
- data/lib/generators/templates/thin/LICENSE +20 -0
- data/lib/generators/templates/thin/README +130 -0
- data/lib/generators/templates/thin/Rakefile +46 -0
- data/lib/generators/templates/thin/TODO +7 -0
- data/lib/generators/templates/thin/application.rb +36 -0
- data/lib/generators/templates/thin/lib/%base_name%.rb +93 -0
- data/lib/generators/templates/thin/lib/%base_name%/merbtasks.rb +106 -0
- data/lib/generators/templates/thin/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/templates/thin/public/javascripts/master.js +0 -0
- data/lib/generators/templates/thin/public/stylesheets/master.css +2 -0
- data/lib/generators/templates/thin/stubs/application.rb +9 -0
- data/lib/generators/templates/thin/views/layout/%symbol_name%.html.erb +16 -0
- data/lib/generators/templates/thin/views/main/index.html.erb +1 -0
- data/lib/generators/templates/very_thin/LICENSE +20 -0
- data/lib/generators/templates/very_thin/README +110 -0
- data/lib/generators/templates/very_thin/Rakefile +46 -0
- data/lib/generators/templates/very_thin/TODO +7 -0
- data/lib/generators/templates/very_thin/application.rb +36 -0
- data/lib/generators/templates/very_thin/lib/%base_name%.rb +89 -0
- data/lib/generators/templates/very_thin/lib/%base_name%/merbtasks.rb +106 -0
- data/lib/generators/templates/very_thin/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/thin.rb +21 -0
- data/lib/generators/very_thin.rb +21 -0
- data/lib/merb-slices.rb +126 -0
- data/lib/merb-slices/controller_mixin.rb +129 -0
- data/lib/merb-slices/merbtasks.rb +19 -0
- data/lib/merb-slices/module.rb +338 -0
- data/lib/merb-slices/module_mixin.rb +535 -0
- data/lib/merb-slices/router_ext.rb +75 -0
- data/spec/full_slice_generator_spec.rb +21 -0
- data/spec/merb-slice_spec.rb +7 -0
- data/spec/slice_generator_spec.rb +22 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/thin_slice_generator_spec.rb +21 -0
- data/spec/very_thin_slice_generator_spec.rb +21 -0
- metadata +157 -0
data/Generators
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Fabien Franzen <info@loobmedia.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
Merb-Slices
|
2
|
+
===========
|
3
|
+
|
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
|
6
|
+
from your main app. In effect, a Slice is just like a regular Merb MVC
|
7
|
+
application, both in functionality as well as in structure.
|
8
|
+
|
9
|
+
When you generate a Slice stub structure, a module is setup to serve as a
|
10
|
+
namespace for your controller, models, helpers etc. This ensures maximum
|
11
|
+
encapsulation. You could say a Slice is a mixture between a Merb plugin (a
|
12
|
+
Gem) and a Merb application, reaping the benefits of both.
|
13
|
+
|
14
|
+
A host application can 'mount' a Slice inside the router, which means you have
|
15
|
+
full over control how it integrates. By default a Slice's routes are prefixed
|
16
|
+
by its name (a router :namespace), but you can easily provide your own prefix
|
17
|
+
or leave it out, mounting it at the root of your url-schema. You can even
|
18
|
+
mount a Slice multiple times and give extra parameters to customize an
|
19
|
+
instance's behaviour.
|
20
|
+
|
21
|
+
A Slice's Application controller uses controller_for_slice to setup slice
|
22
|
+
specific behaviour, which mainly affects cascaded view handling. Additionaly,
|
23
|
+
this method is available to any kind of controller, so it can be used for
|
24
|
+
Merb Mailer too for example.
|
25
|
+
|
26
|
+
There are many ways which let you customize a Slice's functionality and
|
27
|
+
appearance without ever touching the Gem-level code itself. It's not only easy
|
28
|
+
to add template/layout overrides, you can also add/modify controllers, models
|
29
|
+
and other runtime code from within the host application.
|
30
|
+
|
31
|
+
To create your own Slice run this (somewhere outside of your merb app):
|
32
|
+
|
33
|
+
$ merb-gen slice <your-lowercase-slice-name>
|
34
|
+
|
35
|
+
------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
Instructions for installation of an imaginary 'BlogSlice' slice:
|
38
|
+
|
39
|
+
file: config/init.rb
|
40
|
+
|
41
|
+
# add the slice as a regular dependency
|
42
|
+
|
43
|
+
dependency 'blog-slice'
|
44
|
+
|
45
|
+
# if needed, configure which slices to load and in which order
|
46
|
+
|
47
|
+
Merb::Plugins.config[:merb_slices] = { :queue => ["BlogSlice", ...] }
|
48
|
+
|
49
|
+
# optionally configure the plugins in a before_app_loads callback
|
50
|
+
|
51
|
+
Merb::BootLoader.before_app_loads do
|
52
|
+
|
53
|
+
Merb::Slices::config[:blog_slice] = { ... }
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
file: config/router.rb
|
58
|
+
|
59
|
+
# example: /blog-slice/:controller/:action/:id
|
60
|
+
|
61
|
+
r.add_slice(:BlogSlice)
|
62
|
+
|
63
|
+
# example: /foo/:controller/:action/:id
|
64
|
+
|
65
|
+
r.add_slice(:BlogSlice, 'foo') # same as :path => 'foo'
|
66
|
+
|
67
|
+
# example: /:lang/:controller/:action/:id (with :a param set)
|
68
|
+
|
69
|
+
r.add_slice(:BlogSlice, :path => ':lang', :params => { :a => 'b' })
|
70
|
+
|
71
|
+
# example: /:controller/:action/:id
|
72
|
+
|
73
|
+
r.slice(:BlogSlice)
|
74
|
+
|
75
|
+
Normally you should also run the following rake task:
|
76
|
+
|
77
|
+
rake slices:blog_slice:install
|
78
|
+
|
79
|
+
------------------------------------------------------------------------------
|
80
|
+
|
81
|
+
You can put your application-level overrides in:
|
82
|
+
|
83
|
+
host-app/slices/blog-slice/app - controllers, models, views ...
|
84
|
+
|
85
|
+
Templates are located in this order:
|
86
|
+
|
87
|
+
1. host-app/slices/blog-slice/app/views/*
|
88
|
+
2. gems/blog-slice/app/views/*
|
89
|
+
3. host-app/app/views/*
|
90
|
+
|
91
|
+
You can use the host application's layout by configuring the
|
92
|
+
blog-slice slice in a before_app_loads block:
|
93
|
+
|
94
|
+
Merb::Slices.config[:blog_slice] = { :layout => :application }
|
95
|
+
|
96
|
+
By default :blog_slice is used. If you need to override
|
97
|
+
stylesheets or javascripts, just specify your own files in your layout
|
98
|
+
instead/in addition to the ones supplied (if any) in
|
99
|
+
host-app/public/slices/blog-slice.
|
100
|
+
|
101
|
+
In any case don't edit those files directly as they may be clobbered any time
|
102
|
+
rake blog_slice:install is run.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "extlib"
|
4
|
+
require 'merb-core/tasks/merb_rake_helper'
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
##############################################################################
|
8
|
+
# Package && release
|
9
|
+
##############################################################################
|
10
|
+
RUBY_FORGE_PROJECT = "merb"
|
11
|
+
PROJECT_URL = "http://merbivore.com"
|
12
|
+
PROJECT_SUMMARY = "Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application."
|
13
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY
|
14
|
+
|
15
|
+
GEM_AUTHOR = "Fabien Franzen"
|
16
|
+
GEM_EMAIL = "info@fabien.be"
|
17
|
+
|
18
|
+
GEM_NAME = "merb-slices"
|
19
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
20
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
|
21
|
+
|
22
|
+
RELEASE_NAME = "REL #{GEM_VERSION}"
|
23
|
+
|
24
|
+
require "extlib/tasks/release"
|
25
|
+
|
26
|
+
spec = Gem::Specification.new do |s|
|
27
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
28
|
+
s.name = GEM_NAME
|
29
|
+
s.version = GEM_VERSION
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.has_rdoc = true
|
32
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
33
|
+
s.summary = PROJECT_SUMMARY
|
34
|
+
s.description = PROJECT_DESCRIPTION
|
35
|
+
s.author = GEM_AUTHOR
|
36
|
+
s.email = GEM_EMAIL
|
37
|
+
s.homepage = PROJECT_URL
|
38
|
+
s.add_dependency('merb-core', '>= 0.9.4')
|
39
|
+
s.require_path = 'lib'
|
40
|
+
s.files = %w(LICENSE README Rakefile Generators TODO) + Dir.glob("{lib,spec}/**/*")
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
44
|
+
pkg.gem_spec = spec
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Install the gem"
|
48
|
+
task :install => [:package] do
|
49
|
+
sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
|
50
|
+
end
|
51
|
+
|
52
|
+
namespace :jruby do
|
53
|
+
|
54
|
+
desc "Run :package and install the resulting .gem with jruby"
|
55
|
+
task :install => :package do
|
56
|
+
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Run all specs"
|
62
|
+
Spec::Rake::SpecTask.new("specs") do |t|
|
63
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
64
|
+
t.spec_files = Dir["spec/**/*_spec.rb"].sort
|
65
|
+
end
|
data/TODO
ADDED
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class SliceGenerator < Generator
|
4
|
+
|
5
|
+
option :thin, :as => :boolean, :desc => 'Generates a thin slice'
|
6
|
+
option :very_thin, :as => :boolean, :desc => 'Generates an even thinner slice'
|
7
|
+
|
8
|
+
desc <<-DESC
|
9
|
+
Generates a merb slice.
|
10
|
+
DESC
|
11
|
+
|
12
|
+
first_argument :name, :required => true
|
13
|
+
|
14
|
+
invoke :full_slice, :thin => nil, :very_thin => nil
|
15
|
+
invoke :thin_slice, :thin => true
|
16
|
+
invoke :very_thin_slice, :very_thin => true
|
17
|
+
end
|
18
|
+
|
19
|
+
add :slice, SliceGenerator
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class FullSliceGenerator < NamedGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(File.dirname(__FILE__), 'templates', 'full')
|
7
|
+
end
|
8
|
+
|
9
|
+
glob!
|
10
|
+
|
11
|
+
first_argument :name, :required => true
|
12
|
+
|
13
|
+
def destination_root
|
14
|
+
File.join(@destination_root, base_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
add_private :full_slice, FullSliceGenerator
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) <%= Time.now.year %> YOUR NAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,170 @@
|
|
1
|
+
<%= module_name %>
|
2
|
+
<%= "=" * module_name.size %>
|
3
|
+
|
4
|
+
A slice for the Merb framework.
|
5
|
+
|
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
|
+
|
62
|
+
|
63
|
+
To see all available tasks for <%= module_name %> run:
|
64
|
+
|
65
|
+
rake -T slices:<%= symbol_name %>
|
66
|
+
|
67
|
+
------------------------------------------------------------------------------
|
68
|
+
|
69
|
+
Instructions for installation:
|
70
|
+
|
71
|
+
file: config/init.rb
|
72
|
+
|
73
|
+
# add the slice as a regular dependency
|
74
|
+
|
75
|
+
dependency '<%= base_name %>'
|
76
|
+
|
77
|
+
# if needed, configure which slices to load and in which order
|
78
|
+
|
79
|
+
Merb::Plugins.config[:merb_slices] = { :queue => ["<%= module_name %>", ...] }
|
80
|
+
|
81
|
+
# optionally configure the plugins in a before_app_loads callback
|
82
|
+
|
83
|
+
Merb::BootLoader.before_app_loads do
|
84
|
+
|
85
|
+
Merb::Slices::config[:<%= symbol_name %>][:option] = value
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
file: config/router.rb
|
90
|
+
|
91
|
+
# example: /<%= symbol_name %>/:controller/:action/:id
|
92
|
+
|
93
|
+
r.add_slice(:<%= module_name %>)
|
94
|
+
|
95
|
+
# example: /foo/:controller/:action/:id
|
96
|
+
|
97
|
+
r.add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
|
98
|
+
|
99
|
+
# example: /:lang/:controller/:action/:id (with :a param set)
|
100
|
+
|
101
|
+
r.add_slice(:<%= module_name %>, :path => ':lang', :params => { :a => 'b' })
|
102
|
+
|
103
|
+
# example: /:controller/:action/:id
|
104
|
+
|
105
|
+
r.slice(:<%= module_name %>)
|
106
|
+
|
107
|
+
Normally you should also run the following rake task:
|
108
|
+
|
109
|
+
rake slices:<%= symbol_name %>:install
|
110
|
+
|
111
|
+
------------------------------------------------------------------------------
|
112
|
+
|
113
|
+
You can put your application-level overrides in:
|
114
|
+
|
115
|
+
host-app/slices/<%= base_name %>/app - controllers, models, views ...
|
116
|
+
|
117
|
+
Templates are located in this order:
|
118
|
+
|
119
|
+
1. host-app/slices/<%= base_name %>/app/views/*
|
120
|
+
2. gems/<%= base_name %>/app/views/*
|
121
|
+
3. host-app/app/views/*
|
122
|
+
|
123
|
+
You can use the host application's layout by configuring the
|
124
|
+
<%= base_name %> slice in a before_app_loads block:
|
125
|
+
|
126
|
+
Merb::Slices.config[:<%= symbol_name %>] = { :layout => :application }
|
127
|
+
|
128
|
+
By default :<%= symbol_name %> is used. If you need to override
|
129
|
+
stylesheets or javascripts, just specify your own files in your layout
|
130
|
+
instead/in addition to the ones supplied (if any) in
|
131
|
+
host-app/public/slices/<%= base_name %>.
|
132
|
+
|
133
|
+
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>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require 'merb-core/version'
|
5
|
+
require 'merb-core/test/tasks/spectasks'
|
6
|
+
require 'merb-core/tasks/merb_rake_helper'
|
7
|
+
|
8
|
+
NAME = "<%= base_name %>"
|
9
|
+
AUTHOR = "Your Name"
|
10
|
+
EMAIL = "Your Email"
|
11
|
+
HOMEPAGE = "http://merbivore.com/"
|
12
|
+
SUMMARY = "Merb Slice that provides ..."
|
13
|
+
GEM_VERSION = "<%= Merb::VERSION %>"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.rubyforge_project = 'merb'
|
17
|
+
s.name = NAME
|
18
|
+
s.version = GEM_VERSION
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.has_rdoc = true
|
21
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
22
|
+
s.summary = SUMMARY
|
23
|
+
s.description = s.summary
|
24
|
+
s.author = AUTHOR
|
25
|
+
s.email = EMAIL
|
26
|
+
s.homepage = HOMEPAGE
|
27
|
+
s.add_dependency('merb-slices', '>= <%= Merb::VERSION %>')
|
28
|
+
s.require_path = 'lib'
|
29
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
33
|
+
pkg.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Install <%= module_name %> as a gem"
|
37
|
+
task :install => [:package] do
|
38
|
+
sh %{#{sudo} gem install pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :jruby do
|
42
|
+
|
43
|
+
desc "Run :package and install the resulting .gem with jruby"
|
44
|
+
task :install => :package do
|
45
|
+
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|