GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
Updated docs and pretty_urls packaged mappings to match updated 
ResponseProxy.
dyoder (author)
Sun Apr 20 21:01:51 -0700 2008
commit  21dc0b9f7fe8460aa63450efef91cc698f71fc68
tree    8d88db57502aecc3ea05e48859c538bbadae23fe
parent  a82d1a5b7f6d61066645ef61d4d378bc48bb0fd0
...
43
44
45
46
47
 
 
 
48
49
50
51
 
52
53
54
55
56
57
58
 
 
 
59
60
61
...
66
67
68
69
 
70
71
72
73
74
 
75
76
77
...
79
80
81
82
83
 
84
85
86
...
43
44
45
 
 
46
47
48
49
50
51
 
52
53
54
55
56
 
 
 
57
58
59
60
61
62
...
67
68
69
 
70
71
72
73
74
 
75
76
77
78
...
80
81
82
 
 
83
84
85
86
0
@@ -43,19 +43,20 @@ module Waves
0
   # == Examples
0
   #
0
   # path %r{^/#{resource}/#{name}/?$} do |resource, name|
0
- # use( resource ) | controller { find( name ) } |
0
- # view { | instance | show( resource => instance ) }
0
+ # resource( resource ) do
0
+ # controller { find( name ) } | view { | instance | show( resource => instance ) }
0
+ # end
0
   # end
0
   #
0
   # In this example, we take the same rule from above but invoke a controller and view method.
0
- # We use the +use+ directive and the resource parameter to set the MVC instances we're going
0
+ # We use the +resource+ directive and the resource parameter to set the MVC instances we're going
0
   # to use. This is necessary to use the +controller+ or +view+ methods. Each of these take
0
   # a block as arguments which are evaluated in the context of the instance. The +view+ method
0
   # can further take an argument which is "piped" from the result of the controller block. This
0
   # isn't required, but helps to clarify the request processing. Within a view block, a hash
0
- # may also be passed in, which is converted into instance variables for the view instance. In
0
- # this example, the +show+ method is assigned to an instance variable with the same name as
0
- # the resource type.
0
+ # may also be passed in to the view method, which is converted into instance variables for the
0
+ # view instance. In this example, the +show+ method is assigned to an instance variable with the
0
+ # same name as the resource type.
0
   #
0
   # So given the same URL as above - /person/john - what will happen is the +find+ method for
0
   # the +Person+ controller will be invoked and the result passed to the +Person+ view's +show+
0
@@ -66,12 +67,12 @@ module Waves
0
   # controller and view can thus be completely decoupled and become easier to reuse separately.
0
   #
0
   # url 'http://admin.foobar.com:/' do
0
- # use( admin ) | view { console }
0
+ # resource( :admin ) { view { console } }
0
   # end
0
   #
0
   # In this example, we are using the +url+ method to map a subdomain of +foobar.com+ to the
0
   # console method of the Admin view. In this case, we did not need a controller method, so
0
- # we simply didn't call one.
0
+ # we simply didn't call one.
0
   #
0
   # = Mapping Modules
0
   #
0
@@ -79,8 +80,7 @@ module Waves
0
   # mapping module. Some rule sets come packaged with Waves, such as PrettyUrls (rules for
0
   # matching resources using names instead of ids). The simplest way to define such modules for
0
   # reuse is by defining the +included+ class method for the rules module, and then define
0
- # the rules using +module_eval+. This will likely be made simpler in a future release, but
0
- # see the PrettyUrls module for an example of how to do this.
0
+ # the rules using +module_eval+. See the PrettyUrls module for an example of how to do this.
0
   #
0
   # *Important:* Using pre-packaged mapping rules does not prevent you from adding to or
0
   # overriding these rules. However, order does matter, so you should put your own rules
...
27
28
29
30
 
31
32
33
34
35
36
 
37
38
39
40
41
42
 
43
44
45
...
67
68
69
70
71
72
 
 
 
 
73
74
75
76
77
 
