renee-render 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/renee_render.rb +35 -0
  2. data/test/render_test.rb +33 -0
  3. metadata +35 -80
@@ -111,7 +111,42 @@ module Renee
111
111
  end
112
112
  end
113
113
 
114
+ ##
115
+ # Render a partials with collections support
116
+ #
117
+ # @return [String] The html generated from this partial.
118
+ #
119
+ # @example
120
+ # partial 'photo/item', :object => @photo
121
+ # partial 'photo/item', :collection => @photos
122
+ # partial 'photo/item', :locals => { :foo => :bar }
123
+ #
124
+ def partial(template, options={})
125
+ options = { :locals => {}, :layout => false }.merge(options)
126
+ path = template.to_s.split(File::SEPARATOR)
127
+ object_name = path[-1].to_sym
128
+ path[-1] = "_#{path[-1]}"
129
+ template_path = File.join(path).to_sym
130
+ raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil?
131
+ if collection = options.delete(:collection)
132
+ options.delete(:object)
133
+ counter = 0
134
+ collection.map { |member|
135
+ counter += 1
136
+ options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
137
+ render(template_path, options.dup)
138
+ }.join("\n")
139
+ else
140
+ if member = options.delete(:object)
141
+ options[:locals].merge!(object_name => member)
142
+ end
143
+ render(template_path, options.dup)
144
+ end
145
+ end
146
+
114
147
  private
148
+
149
+
115
150
  def render_setup(engine, options, block)
116
151
  options ||= {}
117
152
  options[:outvar] ||= '@_out_buf'
@@ -102,5 +102,38 @@ describe Renee::Render do
102
102
  }
103
103
  assert_raises(Renee::Render::TemplateNotFound) { get('/') }
104
104
  end # missing template, with engine
105
+
106
+ it "should allow partials to be rendered with locals" do
107
+ create_view "_foo", %Q{start\n%p= bar\nend}, :haml
108
+ create_view :index, %Q{%p test\n= partial("foo", :locals => { :bar => "banana"})\n%p bar}, :haml
109
+ mock_app {
110
+ path("/").get { render! "index" }
111
+ }
112
+ get('/')
113
+ assert_equal 200, response.status
114
+ assert_equal "<p>test</p>\nstart\n<p>banana</p>\nend\n<p>bar</p>\n", response.body
115
+ end # partials, locals
116
+
117
+ it "should allow partials to be rendered with object" do
118
+ create_view "_foo", %Q{start\n%p= foo\nend}, :haml
119
+ create_view :index, %Q{%p test\n= partial("foo", :object => "banana")\n%p bar}, :haml
120
+ mock_app {
121
+ path("/").get { render! "index" }
122
+ }
123
+ get('/')
124
+ assert_equal 200, response.status
125
+ assert_equal "<p>test</p>\nstart\n<p>banana</p>\nend\n<p>bar</p>\n", response.body
126
+ end # partials, object
127
+
128
+ it "should allow partials to be rendered with collection" do
129
+ create_view "_foo", %Q{%p= foo}, :haml
130
+ create_view :index, %Q{%p test\n= partial("foo", :collection => ["banana", "strawberry"])\n%p bar}, :haml
131
+ mock_app {
132
+ path("/").get { render! "index" }
133
+ }
134
+ get('/')
135
+ assert_equal 200, response.status
136
+ assert_equal "<p>test</p>\n<p>banana</p>\n\n<p>strawberry</p>\n<p>bar</p>\n", response.body
137
+ end # partials, collection
105
138
  end
106
139
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renee-render
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 6
10
- version: 0.3.6
5
+ version: 0.3.7
11
6
  platform: ruby
12
7
  authors:
13
8
  - Josh Hull
@@ -17,148 +12,108 @@ autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
14
 
20
- date: 2011-11-30 00:00:00 Z
15
+ date: 2011-12-06 00:00:00 -08:00
16
+ default_executable:
21
17
  dependencies:
22
18
  - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
19
+ name: rack
20
+ requirement: &id001 !ruby/object:Gem::Requirement
24
21
  none: false
25
22
  requirements:
26
23
  - - ~>
27
24
  - !ruby/object:Gem::Version
28
- hash: 27
29
- segments:
30
- - 1
31
- - 3
32
- - 0
33
25
  version: 1.3.0
34
- requirement: *id001
35
26
  type: :runtime
36
27
  prerelease: false
37
- name: rack
28
+ version_requirements: *id001
38
29
  - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
30
+ name: tilt
31
+ requirement: &id002 !ruby/object:Gem::Requirement
40
32
  none: false
41
33
  requirements:
42
34
  - - ~>
43
35
  - !ruby/object:Gem::Version
44
- hash: 29
45
- segments:
46
- - 1
47
- - 3
48
- - 3
49
36
  version: 1.3.3
50
- requirement: *id002
51
37
  type: :runtime
52
38
  prerelease: false
53
- name: tilt
39
+ version_requirements: *id002
54
40
  - !ruby/object:Gem::Dependency
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
41
+ name: callsite
42
+ requirement: &id003 !ruby/object:Gem::Requirement
56
43
  none: false
57
44
  requirements:
