Fix wrap_layout for all know templating engines. Fixes #417
This commit is contained in:
parent
9b5d1f17d0
commit
2ab294c602
|
@ -329,19 +329,29 @@ module Middleman
|
|||
def wrap_layout(layout_name, &block)
|
||||
# Save current buffer for later
|
||||
@_out_buf, _buf_was = "", @_out_buf
|
||||
|
||||
begin
|
||||
content = capture(&block) if block_given?
|
||||
content = if block_given?
|
||||
capture_html(&block)
|
||||
else
|
||||
""
|
||||
end
|
||||
ensure
|
||||
# Reset stored buffer
|
||||
@_out_buf = _buf_was
|
||||
end
|
||||
|
||||
layout_path = locate_layout(layout_name, current_engine)
|
||||
|
||||
if !@_out_buf
|
||||
raise "wrap_layout is currently broken for this templating system"
|
||||
end
|
||||
extension = File.extname(layout_path)
|
||||
engine = extension[1..-1].to_sym
|
||||
|
||||
@_out_buf.concat render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
|
||||
# Store last engine for later (could be inside nested renders)
|
||||
@current_engine, engine_was = engine, @current_engine
|
||||
|
||||
concat_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
|
||||
ensure
|
||||
@current_engine = engine_was
|
||||
end
|
||||
|
||||
# The currently rendering engine
|
||||
|
|
|
@ -13,13 +13,24 @@ Feature: Allow nesting of layouts
|
|||
And I should see "Inner"
|
||||
And I should see "Outer"
|
||||
And I should see "Master"
|
||||
When I go to "/haml-test.html"
|
||||
|
||||
Scenario: A page uses an inner layout when uses an outer layout (slim)
|
||||
Given the Server is running at "nested-layout-app"
|
||||
When I go to "/slim-test.html"
|
||||
And I should see "New Article Title"
|
||||
And I should see "The Article Content"
|
||||
And I should see "Inner"
|
||||
And I should see "Outer"
|
||||
And I should see "Master"
|
||||
|
||||
Scenario: A page uses an inner layout when uses an outer layout (haml)
|
||||
Given the Server is running at "nested-layout-app"
|
||||
When I go to "/haml-test.html"
|
||||
And I should see "New Article Title"
|
||||
And I should see "The Article Content"
|
||||
And I should see "Inner"
|
||||
And I should see "Outer"
|
||||
And I should see "Master"
|
||||
|
||||
Scenario: YAML Front Matter isn't clobbered with nested layouts
|
||||
Given the Server is running at "nested-layout-app"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: "New Article Title"
|
||||
date: 2011-01-01
|
||||
layout: inner
|
||||
---
|
||||
|
||||
The Article Content
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: "New Article Title"
|
||||
date: 2011-01-01
|
||||
layout: inner_haml
|
||||
---
|
||||
|
||||
The Article Content
|
|
@ -0,0 +1,3 @@
|
|||
- wrap_layout :outer_haml do
|
||||
Inner
|
||||
= yield
|
|
@ -0,0 +1,3 @@
|
|||
- wrap_layout :outer_slim do
|
||||
Inner
|
||||
= yield
|
|
@ -0,0 +1,3 @@
|
|||
Master
|
||||
= data.page.title
|
||||
= yield
|
|
@ -0,0 +1,3 @@
|
|||
Master
|
||||
= data.page.title
|
||||
= yield
|
|
@ -0,0 +1,3 @@
|
|||
- wrap_layout :master_haml do
|
||||
Outer
|
||||
= yield
|
|
@ -0,0 +1,3 @@
|
|||
- wrap_layout :master_slim do
|
||||
Outer
|
||||
= yield
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: "New Article Title"
|
||||
date: 2011-01-01
|
||||
layout: inner_slim
|
||||
---
|
||||
|
||||
The Article Content
|
Loading…
Reference in a new issue