78
79
80
81
82
 
83
84
85
...
27
28
29
 
30
31
32
33
34
 
 
35
36
37
38
39
 
 
40
41
42
43
...
65
66
67
 
 
 
68
69
70
71
72
73
74
75
 
76
77
78
79
80
 
81
82
83
84
0
@@ -27,19 +27,17 @@ module Waves
0
   
0
             # get all resources for the given model
0
             path %r{^/#{model}/?$}, :method => :get do | model |
0
- use( model.singular ) | controller { all } | view { |data| list( model => data ) }
0
+ resource( model.singular ) { controller { all } | view { |data| list( model => data ) } }
0
             end
0
 
0
             # get the given resource for the given model
0
             path %r{^/#{model}/#{name}/?$}, :method => :get do | model, name |
0
- use(model) | controller { find( name ) } |
0
- view { |data| show( model => data ) }
0
+ resource( model ) { controller { find( name ) } | view { |data| show( model => data ) } }
0
             end
0
   
0
             # display an editor for the given resource / model
0
             path %r{^/#{model}/#{name}/editor/?$}, :method => :get do | model, name |
0
- use(model) | controller { find( name ) } |
0
- view { |data| editor( model => data ) }
0
+ resource( model ) { controller { find( name ) } | view { |data| editor( model => data ) } }
0
             end
0
       
0
           end
0
@@ -67,19 +65,20 @@ module Waves
0
   
0
             # create a new resource for the given model
0
             path %r{^/#{model}/?$}, :method => :post do | model |
0
- use( model.singular )
0
- instance = controller { create }
0
- redirect( "/#{model.singular}/#{instance.name}/editor" )
0
+ resource( model.singular ) do
0
+ instance = controller { create }
0
+ redirect( "/#{model.singular}/#{instance.name}/editor" )
0
+ end
0
             end
0
 
0
             # update the given resource for the given model
0
             path %r{^/#{model}/#{name}/?$}, :method => :put do | model, name |
0
- use(model) | controller { update( name ) }; redirect( url )
0
+ resource( model ) { controller { update( name ) }; redirect( url ) }
0
             end
0
   
0
             # delete the given resource for the given model
0
             path %r{^/#{model}/#{name}/?$}, :method => :delete do | model, name |
0
- use( model ) | controller { delete( name ) }
0
+ resource( model ) { controller { delete( name ) } }
0
             end
0
       
0
           end
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 
29
30
31
...
35
36
37
38
39
40
41
42
43
44
45
46
 
47
48
49
...
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
14
15
...
19
20
21
 
 
 
 
 
 
 
 
 
22
23
24
25
0
@@ -8,24 +8,8 @@ module Waves
0
     
0
     def initialize(request); @request = request; end
0
     
0
- #
0
- # def use( model ) ; @model = model ; self ; end
0
- #
0
- # def controller( &block )
0
- # Waves.application.controllers[ @model ].process( @request, &block )
0
- # end
0
- #
0
- # def view( &block )
0
- # Waves.application.views[ @model ].process( @request, @value, &block )
0
- # end
0
- #
0
- # def |( val ); @value = val; self; end
0
- #
0
-
0
- def resource( resource = nil, &block )
0
- @resource = resource
0
- @response = yield if block_given?
0
- return self
0
+ def resource( resource, &block )
0
+ @resource = resource; yield.call
0
    end
0
   
0
     def controller( &block )
0
@@ -35,15 +19,7 @@ module Waves
0
     def view( &block )
0
       lambda { |val| Waves.application.views[ @resource ].process( @request, val, &block ) }
0
     end
0
-
0
- def to_s
0
- case @response
0
- when String then @response
0
- when Proc then @response.call.to_s
0
- else @response.to_s
0
- end
0
- end
0
-
0
+
0
     def redirect(path, status = '302'); @request.redirect(path, status); end
0
     
0
   end

Comments

    No one has commented yet.