Permalink
Browse files

fix name.

  • Loading branch information...
1 parent 037890d commit 003befe767af5465506f320e1ef24e6347ad809e @s-aska committed Apr 22, 2011
View
@@ -1,4 +1,4 @@
-Revision history for Plack-App-Document
+Revision history for DocLife
0.01 Wed Apr 20 15:10:36 UTC 2011
First version, released
View
@@ -1,7 +1,7 @@
use inc::Module::Install;
-name 'Plack-App-Document';
-all_from 'lib/Plack/App/Document.pm';
+name 'DocLife';
+all_from 'lib/DocLife.pm';
requires 'Path::Class';
requires 'Plack';
requires 'Pod::Simple::XHTML';
View
@@ -1,40 +1,40 @@
-# Plack::App::Document
+# DocLife
Document Viewer written in Perl, to run under Plack.
-- Local Pod Viewer
-- Local Markdown Viewer
+- Pod Viewer
+- Markdown Viewer
## Author's Message (Japanese)
CPAN Authorであれば皆ローカルに似たような物を作っていそうですが、標準化できそうな部分を切り出して公開することにしました。
Markdownはgithubに上げる前の下書きを少し意識しましたが、github独自の拡張記法は一切ケアしていません。
-App::MarkdownBinder, App::MarkdownDiary という拡張アプリの実装例がexampleに同梱されています、作者が実際に利用しています。(以下DEMO参照)
+DocLife::Note, App::Diary という拡張アプリの実装例がexampleに同梱されています、作者が実際に利用しています。(以下DEMO参照)
Plack::Builderのmount機能がVirtualHostも兼ねているので上げ落としも楽です、またコンテンツはDropboxで管理しているのでローカルのエディタで更新しています。
enjoy document life!
## INSTALL
- cpanm https://github.com/s-aska/plack-app-document/tarball/master
+ cpanm https://github.com/s-aska/DocLife/tarball/master
## RUN
- plackup -MPlack::App::Document::Pod -e 'Plack::App::Document::Pod->new( root => "./lib" )->to_app'
+ plackup -MDocLife::Pod -e 'DocLife::Pod->new( root => "./lib" )->to_app'
## DEMO
- demo: <http://pad.demo.7kai.org/>
-- author's blog: <http://blog.7kai.org/> powered by App::MarkdownDiary
-- author's wiki: <http://doc.7kai.org/> powered by App::MarkdownBinder
+- author's blog: <http://blog.7kai.org/> powered by DocLife::Blog
+- author's note: <http://doc.7kai.org/> powered by DocLife::Note
## SUPPORT AND DOCUMENTATION
-- github: <https://github.com/s-aska/plack-app-document>
-- perldoc `perldoc Plack::App::Document`
+- github: <https://github.com/s-aska/DocLife>
+- perldoc `perldoc DocLife`
## LICENSE AND COPYRIGHT
View
@@ -1,18 +1,18 @@
use strict;
use Plack::Builder;
use Plack::App::File;
-use Plack::App::Document;
-use Plack::App::Document::Pod;
-use Plack::App::Document::Markdown;
+use DocLife;
+use DocLife::Pod;
+use DocLife::Markdown;
use App::MarkdownBinder;
use App::MarkdownDiary;
-my $pod_app = Plack::App::Document::Pod->new(
+my $pod_app = DocLife::Pod->new(
root => '../lib',
base_url => '/pod/'
);
-my $doc_app = Plack::App::Document::Markdown->new(
+my $doc_app = DocLife::Markdown->new(
root => './doc',
suffix => '.md',
base_url => '/doc/'
@@ -4,7 +4,7 @@ App::MarkdownDiary は簡易blogです。
Markdown形式のテキストファイルのみで構成、WebUIなし、DBなし、拡張文法なし。
-この割り切りによって植性の高いblogとして完成されています
+この割り切りによって移植性の高いblogとして完成されています
DISQUS, zenback 等外部サービスを利用すればコメント管理を内蔵する必要もありません。
@@ -34,12 +34,14 @@
</head>
<body>
<header>
-<h1>Plack::App::Document Demo</h1>
+<h1>DocLife Demo</h1>
</header>
<article>
+<p>このサイトはDocLifeのデモページです、各モジュールの動作を見ることが出来ます。</p>
+<p>このサイト自体のソースは<a href="https://github.com/s-aska/DocLife">github</a>のexampleにあります。</p>
<ul>
-<li><a href="/pod/">Plack::App::Document::Pod</a></li>
-<li><a href="/doc/">Plack::App::Document::Markdown</a></li>
+<li><a href="/pod/">DocLife::Pod</a></li>
+<li><a href="/doc/">DocLife::Markdown</a></li>
<li><a href="/wiki/">App::MarkdownBinder</a> (Ajax Document Viewer)</li>
<li><a href="/blog/">App::MarkdownDiary</a> (blog)</li>
</ul>
@@ -2,7 +2,7 @@ package App::MarkdownBinder;
use strict;
use warnings;
-use parent 'Plack::App::Document';
+use parent 'DocLife';
use Plack::Util::Accessor qw(title tx);
use Encode;
use Encode::Locale;
@@ -2,7 +2,7 @@ package App::MarkdownDiary;
use strict;
use warnings;
-use parent 'Plack::App::Document';
+use parent 'DocLife';
use Plack::Util::Accessor qw(tx title footer rss_url viewdir tmpdir max_recents max_disp);
use Calendar::Simple;
use Cwd 'abs_path';
View
@@ -0,0 +1,12 @@
+blib*
+Makefile
+Makefile.old
+Build
+Build.bat
+_build*
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+Plack-App-Markdown-*
View
@@ -0,0 +1,197 @@
+package DocLife;
+
+use strict;
+use warnings;
+our $VERSION = '0.01';
+
+use parent qw( Plack::Component );
+use Cwd 'abs_path';
+use Digest::MD5;
+use File::Find;
+use File::Spec;
+use URI::Escape;
+use Path::Class;
+use Plack::Request;
+use Plack::Util::Accessor qw(
+ base_url
+ root
+ suffix
+);
+
+sub prepare_app {
+ my ($self, $env) = @_;
+ $self->base_url('/') unless defined $self->base_url;
+ $self->root(dir(abs_path($self->root || './')));
+}
+
+sub call {
+ my ($self, $env) = @_;
+
+ my $req = Plack::Request->new($env);
+ my $res = $req->new_response(200);
+ $res->content_type('text/html; charset=UTF-8');
+
+ if ($req->path eq '/') {
+ $self->toppage($req, $res);
+ }
+ elsif ($req->path=~m|\Q/../| or $req->path=~m|\Q//|) {
+ $self->forbidden($req, $res);
+ }
+ else {
+ $self->page($req, $res);
+ }
+ $res->finalize;
+}
+
+sub format {
+ my ($self, $req, $res, $file) = @_;
+ $res->content_type('text/plain; charset=UTF-8');
+ $res->body($file->slurp);
+}
+
+sub page {
+ my ($self, $req, $res) = @_;
+
+ my $file = file($self->root, $req->path);
+ $file = file($self->root, $req->path . $self->suffix) if !-f $file and defined $self->suffix;
+ if (-f $file) {
+ $self->format($req, $res, $file);
+ }
+ else {
+ $self->not_found($req, $res);
+ }
+}
+
+sub toppage {
+ my ($self, $req, $res) = @_;
+
+ my $body = $self->html_header;
+ my $suffix = $self->suffix;
+ my $root = $self->root;
+ my @files;
+ find( sub {
+ return unless -f $_;
+ return if length $suffix and $_!~m|\Q$suffix\E$|;
+ push @files, $File::Find::name;
+ }, $root );
+ $body.= "<ul>\n";
+ for my $file ( sort @files ) {
+ $file=~s|^\Q$root\E/?||;
+ my $url = $self->base_url . uri_escape($file);
+ if (length $suffix) {
+ $file=~s|\Q$suffix\E$||;
+ }
+ $body.= qq{<li><a href="$url">$file</a></li>\n};
+ }
+ $body.= "</ul>\n";
+ $body.= $self->html_footer;
+ $res->body($body);
+}
+
+sub forbidden {
+ my ($self, $req, $res) = @_;
+ $res->status(403);
+ $res->body('Forbidden.');
+}
+
+sub not_found {
+ my ($self, $req, $res) = @_;
+ $res->status(404);
+ $res->body('Not Found.');
+}
+
+sub html_header {
+<<"EOF"
+<!DOCTYPE html>
+<html>
+<head>
+<title>Index</title>
+</head>
+<body>
+EOF
+}
+
+sub html_footer {
+<<"EOF"
+</body>
+</html>
+EOF
+}
+
+=head1 NAME
+
+DocLife - Document Viewer written in Perl, to run under Plack.
+
+=head1 SYNOPSIS
+
+ # app.psgi
+ use DocLife::Pod;
+ DocLife::Pod->new( root => "./lib" );
+
+ # one-liner
+ plackup -MDocLife::Pod -e 'DocLife::Pod->new( root => "./lib" )->to_app'
+
+=head1 How To Mount
+
+need base_url option.
+
+ # app.psgi
+ use Plack::Builder;
+ use DocLife::Pod;
+ use DocLife::Markdown;
+
+ my $pod_app = DocLife::Pod->new(
+ root => '../lib',
+ base_url => '/pod/'
+ );
+
+ my $doc_app = DocLife::Markdown->new(
+ root => './doc',
+ suffix => '.md',
+ base_url => '/doc/'
+ );
+
+ builder {
+ mount '/pod' => $pod_app;
+ mount '/doc' => $doc_app;
+ };
+
+=head1 CONFIGURATION
+
+=over 4
+
+=item root
+
+Document root directory. Defaults to the current directory.
+
+=back
+
+=over 4
+
+=item base_url
+
+Specifies a base URL for all URLs on a index page. Defaults to the `/`.
+
+=back
+
+=over 4
+
+=item suffix
+
+Show only files that match the suffix. No url suffix.
+
+=back
+
+=head1 SEE ALSO
+
+L<Plack>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright Shinichiro Aska.
+
+This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
Oops, something went wrong.

0 comments on commit 003befe

Please sign in to comment.