diff --git a/CHANGELOG.md b/CHANGELOG.md
index e19edd9e..f9cba982 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,13 @@
* Fully tested on JRuby
* 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
===
diff --git a/middleman-core/features/markdown.feature b/middleman-core/features/markdown.feature
index 906e8e30..02169527 100644
--- a/middleman-core/features/markdown.feature
+++ b/middleman-core/features/markdown.feature
@@ -12,12 +12,12 @@ Feature: Markdown support
When I go to "/smarty_pants.html"
Then I should see "“Hello”"
- Scenario: Links with block syntax in ERB layout erb
- Given the Server is running at "markdown-app"
+ Scenario: Links with block syntax in ERB layout (erb)
+ Given the Server is running at "more-markdown-app"
When I go to "/with_layout_erb.html"
Then I should see ''
- Scenario: Links with block syntax in ERB layout
- Given the Server is running at "markdown-app"
+ Scenario: Links with block syntax in ERB layout and markdown
+ Given the Server is running at "more-markdown-app"
When I go to "/with_layout.html"
Then I should see ''
diff --git a/middleman-more/fixtures/markdown-app/source/layouts/layout.erb b/middleman-core/fixtures/more-markdown-app/source/layouts/layout.erb
similarity index 100%
rename from middleman-more/fixtures/markdown-app/source/layouts/layout.erb
rename to middleman-core/fixtures/more-markdown-app/source/layouts/layout.erb
diff --git a/middleman-more/fixtures/markdown-app/source/with_layout.markdown b/middleman-core/fixtures/more-markdown-app/source/with_layout.markdown
similarity index 100%
rename from middleman-more/fixtures/markdown-app/source/with_layout.markdown
rename to middleman-core/fixtures/more-markdown-app/source/with_layout.markdown
diff --git a/middleman-more/fixtures/markdown-app/source/with_layout_erb.markdown.erb b/middleman-core/fixtures/more-markdown-app/source/with_layout_erb.markdown.erb
similarity index 100%
rename from middleman-more/fixtures/markdown-app/source/with_layout_erb.markdown.erb
rename to middleman-core/fixtures/more-markdown-app/source/with_layout_erb.markdown.erb
diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb
index 368d8808..3656bf84 100644
--- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb
+++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb
@@ -123,12 +123,9 @@ module Middleman
# @param [Hash] opts
# @return [String]
def render_template(path, locs={}, opts={}, blocks=[])
- # 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)
- @current_engine, engine_was = engine, @current_engine
if defined?(::I18n)
old_locale = ::I18n.locale
::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
# previous render (layouts, partials, nested layouts).
::I18n.locale = old_locale if defined?(::I18n)
- @current_engine = engine_was
@content_blocks = nil
@current_locs = nil
@current_opts = nil
@@ -238,6 +234,13 @@ module Middleman
def render_individual_file(path, locs = {}, opts = {}, context = self, &block)
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
@_out_buf, _buf_was = "", @_out_buf
@@ -283,6 +286,7 @@ module Middleman
ensure
# Reset stored buffer
@_out_buf = _buf_was
+ context.current_engine = engine_was
end
# Get the template data from a path
@@ -394,13 +398,13 @@ module Middleman
# Save current buffer for later
@_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)
engine = extension[1..-1].to_sym
# 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
content = if block_given?
@@ -415,13 +419,19 @@ module Middleman
concat_safe_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
ensure
- @current_engine = engine_was
+ self.current_engine = engine_was
end
# The currently rendering engine
# @return [Symbol, nil]
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
# Find a template on disk given a output path
diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb
index e66274c9..f38c1dc7 100644
--- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb
+++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb
@@ -42,6 +42,22 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
mark_safe(super(name, mark_safe(content), options, &block))
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
def asset_stamp
false