roger 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/CHANGELOG.md +3 -0
- data/lib/roger/template.rb +22 -8
- data/roger.gemspec +1 -1
- data/test/project/partials/test/yield.html.erb +1 -0
- data/test/unit/template_test.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzYxZWRjNGYwZjA1NjRmNzQ4NDA1YjA5NTJlYjg2Y2VjNGE2ODQwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTA4Y2Y4MjIwMjA1OGYzNzgxM2Y1NmZiZTljMDgxOGQ2OGU0YTFlNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjkxOTQ2MmY4MzYzYTcxMDVjNzY5MTAyYzU1NjA3MzgyYzE0OWFlODdlMjRk
|
10
|
+
ZjdlOGUzNDg1M2M1NjYwMjQ0OTg1NDRkOTA4YmZiM2ZhZjFmMjAxZmVhNTk4
|
11
|
+
MDg5ZjNiYjM3MjViMmRiZDYwNzQ3MzkyNWM2ZmY5OGM4ODFhNTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODhjNWUwNzI0ODMxN2E0YThkMzc2NmQ5MWI3MjM2MWY3YjRmNzEyOTczNzZi
|
14
|
+
YjZkMDlkMjM2NjdjNzBjZWU1OWNlOTJiNDZiZDUwZTM1OTI2OWRmZDU4OTEx
|
15
|
+
YWVhMjJjMmViYmFiMTI1YzJhZDFlZjE2NTRlZjMzOTYwNzQxY2Y=
|
data/CHANGELOG.md
CHANGED
@@ -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`
|
data/lib/roger/template.rb
CHANGED
@@ -177,21 +177,35 @@ module Roger
|
|
177
177
|
# ```
|
178
178
|
# <%= yield :name %>
|
179
179
|
# ```
|
180
|
-
def content_for(block_name, &
|
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",
|
183
|
-
eval "_erbout = \"\"",
|
186
|
+
eval "@_erbout_tmp = _erbout", block.binding
|
187
|
+
eval "_erbout = \"\"", block.binding
|
184
188
|
t = Tilt::ERBTemplate.new(){ "<%= yield %>" }
|
185
|
-
|
186
|
-
return nil
|
189
|
+
t.render(&block)
|
187
190
|
ensure
|
188
|
-
eval "_erbout = @_erbout_tmp",
|
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
|
-
|
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
|
data/roger.gemspec
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
B-<%= yield %>-A
|
data/test/unit/template_test.rb
CHANGED
@@ -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.
|
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-
|
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
|