roger 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2E4YjE1MDI4YWZiNmMyMzAwYmQzMGFmN2JiMGZhYjQzYzFjNTIwZA==
4
+ YzYxZWRjNGYwZjA1NjRmNzQ4NDA1YjA5NTJlYjg2Y2VjNGE2ODQwMA==
5
5
  data.tar.gz: !binary |-
6
- NjgxYjg4ZTU2NGJjNzE3MjlmNzc1NjBhNzU1ZDgxMGNmY2RhYjk3Mg==
6
+ NTA4Y2Y4MjIwMjA1OGYzNzgxM2Y1NmZiZTljMDgxOGQ2OGU0YTFlNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTJjNjM2ZTFiNzIwZTU3ODdmYjYyM2QwYzEyYWVhMTk0MGM0OTBlODU5MTBk
10
- NDQyZWE5OGVmNzM1NmMyNWNkM2NmZDNiZGE2MjE0MGI3ZWMwN2VjY2JkZTU2
11
- OWUxYzgyOGJlODE4ZmRkY2U5OWI1MzI1YjEyZGIwOGNjNDU2OWI=
9
+ ZjkxOTQ2MmY4MzYzYTcxMDVjNzY5MTAyYzU1NjA3MzgyYzE0OWFlODdlMjRk
10
+ ZjdlOGUzNDg1M2M1NjYwMjQ0OTg1NDRkOTA4YmZiM2ZhZjFmMjAxZmVhNTk4
11
+ MDg5ZjNiYjM3MjViMmRiZDYwNzQ3MzkyNWM2ZmY5OGM4ODFhNTE=
12
12
  data.tar.gz: !binary |-
13
- OTBiYTliOWQxZDZjYjNkZDdkNTU2Mjg2YjkxOGU4ZmNjNjc2OTRiYTEwOGU4
14
- YTEyMjVkZWMxZjBhMGQxYWI2MTNmODk2MTk5ZDE3NjliZTdiODE0MWMxNzQ1
15
- YmU3NjE1YjYwYWUzNGZlOGQyZWIyMzdlNzM4MmQyODQ4Yzk4MDA=
13
+ ODhjNWUwNzI0ODMxN2E0YThkMzc2NmQ5MWI3MjM2MWY3YjRmNzEyOTczNzZi
14
+ YjZkMDlkMjM2NjdjNzBjZWU1OWNlOTJiNDZiZDUwZTM1OTI2OWRmZDU4OTEx
15
+ YWVhMjJjMmViYmFiMTI1YzJhZDFlZjE2NTRlZjMzOTYwNzQxY2Y=
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.12.0
4
+ * Allow passing blocks to partials. Keep in mind that you'll need to use the `<% ... %>` form when using blocks.
5
+
3
6
  ## Version 0.11.0
4
7
  * You can now register release processors and finalizers with a name and use them by name (call `Roger::Release::Finalizers.register(:name, Finalizer)` or `Roger::Release::Processors.register(:name, Processor)`)
5
8
  * Generators now need to be registered on `Roger::Generators` instead of `Roger::Generators::Base`
@@ -177,21 +177,35 @@ module Roger
177
177
  # ```
178
178
  # <%= yield :name %>
179
179
  # ```
180
- def content_for(block_name, &capture)
180
+ def content_for(block_name, &block)
181
+ @_content_for_blocks[block_name] = capture(&block)
182
+ end
183
+
184
+ def capture(&block)
181
185
  raise ArgumentError, "content_for works only with ERB Templates" if !self.template.template.kind_of?(Tilt::ERBTemplate)
182
- eval "@_erbout_tmp = _erbout", capture.binding
183
- eval "_erbout = \"\"", capture.binding
186
+ eval "@_erbout_tmp = _erbout", block.binding
187
+ eval "_erbout = \"\"", block.binding
184
188
  t = Tilt::ERBTemplate.new(){ "<%= yield %>" }
185
- @_content_for_blocks[block_name] = t.render(&capture)
186
- return nil
189
+ t.render(&block)
187
190
  ensure
188
- eval "_erbout = @_erbout_tmp", capture.binding
191
+ eval "_erbout = @_erbout_tmp", block.binding
189
192
  end
190
193
 
191
- def partial(name, options = {})
194
+ def partial(name, options = {}, &block)
192
195
  if template_path = self.template.find_template(name, :partials_path)
193
196
  partial_template = Tilt.new(template_path.to_s)
194
- partial_template.render(self, options[:locals] || {})
197
+ if block_given?
198
+ block_content = capture(&block)
199
+ else
200
+ block_content = ""
201
+ end
202
+ out = partial_template.render(self, options[:locals] || {}){ block_content }
203
+
204
+ if block_given?
205
+ eval "_erbout.concat(#{out.dump})", block.binding
206
+ else
207
+ out
208
+ end
195
209
  else
196
210
  raise ArgumentError, "No such partial #{name}, referenced from #{self.template.source_path}"
197
211
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "roger"
5
- s.version = "0.11.0"
5
+ s.version = "0.12.0"
6
6
 
7
7
  s.authors = ["Flurin Egger", "Edwin van der Graaf", "Joran Kapteijns"]
8
8
  s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
@@ -0,0 +1 @@
1
+ B-<%= yield %>-A
@@ -99,6 +99,19 @@ module Roger
99
99
 
100
100
  end
101
101
 
102
+ def test_partial_with_block
103
+ template = Template.new("<% partial 'test/yield' do %>CONTENT<% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
104
+ assert_equal template.render, "B-CONTENT-A"
105
+
106
+ template = Template.new("<% partial 'test/yield' do %><%= 'CONTENT' %><% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
107
+ assert_equal template.render, "B-CONTENT-A"
108
+ end
109
+
110
+ def test_partial_with_block_without_yield
111
+ template = Template.new("<% partial 'test/simple' do %>CONTENT<% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
112
+ assert_equal template.render, "ERB"
113
+ end
114
+
102
115
  # Content for parts
103
116
 
104
117
  def test_content_for_not_returning_in_template
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-30 00:00:00.000000000 Z
13
+ date: 2014-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -184,6 +184,7 @@ files:
184
184
  - test/project/partials/test/json.json.erb
185
185
  - test/project/partials/test/markdown.md
186
186
  - test/project/partials/test/simple.html.erb
187
+ - test/project/partials/test/yield.html.erb
187
188
  - test/project/partials2/partials2-test.html.erb
188
189
  - test/unit/cli_test.rb
189
190
  - test/unit/generators_test.rb
@@ -246,6 +247,7 @@ test_files:
246
247
  - test/project/partials/test/json.json.erb
247
248
  - test/project/partials/test/markdown.md
248
249
  - test/project/partials/test/simple.html.erb
250
+ - test/project/partials/test/yield.html.erb
249
251
  - test/project/partials2/partials2-test.html.erb
250
252
  - test/unit/cli_test.rb
251
253
  - test/unit/generators_test.rb