Regenerate @_lookup_cache after each manipulation

Trying to call Resource#metadata from within
MyExtension#manipulate_resource_list generates an exception in
Proxies::ResourceInstanceMethods#get_source_file because @_lookup_cache
is empty. Moving the recalculation inside the loop means regenerating
the cache after each manipulation but allows extensions to examine the
page metadata when manipulating proxied resources.
This commit is contained in:
Tim Bates 2012-07-11 15:16:18 +09:30
parent ffecc3e4cc
commit d30f883e48

View file

@ -47,14 +47,16 @@ module Middleman
# @return [void] # @return [void]
def rebuild_resource_list!(reason=nil) def rebuild_resource_list!(reason=nil)
@resources = @resource_list_manipulators.inject([]) do |result, (_, inst)| @resources = @resource_list_manipulators.inject([]) do |result, (_, inst)|
inst.manipulate_resource_list(result) newres = inst.manipulate_resource_list(result)
end
# Reset lookup cache # Reset lookup cache
@_lookup_cache = { :path => {}, :destination_path => {} } @_lookup_cache = { :path => {}, :destination_path => {} }
@resources.each do |resource| newres.each do |resource|
@_lookup_cache[:path][resource.path] = resource @_lookup_cache[:path][resource.path] = resource
@_lookup_cache[:destination_path][resource.destination_path] = resource @_lookup_cache[:destination_path][resource.destination_path] = resource
end
newres
end end
end end