public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Added Merb::Router.extensions as an official API.

Merb::Router.extensions is now the official way to add functionality
to the router.
carllerche (author)
Sun Oct 12 16:15:22 -0700 2008
commit  72f7c7ef3a2ce6a0a0f409b2092e64da7d0795cf
tree    b5434d3139a1401454adc3a68868e3a15d5159e6
parent  209ca502a6e44f3115042f90b90caec6f82580ed
...
236
237
238
239
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
242
243
...
236
237
238
 
 
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
0
@@ -236,8 +236,40 @@ module Merb
0
         route.generate(params, defaults)
0
       end
0
       
0
-      private
0
-      
0
+      # Add functionality to the router. This can be in the form of
0
+      # including a new module or directly defining new methods.
0
+      #
0
+      # ==== Parameters
0
+      # &block<Block>::
0
+      #   A block of code used to extend the route builder with. This
0
+      #   can be including a module or directly defining some new methods
0
+      #   that should be available to building routes.
0
+      #
0
+      # ==== Example
0
+      # Merb::Router.extensions do
0
+      #   def domain(name, domain, options={}, &block)
0
+      #     match(:domain => domain).namespace(name, :path => nil, &block)
0
+      #   end
0
+      # end
0
+      #
0
+      # In this case, a method 'domain' will be available to the route builder
0
+      # which will create namespaces around domains instead of path prefixes.
0
+      #
0
+      # This can then be used as follows.
0
+      #
0
+      # Merb::Router.prepare do
0
+      #   domain(:admin, "my-admin.com") do
0
+      #     # ... routes come here ...
0
+      #   end
0
+      # end
0
+      # ---
0
+      # @api public
0
+      def extensions(&block)
0
+        Router::Behavior.class_eval(&block)
0
+      end
0
+
0
+    private
0
+    
0
       # Compiles the routes and creates the +match+ method.
0
       # 
0
       # @api private
...
272
273
274
275
276
277
278
279
 
280
281
282
...
301
302
303
 
 
 
 
304
305
306
...
272
273
274
 
 
 
 
 
275
276
277
278
...
297
298
299
300
301
302
303
304
305
306
0
@@ -272,11 +272,7 @@ module Merb
0
       end
0
 
0
     end # Resources
0
-    
0
-    class Behavior
0
-      include Resources
0
-    end
0
-    
0
+
0
     # Adding the collection and member methods to behavior
0
     class ResourceBehavior < Behavior #:nodoc:
0
       
0
@@ -301,5 +297,9 @@ module Merb
0
       end
0
       
0
     end
0
+    
0
+    class Behavior
0
+      include Resources
0
+    end
0
   end
0
 end
0
\ No newline at end of file
...
145
146
147
148
 
149
150
151
...
157
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
...
145
146
147
 
148
149
150
151
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
0
@@ -145,7 +145,7 @@ describe Merb::Router do
0
     end
0
     
0
     it "should not be able to match routes anymore" do
0
-      lambda { route_for("/users") }
0
+      lambda { route_for("/users") }.should raise_error(Merb::Router::NotCompiledError)
0
     end
0
     
0
   end
0
@@ -157,5 +157,21 @@ describe Merb::Router do
0
     end
0
 
0
   end
0
+  
0
+  describe "#extensions" do
0
+    it "should be able to extend the router" do
0
+      Merb::Router.extensions do
0
+        def hello_world
0
+          match("/hello").to(:controller => "world")
0
+        end
0
+      end
0
+      
0
+      Merb::Router.prepare do
0
+        hello_world
0
+      end
0
+      
0
+      route_for("/hello").should have_route(:controller => "world")
0
+    end
0
+  end
0
 
0
 end
0
\ No newline at end of file

Comments