Merge pull request #1338 from dg-ratiodata/feature/chained_templates_partials
Chained template parsing failed if parent is "html.erb" and child is "html.md.erb"
This commit is contained in:
commit
7c37d4ba51
|
@ -16,4 +16,91 @@ Feature: Templates should be chainable
|
||||||
|
|
||||||
And the file "index.html" should contain "Title</h1>"
|
And the file "index.html" should contain "Title</h1>"
|
||||||
And the file "index.html" should contain "Subtitle</h2>"
|
And the file "index.html" should contain "Subtitle</h2>"
|
||||||
And the file "index.html" should contain "Sup</h3>"
|
And the file "index.html" should contain "Sup</h3>"
|
||||||
|
|
||||||
|
Scenario: Partials are parsed by multiple template engines: Outer template has .erb and inner .md.erb
|
||||||
|
Given a fixture app "partial-chained_templates-app"
|
||||||
|
And a template named "my_template.html.erb" with:
|
||||||
|
"""
|
||||||
|
<h1>My Template</h1>
|
||||||
|
|
||||||
|
<%= partial 'my_partial' %>
|
||||||
|
"""
|
||||||
|
And a template named "my_partial.html.md.erb" with:
|
||||||
|
"""
|
||||||
|
## My Partial
|
||||||
|
|
||||||
|
<%= 'hello world' %>
|
||||||
|
"""
|
||||||
|
And the Server is running
|
||||||
|
When I go to "/my_template.html"
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h1>My Template</h1>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h2 id="my-partial">My Partial</h2>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<p>hello world</p>
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Partials are parsed by multiple template engines: Outer template has .md.erb and inner .md.erb
|
||||||
|
Given a fixture app "partial-chained_templates-app"
|
||||||
|
And a template named "my_template.html.md.erb" with:
|
||||||
|
"""
|
||||||
|
# My Template
|
||||||
|
|
||||||
|
<%= partial 'my_partial' %>
|
||||||
|
"""
|
||||||
|
And a template named "my_partial.html.md.erb" with:
|
||||||
|
"""
|
||||||
|
## My Partial
|
||||||
|
|
||||||
|
<%= 'hello world' %>
|
||||||
|
"""
|
||||||
|
And the Server is running
|
||||||
|
When I go to "/my_template.html"
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h1 id="my-template">My Template</h1>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h2 id="my-partial">My Partial</h2>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<p>hello world</p>
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Partials are parsed by multiple template engines: Outer template has .md.erb, and inner .erb
|
||||||
|
Given a fixture app "partial-chained_templates-app"
|
||||||
|
And a template named "my_template.html.md.erb" with:
|
||||||
|
"""
|
||||||
|
# My Template
|
||||||
|
|
||||||
|
<%= partial 'my_partial' %>
|
||||||
|
"""
|
||||||
|
And a template named "my_partial.html.erb" with:
|
||||||
|
"""
|
||||||
|
<h2>My Partial</h2>
|
||||||
|
|
||||||
|
<%= 'hello world' %>
|
||||||
|
"""
|
||||||
|
And the Server is running
|
||||||
|
When I go to "/my_template.html"
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h1 id="my-template">My Template</h1>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<h2>My Partial</h2>
|
||||||
|
"""
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<p>hello world</p>
|
||||||
|
"""
|
||||||
|
|
|
@ -146,18 +146,7 @@ module Middleman
|
||||||
@current_locs = locs
|
@current_locs = locs
|
||||||
@current_opts = opts
|
@current_opts = opts
|
||||||
|
|
||||||
# Keep rendering template until we've used up all extensions. This
|
content = _render_with_all_renderers(path, locs, context, opts)
|
||||||
# handles cases like `style.css.sass.erb`
|
|
||||||
content = nil
|
|
||||||
while ::Tilt[path]
|
|
||||||
begin
|
|
||||||
opts[:template_body] = content if content
|
|
||||||
content = render_individual_file(path, locs, opts, context)
|
|
||||||
path = File.basename(path, File.extname(path))
|
|
||||||
rescue LocalJumpError
|
|
||||||
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{source}/#{config[:layouts_dir]}."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we need a layout and have a layout, use it
|
# If we need a layout and have a layout, use it
|
||||||
if layout_path = fetch_layout(engine, opts)
|
if layout_path = fetch_layout(engine, opts)
|
||||||
|
@ -175,6 +164,34 @@ module Middleman
|
||||||
@current_opts = nil
|
@current_opts = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _render_with_all_renderers(path, locs, context, opts, &block)
|
||||||
|
# Keep rendering template until we've used up all extensions. This
|
||||||
|
# handles cases like `style.css.sass.erb`
|
||||||
|
content = nil
|
||||||
|
|
||||||
|
while ::Tilt[path]
|
||||||
|
begin
|
||||||
|
opts[:template_body] = content if content
|
||||||
|
|
||||||
|
content = if block_given?
|
||||||
|
render_individual_file(path, locs, opts, context, &block)
|
||||||
|
else
|
||||||
|
render_individual_file(path, locs, opts, context)
|
||||||
|
end
|
||||||
|
|
||||||
|
path = File.basename(path, File.extname(path))
|
||||||
|
rescue LocalJumpError
|
||||||
|
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{source}/#{config[:layouts_dir]}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
content
|
||||||
|
end
|
||||||
|
|
||||||
|
public
|
||||||
|
|
||||||
# Sinatra/Padrino compatible render method signature referenced by some view
|
# Sinatra/Padrino compatible render method signature referenced by some view
|
||||||
# helpers. Especially partials.
|
# helpers. Especially partials.
|
||||||
#
|
#
|
||||||
|
@ -198,7 +215,7 @@ module Middleman
|
||||||
|
|
||||||
if ::Tilt[found_partial]
|
if ::Tilt[found_partial]
|
||||||
# Render the partial if found, otherwide throw exception
|
# Render the partial if found, otherwide throw exception
|
||||||
render_individual_file(found_partial, locals, options, self, &block)
|
_render_with_all_renderers(found_partial, locals, self, options, &block)
|
||||||
else
|
else
|
||||||
File.read(found_partial)
|
File.read(found_partial)
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,10 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
||||||
step %Q{the Server is running}
|
step %Q{the Server is running}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given /^a template named "([^\"]*)" with:$/ do |name, string|
|
||||||
|
step %Q{a file named "source/#{name}" with:}, string
|
||||||
|
end
|
||||||
|
|
||||||
When /^I go to "([^\"]*)"$/ do |url|
|
When /^I go to "([^\"]*)"$/ do |url|
|
||||||
@browser.get(URI.escape(url))
|
@browser.get(URI.escape(url))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue