Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add lib dir & move some function

  • Loading branch information...
commit 55f828059b647784a904787ba25c18a51c334239 1 parent bcd1580
@masartz authored
Showing with 62 additions and 32 deletions.
  1. +19 −30 app.psgi
  2. +41 −0 lib/MyApp/Parser.pm
  3. +2 −2 templates/index.html
View
49 app.psgi
@@ -1,11 +1,12 @@
use strict;
use warnings;
-
+
use Plack::Builder;
use Plack::Request;
use Template;
-use XML::Feed;
-use Encode;
+
+use lib './lib';
+use MyApp::Parser;
my $template_config = { INCLUDE_PATH => './templates' };
my $config = require "config.pl";
@@ -14,8 +15,20 @@ my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
- my $timelines = _parse_timeline();
- my $commit_logs = _format_log( $timelines );
+ my $timelines;
+ if ( $req->path eq '/feed' ){
+ $timelines = MyApp::Parser::get_from_feed(
+ $config->{feed_url}
+ );
+ }
+ elsif( $req->path eq 'log' ){
+# $timelines = MyApp::Parser::get_from_log();
+ }
+ else{
+ return [ 404, [ "Content-Type" => "text/plain" ], ["Not Found"] ];
+ }
+
+ my $commit_logs = _format_commit_log( $timelines );
my $args = { commit_logs => $commit_logs } if defined $commit_logs;
my $res = $req->new_response(200);
@@ -32,32 +45,8 @@ sub _render {
return $out;
}
-sub _parse_timeline {
- my $feed = XML::Feed->parse(
- URI->new( $config->{feed_url} ) )
- or return [];
- my @timelines;
- for my $entry ( $feed->entries() ) {
-
- my $comment = $entry->content->body;
- $comment =~ s!^<p>!!;
- $comment =~ s!</p>$!!;
-
- my %row = (
- title => $entry->title,
- link => $entry->link,
- author => $entry->author,
- timestamp => $entry->issued->datetime,
- comment => $comment,
- );
- %row = map { $_ => Encode::encode_utf8( $row{$_} ) } keys %row;
-
- push @timelines , \%row;
- }
- return \@timelines;
-}
-sub _format_log{
+sub _format_commit_log{
my $timeline = shift;
my %logs;
View
41 lib/MyApp/Parser.pm
@@ -0,0 +1,41 @@
+package MyApp::Parser;
+
+use strict;
+use warnings;
+
+use XML::Feed;
+use Encode;
+use URI;
+
+sub get_from_feed {
+ my $feed_url = shift;
+
+ my $feed = XML::Feed->parse(
+ URI->new( $feed_url )
+ ) or return [];
+
+ my @timelines;
+ for my $entry ( $feed->entries() ) {
+
+ my $comment = $entry->content->body;
+ $comment =~ s:^<p>::;
+ $comment =~ s:</p>$::;
+
+ my %row = (
+ title => $entry->title,
+ link => $entry->link,
+ author => $entry->author,
+ timestamp => $entry->issued->datetime,
+ comment => $comment,
+ );
+ %row = map { $_ => Encode::encode_utf8( $row{$_} ) } keys %row;
+
+ push @timelines , \%row;
+ }
+ return \@timelines;
+}
+
+sub get_from_log {
+}
+
+1;
View
4 templates/index.html
@@ -3,7 +3,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-<title>parse timeline</title>
+<title>sort timeline</title>
<script src="static/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
@@ -18,7 +18,7 @@
</head>
<body>
-<h1><a href="/">parse timeline</a></h1></div>
+<h1><a href="/">sort timeline</a></h1></div>
[% IF commit_logs -%]
<dl>
Please sign in to comment.
Something went wrong with that request. Please try again.