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
Search Repo:
Adding the current index and collection size for partials rendered with a 
collection
carllerche (author)
Thu Jul 24 22:29:40 -0700 2008
commit  fea472686b12a0f5da9c2eb1dfab4266836d2fbf
tree    4c7149fdc95d03de5f5d2945854329f5a39b3b06
parent  7cb2d479de25ea46661584b0b636810b0def0f01
...
269
270
271
272
 
273
274
275
...
278
279
280
281
 
 
 
282
283
284
...
269
270
271
 
272
273
274
275
...
278
279
280
 
281
282
283
284
285
286
0
@@ -269,7 +269,7 @@ module Merb::RenderMixin
0
     with = [opts.delete(:with)].flatten
0
     as = opts.delete(:as) || template_location.match(%r[.*/_([^\.]*)])[1]
0
     
0
- @_merb_partial_locals = opts
0
+ @_merb_partial_locals = opts.merge(:collection_index => 0, :collection_size => with.size)
0
     
0
     # this handles an edge-case where the name of the partial is _foo.* and your opts
0
     # have :foo as a key.
0
@@ -278,7 +278,9 @@ module Merb::RenderMixin
0
     sent_template = with.map do |temp|
0
       @_merb_partial_locals[as.to_sym] = temp unless named_local
0
       if template_method && self.respond_to?(template_method)
0
- send(template_method)
0
+ sent = send(template_method)
0
+ @_merb_partial_locals[:collection_index] += 1
0
+ sent
0
       else
0
         raise TemplateNotFound, "Could not find template at #{template_location}.*"
0
       end
...
65
66
67
 
 
 
 
 
 
 
68
69
70
...
111
112
113
114
 
115
...
65
66
67
68
69
70
71
72
73
74
75
76
77
...
118
119
120
 
121
122
0
@@ -65,6 +65,13 @@ module Merb::Test::Fixtures
0
         render
0
       end
0
     end
0
+
0
+ class PartialWithCollectionsAndCounter < RenderIt
0
+ def index
0
+ @foo = %w(1 2 3 4 5)
0
+ render
0
+ end
0
+ end
0
 
0
     class PartialWithLocals < RenderIt
0
 
0
@@ -111,4 +118,4 @@ module Merb::Test::Fixtures
0
       end
0
     end
0
   end
0
-end
0
+end
0
\ No newline at end of file
...
50
51
52
 
 
 
 
53
54
55
...
50
51
52
53
54
55
56
57
58
59
0
@@ -50,6 +50,10 @@ describe Merb::AbstractController, " Partials" do
0
     dispatch_should_make_body("BasicPartialWithMultipleRoots", "Base Index: Alt Partial")
0
   end
0
   
0
+ it "should be able to count collections" do
0
+ dispatch_should_make_body("PartialWithCollectionsAndCounter", "Partial counting: 0/5 1/5 2/5 3/5 4/5 ")
0
+ end
0
+
0
   it "should render a partial using an absolute path" do
0
     dispatch_should_make_body("WithAbsolutePartial", "Index Absolute Partial")
0
   end

Comments

    No one has commented yet.