Fix instance variables in dynamic pages

This commit is contained in:
Tim Bates 2012-07-23 15:15:10 +09:30
parent 2f7371ca1f
commit 99a8723ea6
6 changed files with 27 additions and 8 deletions

View file

@ -96,7 +96,7 @@ module Middleman
# @param [Hash] locs
# @param [Hash] opts
# @return [String]
def render_template(path, locs={}, opts={})
def render_template(path, locs={}, opts={}, blocks=[])
# Detect the remdering engine from the extension
extension = File.extname(path)
engine = extension[1..-1].to_sym
@ -107,6 +107,9 @@ module Middleman
# Use a dup of self as a context so that instance variables set within
# the template don't persist for other templates.
context = self.dup
blocks.each do |block|
context.instance_eval(&block)
end
# Store current locs/opts for later
@current_locs = locs, @current_opts = opts

View file

@ -125,14 +125,11 @@ module Middleman
app.data.store("page", md[:page])
end
md[:blocks].each do |aBlock|
app.instance_eval(&aBlock)
end
app.instance_eval(&block) if block_given?
blocks = md[:blocks].dup rescue []
blocks << block if block_given?
app.current_path ||= self.destination_path
app.render_template(source_file, locs, opts)
app.render_template(source_file, locs, opts, blocks)
end
end