Prefer loading layouts from `layouts_dir`

Prefer loading layouts from `layouts_dir` over layouts with the same name in the source root. This also includes a bunch of refactoring/cleanup of rendering.rb. Fixes #1176.