merb-slices 0.9.8 → 0.9.9
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/README +2 -2
- data/Rakefile +4 -2
- data/bin/slice +3 -1
- data/lib/generators/base.rb +5 -0
- data/lib/generators/full.rb +8 -0
- data/lib/generators/templates/common/LICENSE +1 -1
- data/lib/generators/templates/common/Rakefile +9 -1
- data/lib/generators/templates/full/README +2 -2
- data/lib/generators/templates/full/Rakefile +7 -16
- data/lib/generators/templates/full/lib/%base_name%.rb +3 -1
- data/lib/generators/templates/full/spec/controllers/main_spec.rb +1 -1
- data/lib/generators/templates/thin/README +2 -2
- data/lib/generators/templates/thin/lib/%base_name%.rb +3 -1
- data/lib/generators/templates/very_thin/README +2 -2
- data/lib/generators/templates/very_thin/lib/%base_name%.rb +3 -1
- data/lib/generators/thin.rb +3 -0
- data/lib/generators/very_thin.rb +3 -0
- data/lib/merb-slices/controller_mixin.rb +36 -0
- data/lib/merb-slices/module.rb +1 -1
- data/lib/merb-slices/router_ext.rb +64 -71
- data/lib/merb-slices.rb +1 -1
- data/spec/full_slice_spec.rb +1 -1
- data/spec/merb-slice_spec.rb +10 -6
- data/spec/slices/full-test-slice/LICENSE +1 -1
- data/spec/slices/full-test-slice/README +2 -2
- data/spec/slices/full-test-slice/Rakefile +3 -15
- data/spec/slices/full-test-slice/lib/full-test-slice.rb +3 -1
- data/spec/slices/thin-test-slice/LICENSE +1 -1
- data/spec/slices/thin-test-slice/README +2 -2
- data/spec/slices/thin-test-slice/lib/thin-test-slice.rb +3 -1
- data/spec/slices/very-thin-test-slice/LICENSE +1 -1
- data/spec/slices/very-thin-test-slice/README +2 -2
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice.rb +3 -1
- data/spec/spec_helper.rb +10 -0
- data/spec/thin_slice_spec.rb +1 -1
- data/spec/very_thin_slice_spec.rb +1 -1
- metadata +3 -3
data/README
CHANGED
|
@@ -64,9 +64,9 @@ add_slice(:BlogSlice)
|
|
|
64
64
|
|
|
65
65
|
add_slice(:BlogSlice, 'foo') # same as :path => 'foo'
|
|
66
66
|
|
|
67
|
-
# example: /:lang/:controller/:action/:id
|
|
67
|
+
# example: /:lang/:controller/:action/:id
|
|
68
68
|
|
|
69
|
-
add_slice(:BlogSlice, :path => ':lang'
|
|
69
|
+
add_slice(:BlogSlice, :path => ':lang')
|
|
70
70
|
|
|
71
71
|
# example: /:controller/:action/:id
|
|
72
72
|
|
data/Rakefile
CHANGED
|
@@ -4,6 +4,8 @@ require "extlib"
|
|
|
4
4
|
require 'merb-core/tasks/merb_rake_helper'
|
|
5
5
|
require "spec/rake/spectask"
|
|
6
6
|
|
|
7
|
+
require File.join(File.dirname(__FILE__), "../merb-core/lib/merb-core/version.rb")
|
|
8
|
+
|
|
7
9
|
##############################################################################
|
|
8
10
|
# Package && release
|
|
9
11
|
##############################################################################
|
|
@@ -17,7 +19,7 @@ GEM_EMAIL = "info@fabien.be"
|
|
|
17
19
|
|
|
18
20
|
GEM_NAME = "merb-slices"
|
|
19
21
|
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
|
20
|
-
GEM_VERSION =
|
|
22
|
+
GEM_VERSION = Merb::VERSION + PKG_BUILD
|
|
21
23
|
|
|
22
24
|
RELEASE_NAME = "REL #{GEM_VERSION}"
|
|
23
25
|
|
|
@@ -35,7 +37,7 @@ spec = Gem::Specification.new do |s|
|
|
|
35
37
|
s.author = GEM_AUTHOR
|
|
36
38
|
s.email = GEM_EMAIL
|
|
37
39
|
s.homepage = PROJECT_URL
|
|
38
|
-
s.add_dependency('merb-core', '>= 0.9.
|
|
40
|
+
s.add_dependency('merb-core', '>= 0.9.9')
|
|
39
41
|
s.require_path = 'lib'
|
|
40
42
|
s.files = %w(LICENSE README Rakefile Generators TODO) + Dir.glob("{lib,spec}/**/*")
|
|
41
43
|
s.bindir = "bin"
|
data/bin/slice
CHANGED
|
@@ -16,9 +16,11 @@ Merb::Config.use { |c|
|
|
|
16
16
|
|
|
17
17
|
if File.exists?(slice_file = File.join(__DIR__, 'lib', "#{slice_name}.rb"))
|
|
18
18
|
Merb::BootLoader.before_app_loads do
|
|
19
|
-
# See Merb::Slices::ModuleMixin - $SLICE_MODULE is used as a flag
|
|
20
19
|
$SLICE_MODULE = Merb::Slices.filename2module(slice_file)
|
|
21
20
|
require slice_file
|
|
21
|
+
end
|
|
22
|
+
Merb::BootLoader.after_app_loads do
|
|
23
|
+
# See Merb::Slices::ModuleMixin - $SLICE_MODULE is used as a flag
|
|
22
24
|
Merb::Router.prepare do
|
|
23
25
|
slice($SLICE_MODULE)
|
|
24
26
|
slice_id = slice_name.gsub('-', '_').to_sym
|
data/lib/generators/base.rb
CHANGED
data/lib/generators/full.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module Merb::Generators
|
|
2
2
|
|
|
3
3
|
class FullSliceGenerator < BaseSliceGenerator
|
|
4
|
+
|
|
5
|
+
def initialize(*args)
|
|
6
|
+
Merb.disable(:initfile)
|
|
7
|
+
super
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
def self.source_root
|
|
6
11
|
File.join(File.dirname(__FILE__), 'templates', 'full')
|
|
@@ -19,6 +24,9 @@ module Merb::Generators
|
|
|
19
24
|
|
|
20
25
|
first_argument :name, :required => true
|
|
21
26
|
|
|
27
|
+
option :testing_framework, :default => :rspec,
|
|
28
|
+
:desc => 'Testing framework to use (one of: rspec, test_unit).'
|
|
29
|
+
|
|
22
30
|
def destination_root
|
|
23
31
|
File.join(@destination_root, base_name)
|
|
24
32
|
end
|
|
@@ -47,4 +47,12 @@ task :gemspec do
|
|
|
47
47
|
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
|
48
48
|
file.puts spec.to_ruby
|
|
49
49
|
end
|
|
50
|
-
end
|
|
50
|
+
end
|
|
51
|
+
<% if testing_framework.to_sym == :rspec %>
|
|
52
|
+
require 'spec/rake/spectask'
|
|
53
|
+
require 'merb-core/test/tasks/spectasks'
|
|
54
|
+
desc 'Default: run spec examples'
|
|
55
|
+
task :default => 'spec'
|
|
56
|
+
<% elsif testing_framework.to_sym == :test_unit %>
|
|
57
|
+
require 'rake/testtask'
|
|
58
|
+
<% end %>
|
|
@@ -96,9 +96,9 @@ add_slice(:<%= module_name %>)
|
|
|
96
96
|
|
|
97
97
|
add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
|
|
98
98
|
|
|
99
|
-
# example: /:lang/:controller/:action/:id
|
|
99
|
+
# example: /:lang/:controller/:action/:id
|
|
100
100
|
|
|
101
|
-
add_slice(:<%= module_name %>, :path => ':lang'
|
|
101
|
+
add_slice(:<%= module_name %>, :path => ':lang')
|
|
102
102
|
|
|
103
103
|
# example: /:controller/:action/:id
|
|
104
104
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'rake/gempackagetask'
|
|
3
|
-
require 'spec/rake/spectask'
|
|
4
3
|
|
|
5
4
|
require 'merb-core'
|
|
6
5
|
require 'merb-core/tasks/merb'
|
|
7
|
-
require 'merb-core/test/tasks/spectasks'
|
|
8
6
|
|
|
9
7
|
GEM_NAME = "<%= base_name %>"
|
|
10
8
|
AUTHOR = "Your Name"
|
|
@@ -50,18 +48,11 @@ task :gemspec do
|
|
|
50
48
|
file.puts spec.to_ruby
|
|
51
49
|
end
|
|
52
50
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
t.spec_opts = ["-cfs"]
|
|
57
|
-
t.spec_files = begin
|
|
58
|
-
if ENV["TASK"]
|
|
59
|
-
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
|
|
60
|
-
else
|
|
61
|
-
FileList['spec/**/*_spec.rb']
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
51
|
+
<% if testing_framework.to_sym == :rspec %>
|
|
52
|
+
require 'spec/rake/spectask'
|
|
53
|
+
require 'merb-core/test/tasks/spectasks'
|
|
66
54
|
desc 'Default: run spec examples'
|
|
67
|
-
task :default => 'spec'
|
|
55
|
+
task :default => 'spec'
|
|
56
|
+
<% elsif testing_framework.to_sym == :test_unit %>
|
|
57
|
+
require 'rake/testtask'
|
|
58
|
+
<% end %>
|
|
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
|
23
23
|
# Slice metadata
|
|
24
24
|
self.description = "<%= module_name %> is a chunky Merb slice!"
|
|
25
25
|
self.version = "0.0.1"
|
|
26
|
-
self.author = "
|
|
26
|
+
self.author = "Engine Yard"
|
|
27
27
|
|
|
28
28
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
29
29
|
# right after a slice's classes have been loaded internally.
|
|
@@ -56,6 +56,8 @@ if defined?(Merb::Plugins)
|
|
|
56
56
|
scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index)
|
|
57
57
|
# the slice is mounted at /<%= base_name %> - note that it comes before default_routes
|
|
58
58
|
scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
|
|
59
|
+
# enable slice-level default routes by default
|
|
60
|
+
scope.default_routes
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
end
|
|
@@ -48,7 +48,7 @@ describe "<%= module_name %>::Main (controller)" do
|
|
|
48
48
|
controller.slice_url(:index, :format => 'html').should == url
|
|
49
49
|
|
|
50
50
|
url = controller.url(:<%= symbol_name %>_home)
|
|
51
|
-
url.should == "/<%= base_name
|
|
51
|
+
url.should == "/<%= base_name %>/"
|
|
52
52
|
controller.slice_url(:home).should == url
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -81,9 +81,9 @@ add_slice(:<%= module_name %>)
|
|
|
81
81
|
|
|
82
82
|
add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
|
|
83
83
|
|
|
84
|
-
# example: /:lang/:controller/:action/:id
|
|
84
|
+
# example: /:lang/:controller/:action/:id
|
|
85
85
|
|
|
86
|
-
add_slice(:<%= module_name %>, :path => ':lang'
|
|
86
|
+
add_slice(:<%= module_name %>, :path => ':lang')
|
|
87
87
|
|
|
88
88
|
# example: /:controller/:action/:id
|
|
89
89
|
|
|
@@ -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 = "
|
|
21
|
+
self.author = "Engine Yard"
|
|
22
22
|
|
|
23
23
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
24
24
|
# right after a slice's classes have been loaded internally.
|
|
@@ -47,6 +47,8 @@ if defined?(Merb::Plugins)
|
|
|
47
47
|
# @note prefix your named routes with :<%= symbol_name %>_
|
|
48
48
|
# to avoid potential conflicts with global named routes.
|
|
49
49
|
def self.setup_router(scope)
|
|
50
|
+
# enable slice-level default routes by default
|
|
51
|
+
scope.default_routes
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
# This sets up a thin slice's structure.
|
|
@@ -61,9 +61,9 @@ add_slice(:<%= module_name %>)
|
|
|
61
61
|
|
|
62
62
|
add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
|
|
63
63
|
|
|
64
|
-
# example: /:lang/:controller/:action/:id
|
|
64
|
+
# example: /:lang/:controller/:action/:id
|
|
65
65
|
|
|
66
|
-
add_slice(:<%= module_name %>, :path => ':lang'
|
|
66
|
+
add_slice(:<%= module_name %>, :path => ':lang')
|
|
67
67
|
|
|
68
68
|
# example: /:controller/:action/:id
|
|
69
69
|
|
|
@@ -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 = "
|
|
20
|
+
self.author = "Engine Yard"
|
|
21
21
|
|
|
22
22
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
23
23
|
# right after a slice's classes have been loaded internally.
|
|
@@ -46,6 +46,8 @@ if defined?(Merb::Plugins)
|
|
|
46
46
|
# @note prefix your named routes with :<%= symbol_name %>_
|
|
47
47
|
# to avoid potential conflicts with global named routes.
|
|
48
48
|
def self.setup_router(scope)
|
|
49
|
+
# enable slice-level default routes by default
|
|
50
|
+
scope.default_routes
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
# This sets up a very thin slice's structure.
|
data/lib/generators/thin.rb
CHANGED
|
@@ -22,6 +22,9 @@ module Merb::Generators
|
|
|
22
22
|
|
|
23
23
|
first_argument :name, :required => true
|
|
24
24
|
|
|
25
|
+
option :testing_framework, :default => :rspec,
|
|
26
|
+
:desc => 'Testing framework to use (one of: rspec, test_unit).'
|
|
27
|
+
|
|
25
28
|
def destination_root
|
|
26
29
|
File.join(@destination_root, base_name)
|
|
27
30
|
end
|
data/lib/generators/very_thin.rb
CHANGED
|
@@ -19,6 +19,9 @@ module Merb::Generators
|
|
|
19
19
|
|
|
20
20
|
first_argument :name, :required => true
|
|
21
21
|
|
|
22
|
+
option :testing_framework, :default => :rspec,
|
|
23
|
+
:desc => 'Testing framework to use (one of: rspec, test_unit).'
|
|
24
|
+
|
|
22
25
|
def destination_root
|
|
23
26
|
File.join(@destination_root, base_name)
|
|
24
27
|
end
|
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
module Merb
|
|
2
2
|
module Slices
|
|
3
3
|
|
|
4
|
+
module Support
|
|
5
|
+
|
|
6
|
+
# This module should be explicitly included into a controller,
|
|
7
|
+
# for example in Application (the main controller of your app).
|
|
8
|
+
# It contains optional methods for slice/plugin developers.
|
|
9
|
+
|
|
10
|
+
# Generate a slice url - takes the slice's :path_prefix into account.
|
|
11
|
+
#
|
|
12
|
+
# @param slice_name<Symbol>
|
|
13
|
+
# The name of the slice - in identifier_sym format (underscored).
|
|
14
|
+
# @param *args<Array[Symbol,Hash]>
|
|
15
|
+
# There are several possibilities regarding arguments:
|
|
16
|
+
# - when passing a Hash only, the :default route of the current
|
|
17
|
+
# slice will be used
|
|
18
|
+
# - when a Symbol is passed, it's used as the route name
|
|
19
|
+
# - a Hash with additional params can optionally be passed
|
|
20
|
+
#
|
|
21
|
+
# @return <String> A uri based on the requested slice.
|
|
22
|
+
#
|
|
23
|
+
# @example slice_url(:awesome, :format => 'html')
|
|
24
|
+
# @example slice_url(:forum, :posts, :format => 'xml')
|
|
25
|
+
def slice_url(slice_name, *args)
|
|
26
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
|
27
|
+
route_name = args[0].is_a?(Symbol) ? args.shift : :default
|
|
28
|
+
|
|
29
|
+
routes = Merb::Slices.named_routes[slice_name]
|
|
30
|
+
unless routes && route = routes[route_name]
|
|
31
|
+
raise Merb::Router::GenerationError, "Named route not found: #{route_name}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
args.push(opts)
|
|
35
|
+
route.generate(args, params)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
4
40
|
module ControllerMixin
|
|
5
41
|
|
|
6
42
|
def self.included(klass)
|
data/lib/merb-slices/module.rb
CHANGED
|
@@ -39,7 +39,7 @@ module Merb
|
|
|
39
39
|
slice_path = File.expand_path(File.dirname(slice_file) + '/..')
|
|
40
40
|
# check if slice_path exists instead of just the module name - more flexible
|
|
41
41
|
if !self.paths.include?(slice_path) || force
|
|
42
|
-
Merb.logger.
|
|
42
|
+
Merb.logger.verbose!("Registered slice '#{module_name}' located at #{slice_path}") if force
|
|
43
43
|
self.files[module_name] = slice_file
|
|
44
44
|
self.paths[module_name] = slice_path
|
|
45
45
|
slice_mod = setup_module(module_name)
|
|
@@ -1,78 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
class Router
|
|
3
|
-
|
|
4
|
-
class Behavior
|
|
1
|
+
Merb::Router.extensions do
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
# Add all known slices to the router
|
|
4
|
+
#
|
|
5
|
+
# By combining this with Merb::Slices.activate_by_file and Merb::Slices.deactivate
|
|
6
|
+
# one can enable/disable slices at runtime, without restarting your app.
|
|
7
|
+
#
|
|
8
|
+
# @param config<Hash>
|
|
9
|
+
# Optional hash, mapping slice module names to their settings;
|
|
10
|
+
# set :path (or use a string) if you want to override what appears on the url.
|
|
11
|
+
#
|
|
12
|
+
# @yield A new Behavior instance is yielded in the block for nested routes.
|
|
13
|
+
# @yieldparam ns<Behavior> The namespace behavior object.
|
|
14
|
+
#
|
|
15
|
+
# @example all_slices('BlogSlice' => 'blog', 'ForumSlice' => { :path => 'forum' })
|
|
16
|
+
#
|
|
17
|
+
# @note The block is yielded for each slice individually.
|
|
18
|
+
def all_slices(config = {}, &block)
|
|
19
|
+
Merb::Slices.slice_names.each { |module_name| add_slice(module_name, config[module_name] || {}, &block) }
|
|
20
|
+
end
|
|
21
|
+
alias :add_slices :all_slices
|
|
22
|
+
|
|
23
|
+
# Add a Slice in a router namespace
|
|
24
|
+
#
|
|
25
|
+
# @param slice_module<String, Symbol, Module> A Slice module to mount.
|
|
26
|
+
# @param options<Hash, String> Optional hash, set :path if you want to override what appears on the url.
|
|
27
|
+
#
|
|
28
|
+
# @yield A new Behavior instance is yielded in the block for nested routes - runs before the slice routes are setup.
|
|
29
|
+
# @yieldparam ns<Behavior> The namespace behavior object.
|
|
30
|
+
#
|
|
31
|
+
# @return <Behaviour> The current router context.
|
|
32
|
+
#
|
|
33
|
+
# @note If a slice has no routes at all, the activate hook won't be executed.
|
|
34
|
+
#
|
|
35
|
+
# @note Normally you should specify the slice_module using a String or Symbol
|
|
36
|
+
# this ensures that your module can be removed from the router at runtime.
|
|
37
|
+
def add_slice(slice_module, options = {}, &block)
|
|
38
|
+
if Merb::Slices.exists?(slice_module)
|
|
39
|
+
options = { :path => options } if options.is_a?(String)
|
|
40
|
+
slice_module = Object.full_const_get(slice_module.to_s.camel_case) if slice_module.class.in?(String, Symbol)
|
|
41
|
+
namespace = options[:namespace] || slice_module.identifier_sym
|
|
42
|
+
options[:path] ||= options[:path_prefix] || slice_module[:path_prefix] || options[:namespace] || slice_module.identifier
|
|
43
|
+
options[:prepend_routes] = block if block_given?
|
|
44
|
+
slice_module[:path_prefix] = options[:path]
|
|
45
|
+
Merb.logger.verbose!("Mounting slice #{slice_module} at /#{options[:path]}")
|
|
25
46
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
# @param slice_module<String, Symbol, Module> A Slice module to mount.
|
|
29
|
-
# @param options<Hash, String> Optional hash, set :path if you want to override what appears on the url.
|
|
30
|
-
#
|
|
31
|
-
# @yield A new Behavior instance is yielded in the block for nested routes - runs before the slice routes are setup.
|
|
32
|
-
# @yieldparam ns<Behavior> The namespace behavior object.
|
|
33
|
-
#
|
|
34
|
-
# @return <Behaviour> The current router context.
|
|
35
|
-
#
|
|
36
|
-
# @note If a slice has no routes at all, the activate hook won't be executed.
|
|
37
|
-
#
|
|
38
|
-
# @note Normally you should specify the slice_module using a String or Symbol
|
|
39
|
-
# this ensures that your module can be removed from the router at runtime.
|
|
40
|
-
def add_slice(slice_module, options = {}, &block)
|
|
41
|
-
if Merb::Slices.exists?(slice_module)
|
|
42
|
-
options = { :path => options } if options.is_a?(String)
|
|
43
|
-
slice_module = Object.full_const_get(slice_module.to_s.camel_case) if slice_module.class.in?(String, Symbol)
|
|
44
|
-
namespace = options[:namespace] || slice_module.identifier_sym
|
|
45
|
-
options[:path] ||= options[:path_prefix] || slice_module[:path_prefix] || options[:namespace] || slice_module.identifier
|
|
46
|
-
options[:default_routes] = true unless options.key?(:default_routes)
|
|
47
|
-
options[:prepend_routes] = block if block_given?
|
|
48
|
-
slice_module[:path_prefix] = options[:path]
|
|
49
|
-
Merb.logger.info!("Mounting slice #{slice_module} at /#{options[:path]}")
|
|
50
|
-
|
|
51
|
-
# reset the inherited controller prefix - especially for 'slice' entries (see below)
|
|
52
|
-
@options[:controller_prefix] = nil if options.delete(:reset_controller_prefix)
|
|
53
|
-
|
|
54
|
-
# setup routes - capture the slice's routes for easy reference
|
|
55
|
-
self.namespace(namespace, options.except(:default_routes, :prepend_routes, :append_routes, :path_prefix)) do |ns|
|
|
56
|
-
Merb::Slices.named_routes[slice_module.identifier_sym] = ns.capture do
|
|
57
|
-
options[:prepend_routes].call(ns) if options[:prepend_routes].respond_to?(:call)
|
|
58
|
-
slice_module.setup_router(ns) # setup the routes from the slice itself
|
|
59
|
-
options[:append_routes].call(ns) if options[:append_routes].respond_to?(:call)
|
|
60
|
-
ns.default_routes(options[:params] || {}) if options[:default_routes]
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
else
|
|
64
|
-
Merb.logger.info!("Skipped adding slice #{slice_module} to router...")
|
|
65
|
-
end
|
|
66
|
-
self
|
|
67
|
-
end
|
|
47
|
+
# reset the inherited controller prefix - especially for 'slice' entries (see below)
|
|
48
|
+
@options[:controller_prefix] = nil if options.delete(:reset_controller_prefix)
|
|
68
49
|
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
50
|
+
# setup routes - capture the slice's routes for easy reference
|
|
51
|
+
self.namespace(namespace, options.except(:default_routes, :prepend_routes, :append_routes, :path_prefix)) do |ns|
|
|
52
|
+
Merb::Slices.named_routes[slice_module.identifier_sym] = ns.capture do
|
|
53
|
+
options[:prepend_routes].call(ns) if options[:prepend_routes].respond_to?(:call)
|
|
54
|
+
slice_module.setup_router(ns) # setup the routes from the slice itself
|
|
55
|
+
options[:append_routes].call(ns) if options[:append_routes].respond_to?(:call)
|
|
56
|
+
end
|
|
74
57
|
end
|
|
75
|
-
|
|
58
|
+
else
|
|
59
|
+
Merb.logger.info!("Skipped adding slice #{slice_module} to router...")
|
|
76
60
|
end
|
|
61
|
+
self
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Insert a slice directly into the current router context.
|
|
65
|
+
#
|
|
66
|
+
# This will still setup a namespace, but doesn't set a path prefix. Only for special cases.
|
|
67
|
+
def slice(slice_module, options = {}, &block)
|
|
68
|
+
add_slice(slice_module, options.merge(:path => '', :reset_controller_prefix => true), &block)
|
|
77
69
|
end
|
|
70
|
+
|
|
78
71
|
end
|
data/lib/merb-slices.rb
CHANGED
|
@@ -96,7 +96,7 @@ if defined?(Merb::Plugins)
|
|
|
96
96
|
|
|
97
97
|
def self.run
|
|
98
98
|
Merb::Slices.each_slice do |slice|
|
|
99
|
-
Merb.logger.
|
|
99
|
+
Merb.logger.verbose!("Initializing slice '#{slice}' ...")
|
|
100
100
|
slice.init if slice.respond_to?(:init)
|
|
101
101
|
end
|
|
102
102
|
end
|
data/spec/full_slice_spec.rb
CHANGED
|
@@ -63,7 +63,7 @@ describe "A slice" do
|
|
|
63
63
|
it "should have metadata properties" do
|
|
64
64
|
FullTestSlice.description.should == "FullTestSlice is a chunky Merb slice!"
|
|
65
65
|
FullTestSlice.version.should == "0.0.1"
|
|
66
|
-
FullTestSlice.author.should == "
|
|
66
|
+
FullTestSlice.author.should == "Engine Yard"
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "should have a :named_routes property" do
|
data/spec/merb-slice_spec.rb
CHANGED
|
@@ -54,7 +54,7 @@ describe "The Merb::Router::Behavior methods" do
|
|
|
54
54
|
scope.match('/dashboard').to(:controller => 'main', :action => 'index').name(:dashboard)
|
|
55
55
|
end
|
|
56
56
|
add_slice(:thin_test_slice, 'thin') # shortcut for :path => 'thin'
|
|
57
|
-
slice(:very_thin_test_slice, :name_prefix => 'awesome'
|
|
57
|
+
slice(:very_thin_test_slice, :name_prefix => 'awesome')
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
@@ -83,11 +83,7 @@ describe "The Merb::Router::Behavior methods" do
|
|
|
83
83
|
Merb::Router.named_routes[:awesome_default].should == VeryThinTestSlice.named_routes[:default]
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
it "
|
|
87
|
-
Merb::Router.named_routes[:awesome_default].params[:foo].should == '"bar"'
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "enable url() and slice_url() respectively" do
|
|
86
|
+
it "enables url() and slice_url() respectively" do
|
|
91
87
|
controller = dispatch_to(FullTestSlice::Main, 'index')
|
|
92
88
|
controller.url(:full_test_slice_index, :format => 'html').should == '/full/index.html'
|
|
93
89
|
controller.slice_url(:full_test_slice, :index, :format => 'html').should == '/full/index.html'
|
|
@@ -98,4 +94,12 @@ describe "The Merb::Router::Behavior methods" do
|
|
|
98
94
|
controller.slice_url(:dashboard).should == '/full/dashboard'
|
|
99
95
|
end
|
|
100
96
|
|
|
97
|
+
it "enables slice_url() for Controllers that include Merb::Slices::Support" do
|
|
98
|
+
controller = dispatch_to(Merb::Test::SampleAppController, 'index')
|
|
99
|
+
controller.slice_url(:full_test_slice, :dashboard).should == '/full/dashboard'
|
|
100
|
+
params = { :controller => 'foo', :action => 'bar', :id => 'baz' }
|
|
101
|
+
controller.slice_url(:thin_test_slice, :default, params).should == '/thin/foo/bar/baz'
|
|
102
|
+
controller.slice_url(:very_thin_test_slice, :default, params).should == '/foo/bar/baz'
|
|
103
|
+
end
|
|
104
|
+
|
|
101
105
|
end
|
|
@@ -96,9 +96,9 @@ add_slice(:FullTestSlice)
|
|
|
96
96
|
|
|
97
97
|
add_slice(:FullTestSlice, 'foo') # same as :path => 'foo'
|
|
98
98
|
|
|
99
|
-
# example: /:lang/:controller/:action/:id
|
|
99
|
+
# example: /:lang/:controller/:action/:id
|
|
100
100
|
|
|
101
|
-
add_slice(:FullTestSlice, :path => ':lang'
|
|
101
|
+
add_slice(:FullTestSlice, :path => ':lang')
|
|
102
102
|
|
|
103
103
|
# example: /:controller/:action/:id
|
|
104
104
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'rake/gempackagetask'
|
|
3
|
-
require 'spec/rake/spectask'
|
|
4
3
|
|
|
5
4
|
require 'merb-core'
|
|
6
5
|
require 'merb-core/tasks/merb'
|
|
7
|
-
require 'merb-core/test/tasks/spectasks'
|
|
8
6
|
|
|
9
7
|
GEM_NAME = "full-test-slice"
|
|
10
8
|
AUTHOR = "Your Name"
|
|
@@ -51,17 +49,7 @@ task :gemspec do
|
|
|
51
49
|
end
|
|
52
50
|
end
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
t.spec_opts = ["-cfs"]
|
|
57
|
-
t.spec_files = begin
|
|
58
|
-
if ENV["TASK"]
|
|
59
|
-
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
|
|
60
|
-
else
|
|
61
|
-
FileList['spec/**/*_spec.rb']
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
52
|
+
require 'spec/rake/spectask'
|
|
53
|
+
require 'merb-core/test/tasks/spectasks'
|
|
66
54
|
desc 'Default: run spec examples'
|
|
67
|
-
task :default => 'spec'
|
|
55
|
+
task :default => 'spec'
|
|
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
|
23
23
|
# Slice metadata
|
|
24
24
|
self.description = "FullTestSlice is a chunky Merb slice!"
|
|
25
25
|
self.version = "0.0.1"
|
|
26
|
-
self.author = "
|
|
26
|
+
self.author = "Engine Yard"
|
|
27
27
|
|
|
28
28
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
29
29
|
# right after a slice's classes have been loaded internally.
|
|
@@ -56,6 +56,8 @@ if defined?(Merb::Plugins)
|
|
|
56
56
|
scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index)
|
|
57
57
|
# the slice is mounted at /full-test-slice - note that it comes before default_routes
|
|
58
58
|
scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
|
|
59
|
+
# enable slice-level default routes by default
|
|
60
|
+
scope.default_routes
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
end
|
|
@@ -81,9 +81,9 @@ add_slice(:ThinTestSlice)
|
|
|
81
81
|
|
|
82
82
|
add_slice(:ThinTestSlice, 'foo') # same as :path => 'foo'
|
|
83
83
|
|
|
84
|
-
# example: /:lang/:controller/:action/:id
|
|
84
|
+
# example: /:lang/:controller/:action/:id
|
|
85
85
|
|
|
86
|
-
add_slice(:ThinTestSlice, :path => ':lang'
|
|
86
|
+
add_slice(:ThinTestSlice, :path => ':lang')
|
|
87
87
|
|
|
88
88
|
# example: /:controller/:action/:id
|
|
89
89
|
|
|
@@ -18,7 +18,7 @@ if defined?(Merb::Plugins)
|
|
|
18
18
|
# Slice metadata
|
|
19
19
|
self.description = "ThinTestSlice is a thin Merb slice!"
|
|
20
20
|
self.version = "0.0.1"
|
|
21
|
-
self.author = "
|
|
21
|
+
self.author = "Engine Yard"
|
|
22
22
|
|
|
23
23
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
24
24
|
# right after a slice's classes have been loaded internally.
|
|
@@ -47,6 +47,8 @@ if defined?(Merb::Plugins)
|
|
|
47
47
|
# @note prefix your named routes with :thin_test_slice_
|
|
48
48
|
# to avoid potential conflicts with global named routes.
|
|
49
49
|
def self.setup_router(scope)
|
|
50
|
+
# enable slice-level default routes by default
|
|
51
|
+
scope.default_routes
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
# This sets up a thin slice's structure.
|
|
@@ -61,9 +61,9 @@ add_slice(:VeryThinTestSlice)
|
|
|
61
61
|
|
|
62
62
|
add_slice(:VeryThinTestSlice, 'foo') # same as :path => 'foo'
|
|
63
63
|
|
|
64
|
-
# example: /:lang/:controller/:action/:id
|
|
64
|
+
# example: /:lang/:controller/:action/:id
|
|
65
65
|
|
|
66
|
-
add_slice(:VeryThinTestSlice, :path => ':lang'
|
|
66
|
+
add_slice(:VeryThinTestSlice, :path => ':lang')
|
|
67
67
|
|
|
68
68
|
# example: /:controller/:action/:id
|
|
69
69
|
|
|
@@ -17,7 +17,7 @@ if defined?(Merb::Plugins)
|
|
|
17
17
|
# Slice metadata
|
|
18
18
|
self.description = "VeryThinTestSlice is a very thin Merb slice!"
|
|
19
19
|
self.version = "0.0.1"
|
|
20
|
-
self.author = "
|
|
20
|
+
self.author = "Engine Yard"
|
|
21
21
|
|
|
22
22
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
|
23
23
|
# right after a slice's classes have been loaded internally.
|
|
@@ -46,6 +46,8 @@ if defined?(Merb::Plugins)
|
|
|
46
46
|
# @note prefix your named routes with :very_thin_test_slice_
|
|
47
47
|
# to avoid potential conflicts with global named routes.
|
|
48
48
|
def self.setup_router(scope)
|
|
49
|
+
# enable slice-level default routes by default
|
|
50
|
+
scope.default_routes
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
# This sets up a very thin slice's structure.
|
data/spec/spec_helper.rb
CHANGED
|
@@ -11,6 +11,16 @@ require 'generators/very_thin'
|
|
|
11
11
|
|
|
12
12
|
module Merb
|
|
13
13
|
module Test
|
|
14
|
+
|
|
15
|
+
class SampleAppController < Merb::Controller
|
|
16
|
+
|
|
17
|
+
include Merb::Slices::Support
|
|
18
|
+
|
|
19
|
+
def index
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
14
24
|
module SliceHelper
|
|
15
25
|
|
|
16
26
|
def current_slice_root=(path)
|
data/spec/thin_slice_spec.rb
CHANGED
|
@@ -67,7 +67,7 @@ describe "A thin slice" do
|
|
|
67
67
|
it "should have metadata properties" do
|
|
68
68
|
ThinTestSlice.description.should == "ThinTestSlice is a thin Merb slice!"
|
|
69
69
|
ThinTestSlice.version.should == "0.0.1"
|
|
70
|
-
ThinTestSlice.author.should == "
|
|
70
|
+
ThinTestSlice.author.should == "Engine Yard"
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "should have a :named_routes property" do
|
|
@@ -67,7 +67,7 @@ describe "A very thin slice" do
|
|
|
67
67
|
it "should have metadata properties" do
|
|
68
68
|
VeryThinTestSlice.description.should == "VeryThinTestSlice is a very thin Merb slice!"
|
|
69
69
|
VeryThinTestSlice.version.should == "0.0.1"
|
|
70
|
-
VeryThinTestSlice.author.should == "
|
|
70
|
+
VeryThinTestSlice.author.should == "Engine Yard"
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "should have a :named_routes property" do
|
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: 0.9.
|
|
4
|
+
version: 0.9.9
|
|
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-10-
|
|
12
|
+
date: 2008-10-13 00:00:00 +03: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: 0.9.
|
|
23
|
+
version: 0.9.9
|
|
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
|