58
45
  - - ~>
59
46
  - !ruby/object:Gem::Version
60
- hash: 19
61
- segments:
62
- - 0
63
- - 0
64
- - 6
65
47
  version: 0.0.6
66
- requirement: *id003
67
48
  type: :runtime
68
49
  prerelease: false
69
- name: callsite
50
+ version_requirements: *id003
70
51
  - !ruby/object:Gem::Dependency
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
52
+ name: renee-core
53
+ requirement: &id004 !ruby/object:Gem::Requirement
72
54
  none: false
73
55
  requirements:
74
56
  - - "="
75
57
  - !ruby/object:Gem::Version
76
- hash: 31
77
- segments:
78
- - 0
79
- - 3
80
- - 6
81
- version: 0.3.6
82
- requirement: *id004
58
+ version: 0.3.7
83
59
  type: :runtime
84
60
  prerelease: false
85
- name: renee-core
61
+ version_requirements: *id004
86
62
  - !ruby/object:Gem::Dependency
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
63
+ name: minitest
64
+ requirement: &id005 !ruby/object:Gem::Requirement
88
65
  none: false
89
66
  requirements:
90
67
  - - ~>
91
68
  - !ruby/object:Gem::Version
92
- hash: 21
93
- segments:
94
- - 2
95
- - 6
96
- - 1
97
69
  version: 2.6.1
98
- requirement: *id005
99
70
  type: :development
100
71
  prerelease: false
101
- name: minitest
72
+ version_requirements: *id005
102
73
  - !ruby/object:Gem::Dependency
103
- version_requirements: &id006 !ruby/object:Gem::Requirement
74
+ name: rake
75
+ requirement: &id006 !ruby/object:Gem::Requirement
104
76
  none: false
105
77
  requirements:
106
78
  - - ">="
107
79
  - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
110
- - 0
111
80
  version: "0"
112
- requirement: *id006
113
81
  type: :development
114
82
  prerelease: false
115
- name: rake
83
+ version_requirements: *id006
116
84
  - !ruby/object:Gem::Dependency
117
- version_requirements: &id007 !ruby/object:Gem::Requirement
85
+ name: bundler
86
+ requirement: &id007 !ruby/object:Gem::Requirement
118
87
  none: false
119
88
  requirements:
120
89
  - - ">="
121
90
  - !ruby/object:Gem::Version
122
- hash: 3
123
- segments:
124
- - 0
125
91
  version: "0"
126
- requirement: *id007
127
92
  type: :development
128
93
  prerelease: false
129
- name: bundler
94
+ version_requirements: *id007
130
95
  - !ruby/object:Gem::Dependency
131
- version_requirements: &id008 !ruby/object:Gem::Requirement
96
+ name: rack-test
97
+ requirement: &id008 !ruby/object:Gem::Requirement
132
98
  none: false
133
99
  requirements:
134
100
  - - ">="
135
101
  - !ruby/object:Gem::Version
136
- hash: 11
137
- segments:
138
- - 0
139
- - 5
140
- - 0
141
102
  version: 0.5.0
142
- requirement: *id008
143
103
  type: :development
144
104
  prerelease: false
145
- name: rack-test
105
+ version_requirements: *id008
146
106
  - !ruby/object:Gem::Dependency
147
- version_requirements: &id009 !ruby/object:Gem::Requirement
107
+ name: haml
108
+ requirement: &id009 !ruby/object:Gem::Requirement
148
109
  none: false
149
110
  requirements:
150
111
  - - ">="
151
112
  - !ruby/object:Gem::Version
152
- hash: 7
153
- segments:
154
- - 2
155
- - 2
156
- - 0
157
113
  version: 2.2.0
158
- requirement: *id009
159
114
  type: :development
160
115
  prerelease: false
161
- name: haml
116
+ version_requirements: *id009
162
117
  description: The super-friendly web framework rendering component.
163
118
  email:
164
119
  - joshbuddy@gmail.com
@@ -179,6 +134,7 @@ files:
179
134
  - renee-render.gemspec
180
135
  - test/render_test.rb
181
136
  - test/test_helper.rb
137
+ has_rdoc: true
182
138
  homepage: http://reneerb.com
183
139
  licenses: []
184
140
 
@@ -192,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
148
  requirements:
193
149
  - - ">="
194
150
  - !ruby/object:Gem::Version
195
- hash: 3
151
+ hash: 3690837816522299501
196
152
  segments:
197
153
  - 0
198
154
  version: "0"
@@ -201,18 +157,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
157
  requirements:
202
158
  - - ">="
203
159
  - !ruby/object:Gem::Version
204
- hash: 3
160
+ hash: 3690837816522299501
205
161
  segments:
206
162
  - 0
207
163
  version: "0"
208
164
  requirements: []
209
165
 
210
166
  rubyforge_project: renee
211
- rubygems_version: 1.8.10
167
+ rubygems_version: 1.6.2
212
168
  signing_key:
213
169
  specification_version: 3
214
170
  summary: The super-friendly web framework rendering component
215
171
  test_files:
216
172
  - test/render_test.rb
217
173
  - test/test_helper.rb
218
- has_rdoc: