Plack-App-Directory-Markdown

 view release on metacpan or  search on metacpan

lib/Plack/App/Directory/Markdown.pm  view on Meta::CPAN

    my $i = 0;
    foreach my $part (reverse(split('/',$path))) {
        my $link = '../' x $i;

        push @out,
            {
            name => $part,
            link => "${link}",
            };
        $i++;
    }
    $out[0]->{link} = '';    # Last element should link to itself
    return [ reverse @out ];
}

1;

__DATA__

@@ base.tx
<head>
<meta charset="utf-8">
<title><: $title :></title>
<style type="text/css">
  img { max-width: 100%; }
  ul.paginate { padding: 0; }
  ul.paginate li { display: inline; }
  ul.paginate li.prev::before { content: "\00ab  "; // laquo; }
  ul.paginate li.next::after { content: "  \00bb"; // raquo; }
  ul.paginate li + li::before { content: ' | '; }
</style>
<!-- you can locate your style.css and adjust styles -->
<link rel="stylesheet" type="text/css" media="all" href="/style.css" />
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-menu-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/"><: $title :></a>
    </div>
    <div class="collapse navbar-collapse" id="nav-menu-1">
      <ul class="nav navbar-nav">
        <li><a href="/">Home</a></li>
      </ul>
    </div>
  </div>
</nav>
<: block body -> { :>default body<: } :>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<script>$(function(){$('pre > code').addClass('prettyprint');});</script>
</body>

@@ index.tx
: cascade base;
: override body -> {
<h1>Index of
: for process_path($path) -> $part {
/ <a href="<: $part.link :>"><: $part.name :></a>
: }
</h1>
<ul>
:   for $files -> $file {
<li><a href="<: $file.link :>"><: $file.name :></a></li>
:   }
</ul>
: } # endblock body

@@ md.tx
: cascade base;
: override body -> {
<h1>
: for process_path($path) -> $part {
/ <a href="<: $part.link :>"><: $part.name :></a>
: }
</h1>
: include paginate
: $content | mark_raw
: include paginate
: } # endblock body

@@ paginate.tx
<nav>
  <ul class="paginate">
: if $prev {
    <li class="prev"><a href="/<: $prev :>"><: $prev :></a></li>
: }
: if $next {
    <li class="next"><a href="/<: $next :>"><: $next :></a></li>
: }
  </ul>

__END__

=head1 NAME

Plack::App::Directory::Markdown - Serve translated HTML from markdown files from document root with directory index

=head1 SYNOPSIS

  # app.psgi
  use Plack::App::Directory::Markdown;
  my $app = Plack::App::Directory::Markdown->new->to_app;

  # app.psgi(with options)
  use Plack::App::Directory::Markdown;
  my $app = Plack::App::Directory::Markdown->new({
    root           => '/path/to/markdown_files',
    title          => 'page title',
    tx_path        => '/path/to/xslate_templates',
    markdown_class => 'Text::Markdown',
  })->to_app;

=head1 DESCRIPTION

This is a PSGI application for documentation with markdown.

=head1 CONFIGURATION

=over 4

=item root

Document root directory. Defaults to the current directory.

=item title

Page title. Defaults to 'Markdown'.

=item tx_path



( run in 1.293 second using v1.01-cache-2.11-cpan-9581c071862 )