thorero-slices 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ module Merb
2
+ class Router
3
+
4
+ class Behavior
5
+
6
+ # Add all known slices to the router
7
+ #
8
+ # By combining this with Merb::Slices.activate_by_file and Merb::Slices.deactivate
9
+ # one can enable/disable slices at runtime, without restarting your app.
10
+ #
11
+ # @param config<Hash>
12
+ # Optional hash, mapping slice module names to their settings;
13
+ # set :path (or use a string) if you want to override what appears on the url.
14
+ #
15
+ # @yield A new Behavior instance is yielded in the block for nested routes.
16
+ # @yieldparam ns<Behavior> The namespace behavior object.
17
+ #
18
+ # @example r.all_slices('BlogSlice' => 'blog', 'ForumSlice' => { :path => 'forum' })
19
+ #
20
+ # @note The block is yielded for each slice individually.
21
+ def all_slices(config = {}, &block)
22
+ Merb::Slices.slice_names.each { |module_name| add_slice(module_name, config[module_name] || {}, &block) }
23
+ end
24
+ alias :add_slices :all_slices
25
+
26
+ # Add a Slice in a router namespace
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) if slice_module.class.in?(String, Symbol)
44
+ namespace = options[:namespace] || slice_module.to_s.snake_case
45
+ options[:path] ||= 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
+ # setup routes - capture the slice's routes for easy reference
52
+ slice_module.routes, slice_module.named_routes = Merb::Router.capture do
53
+ self.namespace(namespace.to_sym, options.except(:default_routes, :prepend_routes, :append_routes)) do |ns|
54
+ options[:prepend_routes].call(ns) if options[:prepend_routes].respond_to?(:call)
55
+ slice_module.setup_router(ns) # setup the routes from the slice itself
56
+ options[:append_routes].call(ns) if options[:append_routes].respond_to?(:call)
57
+ ns.default_routes(options[:params] || {}) if options[:default_routes]
58
+ end
59
+ end
60
+ else
61
+ Merb.logger.info!("Skipped adding slice #{slice_module} to router...")
62
+ end
63
+ self
64
+ end
65
+
66
+ # Insert a slice directly into the current router context.
67
+ #
68
+ # This will still setup a namespace, but doesn't set a path prefix.
69
+ def slice(slice_module, options = {}, &block)
70
+ add_slice(slice_module, options.merge(:path => ''), &block)
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb-slices" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thorero-slices
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4
5
+ platform: ruby
6
+ authors:
7
+ - Fabien Franzen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-02 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.4
24
+ version:
25
+ description: Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application.
26
+ email: info@fabien.be
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb-slices
41
+ - lib/merb-slices/controller_mixin.rb
42
+ - lib/merb-slices/merbtasks.rb
43
+ - lib/merb-slices/module.rb
44
+ - lib/merb-slices/module_mixin.rb
45
+ - lib/merb-slices/router_ext.rb
46
+ - lib/merb-slices.rb
47
+ - spec/merb-slice_spec.rb
48
+ - spec/spec_helper.rb
49
+ has_rdoc: true
50
+ homepage: http://merbivore.com
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: thorero
71
+ rubygems_version: 1.2.0
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application.
75
+ test_files: []
76
+