module Middleman::CoreExtensions::Rendering::InstanceMethods

def fetch_layout(engine, opts)

Returns:
  • (String) -

Parameters:
  • opts (Hash) --
  • engine (Symbol) --
def fetch_layout(engine, opts)
  # The layout name comes from either the system default or the options
  local_layout = opts.has_key?(:layout) ? opts[:layout] : layout
  return false unless local_layout
  # Look for engine-specific options
  engine_options = respond_to?(engine) ? send(engine) : {}
  # The engine for the layout can be set in options, engine_options or passed
  # into this method
  layout_engine = if opts.has_key?(:layout_engine)
    opts[:layout_engine]
  elsif engine_options.has_key?(:layout_engine)
    engine_options[:layout_engine]
  else
    engine
  end
  # Automatic mode
  if local_layout == :_auto_layout
    # Look for :layout of any extension
    # If found, use it. If not, continue
    locate_layout(:layout, layout_engine) || false
  else
    # Look for specific layout
    # If found, use it. If not, error.
    if layout_path = locate_layout(local_layout, layout_engine)
      layout_path
    else
      raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, "Could not locate layout: #{local_layout}"
    end
  end
end