Set current_engine on the context, not self, since we dup self and use that for each render loop. Closes #860

This commit is contained in:
Thomas Reynolds 2013-06-12 13:52:35 -07:00
parent b234deb540
commit 7d7d5e683e
7 changed files with 45 additions and 12 deletions

View file

@ -9,6 +9,13 @@
* Fully tested on JRuby * Fully tested on JRuby
* Build defaults to --clean * Build defaults to --clean
3.1.0.rc.4
===
* Blocks with different templating languages than their layout now work as expected. #860
3.1.0.rc.2 3.1.0.rc.2
=== ===

View file

@ -12,12 +12,12 @@ Feature: Markdown support
When I go to "/smarty_pants.html" When I go to "/smarty_pants.html"
Then I should see "Hello" Then I should see "Hello"
Scenario: Links with block syntax in ERB layout erb Scenario: Links with block syntax in ERB layout (erb)
Given the Server is running at "markdown-app" Given the Server is running at "more-markdown-app"
When I go to "/with_layout_erb.html" When I go to "/with_layout_erb.html"
Then I should see '<a href="layout_block_link.html">' Then I should see '<a href="layout_block_link.html">'
Scenario: Links with block syntax in ERB layout Scenario: Links with block syntax in ERB layout and markdown
Given the Server is running at "markdown-app" Given the Server is running at "more-markdown-app"
When I go to "/with_layout.html" When I go to "/with_layout.html"
Then I should see '<a href="layout_block_link.html">' Then I should see '<a href="layout_block_link.html">'

View file

@ -123,12 +123,9 @@ module Middleman
# @param [Hash] opts # @param [Hash] opts
# @return [String] # @return [String]
def render_template(path, locs={}, opts={}, blocks=[]) def render_template(path, locs={}, opts={}, blocks=[])
# Detect the remdering engine from the extension
extension = File.extname(path) extension = File.extname(path)
engine = extension[1..-1].to_sym engine = extension[1..-1].to_sym
# Store last engine for later (could be inside nested renders)
@current_engine, engine_was = engine, @current_engine
if defined?(::I18n) if defined?(::I18n)
old_locale = ::I18n.locale old_locale = ::I18n.locale
::I18n.locale = opts[:lang] if opts[:lang] ::I18n.locale = opts[:lang] if opts[:lang]
@ -171,7 +168,6 @@ module Middleman
# Pop all the saved variables from earlier as we may be returning to a # Pop all the saved variables from earlier as we may be returning to a
# previous render (layouts, partials, nested layouts). # previous render (layouts, partials, nested layouts).
::I18n.locale = old_locale if defined?(::I18n) ::I18n.locale = old_locale if defined?(::I18n)
@current_engine = engine_was
@content_blocks = nil @content_blocks = nil
@current_locs = nil @current_locs = nil
@current_opts = nil @current_opts = nil
@ -238,6 +234,13 @@ module Middleman
def render_individual_file(path, locs = {}, opts = {}, context = self, &block) def render_individual_file(path, locs = {}, opts = {}, context = self, &block)
path = path.to_s path = path.to_s
# Detect the remdering engine from the extension
extension = File.extname(path)
engine = extension[1..-1].to_sym
# Store last engine for later (could be inside nested renders)
context.current_engine, engine_was = engine, context.current_engine
# Save current buffer for later # Save current buffer for later
@_out_buf, _buf_was = "", @_out_buf @_out_buf, _buf_was = "", @_out_buf
@ -283,6 +286,7 @@ module Middleman
ensure ensure
# Reset stored buffer # Reset stored buffer
@_out_buf = _buf_was @_out_buf = _buf_was
context.current_engine = engine_was
end end
# Get the template data from a path # Get the template data from a path
@ -394,13 +398,13 @@ module Middleman
# Save current buffer for later # Save current buffer for later
@_out_buf, _buf_was = "", @_out_buf @_out_buf, _buf_was = "", @_out_buf
layout_path = locate_layout(layout_name, current_engine) layout_path = locate_layout(layout_name, self.current_engine)
extension = File.extname(layout_path) extension = File.extname(layout_path)
engine = extension[1..-1].to_sym engine = extension[1..-1].to_sym
# Store last engine for later (could be inside nested renders) # Store last engine for later (could be inside nested renders)
@current_engine, engine_was = engine, @current_engine self.current_engine, engine_was = engine, self.current_engine
begin begin
content = if block_given? content = if block_given?
@ -415,13 +419,19 @@ module Middleman
concat_safe_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content } concat_safe_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
ensure ensure
@current_engine = engine_was self.current_engine = engine_was
end end
# The currently rendering engine # The currently rendering engine
# @return [Symbol, nil] # @return [Symbol, nil]
def current_engine def current_engine
@current_engine ||= nil @_current_engine ||= nil
end
# The currently rendering engine
# @return [Symbol, nil]
def current_engine=(v)
@_current_engine = v
end end
# Find a template on disk given a output path # Find a template on disk given a output path

View file

@ -42,6 +42,22 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
mark_safe(super(name, mark_safe(content), options, &block)) mark_safe(super(name, mark_safe(content), options, &block))
end end
def capture_html(*args, &block)
handler = auto_find_proper_handler(&block)
captured_block, captured_html = nil, ""
if handler && handler.is_type? && handler.block_is_type?(block)
captured_html, captured_block = handler.capture_from_template(*args, &block)
end
# invoking the block directly if there was no template
captured_html = block_given? && ( captured_block || block.call(*args) ) if captured_html.blank?
captured_html
end
def auto_find_proper_handler(&block)
engine = block_given? ? File.extname(block.source_location[0])[1..-1].to_sym : current_engine
::Padrino::Helpers::OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(engine) && h.is_type? }
end
# Disable Padrino cache buster # Disable Padrino cache buster
def asset_stamp def asset_stamp
false false