lib/roger/template.rb in roger-1.1.1 vs lib/roger/template.rb in roger-1.1.2
- old
+ new
@@ -33,10 +33,11 @@
# @option options [String,Pathname] :source_path The path to the source of the template being processed
# @option options [String,Pathname] :layouts_path The path to where all layouts reside
# @option options [String,Pathname] :partials_path The path to where all partials reside
def initialize(source, options = {})
@options = options
+
self.source_path = options[:source_path]
self.data, self.source = extract_front_matter(source)
self.template = Tilt.new(self.source_path.to_s){ self.source }
if self.data[:layout] && layout_template_path = self.find_template(self.data[:layout], :layouts_path)
@@ -147,10 +148,13 @@
attr_accessor :_content_for_blocks
def initialize(template, env={})
@_content_for_blocks = {}
@_template, @_env = template, env
+
+ # Block counter to make sure erbtemp binding is always unique
+ @block_counter = 0
end
# The current Roger::Template in use
def template
@_template
@@ -182,16 +186,20 @@
@_content_for_blocks[block_name] = capture(&block)
end
def capture(&block)
raise ArgumentError, "content_for works only with ERB Templates" if !self.template.template.kind_of?(Tilt::ERBTemplate)
- eval "@_erbout_tmp = _erbout", block.binding
+
+ @block_counter += 1
+ counter = @block_counter
+
+ eval "@_erbout_tmp#{counter} = _erbout", block.binding
eval "_erbout = \"\"", block.binding
t = Tilt::ERBTemplate.new(){ "<%= yield %>" }
- t.render(&block)
+ t.render(&block)
ensure
- eval "_erbout = @_erbout_tmp", block.binding
+ eval "_erbout = @_erbout_tmp#{counter}", block.binding
end
def partial(name, options = {}, &block)
if template_path = self.template.find_template(name, :partials_path)
partial_template = Tilt.new(template_path.to_s)
@@ -212,6 +220,6 @@
end
end
end
-end
\ No newline at end of file
+end