hayajo / Mojolicious-Plugin-Directory

Other
6 stars 6 forks source link

Feature request: Use inside templates - taghelper? #1

Open abandholm opened 11 years ago

abandholm commented 11 years ago

I suppose you intended it to be a standalone server for static files, but I think it could be even more useful if it could be used in my own templates - something like:

% template 'my_template';
<p>These are my files:</p>
<%= Directory( root=> './stuff' ) %>

I can almost achieve this by playing with the handler and dir_page, but not easily ;-)

hayajo commented 11 years ago

This plugin is poor compatibility with "Mojolicious::Routes", so I doesn't consider to provide "taghelper".

I added the "dir_template" option in develop/0.08 branch. What do you think?


# Mojolicious::Lite
plugin Directory => { dir_template => 'index' };

...

__DATA__

@@ index.html.ep
% layout 'default';
% title 'DirectoryIndex';
<h1>Index of <%= $current %></h1>
<ul>
% for my $file (@$files) {
<li><a href='<%= $file->{url} %>'><%== $file->{name} %></a></li>
% }

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>