Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor to handle index.$tmpl_ext for "dir index".

If we don't find a direct match for `views/$path`, try appending `/index` to the
path and looking again.

This means that, if the request was for `/foo` and we didn't have
`views/foo`, we'll then look for `views/foo/index.tt`, and use that if found.

This is something I've missed for a long time, and makes the auto_page feature a
lot more useful, I think.
  • Loading branch information...
commit a268865a05946d128ee4b09141bdf9bdbc98d869 1 parent ffdd5d8
@bigpresh bigpresh authored
Showing with 20 additions and 5 deletions.
  1. +20 −5 lib/Dancer/Renderer.pm
View
25 lib/Dancer/Renderer.pm
@@ -162,16 +162,31 @@ sub render_autopage {
if ($view && -f $view) {
# A view exists for the path requested, go ahead and render it:
- my $response = Dancer::Response->new;
- $response->status(200);
- $response->content(
- Dancer::template($viewpath)
+ return _autopage_response($viewpath);
+ }
+
+ # Try appending "index" and looking again
+ $view = Dancer::engine('template')->view(
+ Dancer::FileUtils::path($viewpath, 'index')
+ )|| '';
+ Dancer::error("Looking for $viewpath/index - got $view");
+ if ($view && -f $view) {
+ return _autopage_response(
+ Dancer::FileUtils::path($viewpath, 'index')
);
- return $response;
}
return;
}
+sub _autopage_response {
+ my $viewpath = shift;
+ my $response = Dancer::Response->new;
+ $response->status(200);
+ $response->content(
+ Dancer::template($viewpath)
+ );
+ return $response;
+}
sub serialize_response_if_needed {
my $response = Dancer::SharedData->response();
Please sign in to comment.
Something went wrong with that request. Please try again.