module Middleman::CoreExtensions::Rendering::InstanceMethods
def render(engine, data, options={}, &block)
-
(String)
-
Parameters:
-
options
(Hash
) -- -
data
(String, Symbol
) -- -
engine
(String, Symbol
) --
def render(engine, data, options={}, &block) data = data.to_s locals = options[:locals] found_partial = false engine = nil # If the path is known to the sitemap if resource = sitemap.find_resource_by_path(current_path) current_dir = File.dirname(resource.source_file) engine = File.extname(resource.source_file)[1..-1].to_sym # Look for partials relative to the current path if current_dir != self.source_dir relative_dir = File.join(current_dir.sub("#{self.source_dir}/", ""), data) # Try to use the current engine first found_partial, found_engine = resolve_template(relative_dir, :preferred_engine => engine, :try_without_underscore => true) # Fall back to any engine available if !found_partial found_partial, found_engine = resolve_template(relative_dir, :try_without_underscore => true) end end end # Look in the root for the partial with the current engine if !found_partial && !engine.nil? found_partial, found_engine = resolve_template(data, :preferred_engine => engine, :try_without_underscore => true) end # Look in the root with any engine if !found_partial found_partial, found_engine = resolve_template(data, :try_without_underscore => true) end # Render the partial if found, otherwide throw exception if found_partial render_individual_file(found_partial, locals, options, self, &block) else raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, "Could not locate partial: #{data}" end end