Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move the feed templates to the Config.pm file

  • Loading branch information...
commit 31ba0676d0a698f86b7c4307d1b23da33792f124 1 parent 1ae764e
@szabgab authored
View
19 lib/Dwimmer/Feed/Collector.pm
@@ -8,8 +8,6 @@ our $VERSION = '0.27';
my $MAX_SIZE = 500;
my $TRIM_SIZE = 400;
-use Dwimmer::Feed::DB;
-
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use File::Path qw(mkpath);
@@ -18,6 +16,10 @@ use MIME::Lite ();
use Template;
use XML::Feed ();
+use Dwimmer::Feed::DB;
+use Dwimmer::Feed::Config;
+
+
#has 'sources' => (is => 'ro', isa => 'Str', required => 1);
has 'store' => (is => 'ro', isa => 'Str', required => 1);
has 'db' => (is => 'rw', isa => 'Dwimmer::Feed::DB');
@@ -68,6 +70,7 @@ sub collect {
alarm 0;
if ($err) {
main::LOG(" EXCEPTION: $err");
+ next;
}
if (not $feed) {
main::LOG(" ERROR: " . XML::Feed->errstr);
@@ -199,17 +202,19 @@ sub generate_html {
my $root = dirname dirname abs_path $0;
+ my $config = Dwimmer::Feed::Config->get_config_hash($self->db);
my $t = Template->new({ ABSOLUTE => 1, });
- $t->process("$root/views/feed_index.tt", {entries => \@entries, %site}, "$dir/index.html") or die $t->error;
- $t->process("$root/views/feed_rss.tt", {entries => \@entries, %site}, "$dir/rss.xml") or die $t->error;
- $t->process("$root/views/feed_atom.tt", {entries => \@entries, %site}, "$dir/atom.xml") or die $t->error;
- $t->process("$root/views/feed_feeds.tt", {entries => \@feeds}, "$dir/feeds.html") or die $t->error;
+ my $index_tt = $config->get($self->db, 'index_tt');
+ $t->process(\$index_tt, {entries => \@entries, %site}, "$dir/index.html") or die $t->error;
+ $t->process(\$config->get($self->db, 'rss_tt'), {entries => \@entries, %site}, "$dir/rss.xml") or die $t->error;
+ $t->process(\$config->get($self->db, 'atom_tt'), {entries => \@entries, %site}, "$dir/atom.xml") or die $t->error;
+ $t->process(\$config->get($self->db, 'feeds_tt'), {entries => \@feeds}, "$dir/feeds.html") or die $t->error;
foreach my $date (keys %entries_on) {
my ($year, $month, $day) = split /-/, $date;
my $path = "$dir/archive/$year/$month";
mkpath $path;
- $t->process("$root/views/feed_index.tt", {entries => $entries_on{$date}, %site}, "$path/$day.html") or die $t->error;
+ $t->process(\$index_tt, {entries => $entries_on{$date}, %site}, "$path/$day.html") or die $t->error;
}
return;
View
288 lib/Dwimmer/Feed/Config.pm
@@ -2,6 +2,8 @@ package Dwimmer::Feed::Config;
use strict;
use warnings;
+my %DEFAULT;
+
sub get_config_hash {
my ($self, $db) = @_;
@@ -14,5 +16,291 @@ sub get_config {
my $config = $db->get_config;
}
+sub get {
+ my ($self, $db, $field) = @_;
+
+ # TODO later check db as well
+ return $DEFAULT{$field};
+
+ #my $config = $db->get_config;
+}
+
+
+$DEFAULT{atom_tt} = q{
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+<title>[% title %]</title>
+<subtitle>[% subtitle %]></subtitle>
+<link href="[% url %]"/>
+<id>[% id %]</id>
+<updated>[% last_build_date %]</updated>
+
+<author>
+ <name>[% admin_name %]</name>
+ <email>[% admin_email %]</email>
+</author>
+<generator uri="http://search.cpan.org/dist/Dwimmer/" version="[% dwimmer_version %]">Dwimmer</generator>
+
+[% FOR e IN entries %]
+<entry>
+ <author>
+ <name>[% e.author_name %]</name>
+ <uri>[% e.author_uri %]</uri>
+ </author>
+ <title>[% e.title %]</title>
+ <link href="[% e.link %]"/>
+ <id>[% e.id %]</id>
+ <updated>[% e.issued %]</updated>
+ <published>[% e.issued %]</published>
+ <summary><![CDATA[[% e.display %]]]></summary>
+</entry>
+[% END %]
+
+</feed>
+};
+
+$DEFAULT{rss_tt} = q{
+<?xml version="1.0"?>
+<?xml-stylesheet title="CSS_formatting" type="text/css" href="http://www.interglacial.com/rss/rss.css"?>
+<rss version="2.0"><channel>
+
+<link>[% url %]</link>
+<title>[% title %]</title>
+<description>[% description %]</description>
+<language>[% language %]</language>
+<lastBuildDate>[% last_build_date %]</lastBuildDate>
+<webMaster>[% admin_email %]</webMaster>
+
+<docs>http://www.interglacial.com/rss/about.html</docs>
+
+[% FOR e IN entries %]
+<item>
+ <title>[% e.title %]</title>
+ <link>[% e.link %]</link>
+ <description><![CDATA[[% e.display %]]]></description>
+ <dc:date>[% e.issued %]</dc:date>
+</item>
+[% END %]
+
+</channel></rss>
+};
+
+$DEFAULT{index_tt} = q{
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
+<head>
+<title>Perlsphere - the Perl blog aggregator</title>
+ <link href="/rss.xml" rel="alternate" type="application/rss+xml" title ="Perlsphere RSS Feed" />
+ <link href="/atom.xml" rel="alternate" type="application/atom+xml" title ="Perlspehere ATOM Feed" />
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
+</head>
+<body>
+<style>
+html {
+ margin: 0;
+ padding: 0;
+}
+body {
+ margin: 0;
+ padding: 0;
+ /* text-align: center;*/
+ width: 800px;
+ margin-left: auto;
+ margin-right: auto;
+ font-size: 16px;
+
+}
+#header_text {
+}
+
+.entry {
+ background-color: #DDD;
+ padding: 10px;
+ margin-top: 10px;
+ margin-bottom: 10px;
+
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border: 1px solid #000;
+
+ min-height: 220px;
+ height:auto !important;
+ min-height: 220px;
+}
+
+.left {
+ width: 675px;
+ position: relative;
+ background-color: #EEEEEE;
+
+ padding: 5px;
+
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border: 1px solid #000;
+
+}
+
+.entry_info {
+ margin-top: 10px;
+ width: 675px;
+ background-color: #E4E4E4;
+ padding: 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border: 1px solid #000;
+}
+
+.social_link {
+ float: right;
+ position: relative;
+ width: 70px;
+ background-color: #DFDFDF;
+ text-align: center;
+
+ padding: 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border: 1px solid #000;
+
+}
+
+
+.title {
+ font-size: 24px;
+ font-weight: bold;
+}
+.title a {
+ text-decoration: none;
+}
+</style>
+
+
+ <h1>Perlsphere</h1>
+ <div id="header_text">
+ The Perl firehose! The Web's biggest collection of Perl blogs.
+ If you'd like your Perl blog or tech blog's Perl category to appear here, send mail to szabgab@gmail.com
+ (Please have several posts already). <a href="/feeds.html">feeds</a>.
+ </div>
+
+[% FOR e IN entries %]
+ <div class="entry">
+
+ <div class="social_link">
+ <a href="http://twitter.com/share" class="twitter-share-button"
+ data-text="[% e.title %]" data-url="[% e.link %]" data-count="vertical" data-via="szabgab">Tweet</a>
+ <script type="text/javascript" src="http://platform.twitter.com/widgets.js">
+ </script>
+
+ <script>reddit_url='[% e.link %]'</script>
+ <script>reddit_title='[% e.title %]'</script>
+ <script type="text/javascript" src="http://reddit.com/button.js?t=2"></script>
+
+
+ <g:plusone size="tall" href="[% e.link %]"></g:plusone>
+
+<!--
+ <a name="fb_share" type="box_count" class="fb_share"
+ share_url="[% e.link %]">Share</a>
+ <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
+-->
+
+ </div>
+
+ <div class="left">
+ <div class="source"><a href="[% e.source_url %]">[% e.source_name %]</a></div>
+ <div class="title"><a href="[% e.link %]">[% e.title %]</a></div>
+ <div class="summary">
+ [% e.display %]
+ </div>
+ </div>
+ <div class="entry_info">
+ <div class="date">Posted on [% e.issued %]</div>
+ <div class="permalink">For the full article visit <a href="[% e.link %]">[% e.title %]</a></div>
+ </div>
+ </div>
+[% END %]
+
+<div>
+<div>
+Last updated: [% last_update %]
+</div>
+</div>
+[% track %]
+</body>
+</html>
+};
+
+
+$DEFAULT{feed_tt} = q{
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
+<head>
+<title>Perlsphere - the Perl blog aggregator</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+</head>
+<body>
+<style>
+html {
+ margin: 0;
+ padding: 0;
+}
+body {
+ margin: 0;
+ padding: 0;
+ /* text-align: center;*/
+ width: 800px;
+ margin-left: auto;
+ margin-right: auto;
+ font-size: 16px;
+
+}
+#header_text {
+}
+
+.entry {
+ background-color: #DDD;
+ padding: 10px;
+ margin-top: 10px;
+ margin-bottom: 10px;
+
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border: 1px solid #000;
+
+}
+.title {
+ font-size: 24px;
+ font-weight: bold;
+}
+.title a {
+ text-decoration: none;
+}
+</style>
+
+
+ <h1>Perlsphere feeds</h1>
+ <a href="/">home</a>
+
+[% FOR e IN entries %]
+ <div class="entry">
+ <div class="title"><a href="[% e.url %]">[% e.title %]</a></div>
+ [% IF e.twitter %]
+ <div class="twitter"><a href="https://twitter.com/#!/[% e.twitter %]">@[% e.twitter %]</a></div>
+ [% END %]
+ <div class="latest">Latest: <a href="[% e.latest_entry.link %]">[% e.latest_entry.title %]</a> on [% e.latest_entry.issued %]</div>
+ </div>
+[% END %]
+
+</div>
+[% track %]
+</body>
+</html>
+};
+
+
1;
View
31 views/feed_atom.tt
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
-
-<title>[% title %]</title>
-<subtitle>[% subtitle %]></subtitle>
-<link href="[% url %]"/>
-<id>[% id %]</id>
-<updated>[% last_build_date %]</updated>
-
-<author>
- <name>[% admin_name %]</name>
- <email>[% admin_email %]</email>
-</author>
-<generator uri="http://search.cpan.org/dist/Dwimmer/" version="[% dwimmer_version %]">Dwimmer</generator>
-
-[% FOR e IN entries %]
-<entry>
- <author>
- <name>[% e.author_name %]</name>
- <uri>[% e.author_uri %]</uri>
- </author>
- <title>[% e.title %]</title>
- <link href="[% e.link %]"/>
- <id>[% e.id %]</id>
- <updated>[% e.issued %]</updated>
- <published>[% e.issued %]</published>
- <summary><![CDATA[[% e.display %]]]></summary>
-</entry>
-[% END %]
-
-</feed>
View
63 views/feed_feeds.tt
@@ -1,63 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
-<head>
-<title>Perlsphere - the Perl blog aggregator</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-</head>
-<body>
-<style>
-html {
- margin: 0;
- padding: 0;
-}
-body {
- margin: 0;
- padding: 0;
- /* text-align: center;*/
- width: 800px;
- margin-left: auto;
- margin-right: auto;
- font-size: 16px;
-
-}
-#header_text {
-}
-
-.entry {
- background-color: #DDD;
- padding: 10px;
- margin-top: 10px;
- margin-bottom: 10px;
-
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- border: 1px solid #000;
-
-}
-.title {
- font-size: 24px;
- font-weight: bold;
-}
-.title a {
- text-decoration: none;
-}
-</style>
-
-
- <h1>Perlsphere feeds</h1>
- <a href="/">home</a>
-
-[% FOR e IN entries %]
- <div class="entry">
- <div class="title"><a href="[% e.url %]">[% e.title %]</a></div>
- [% IF e.twitter %]
- <div class="twitter"><a href="https://twitter.com/#!/[% e.twitter %]">@[% e.twitter %]</a></div>
- [% END %]
- <div class="latest">Latest: <a href="[% e.latest_entry.link %]">[% e.latest_entry.title %]</a> on [% e.latest_entry.issued %]</div>
- </div>
-[% END %]
-
-</div>
-[% track %]
-</body>
-</html>
View
145 views/feed_index.tt
@@ -1,145 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
-<head>
-<title>Perlsphere - the Perl blog aggregator</title>
- <link href="/rss.xml" rel="alternate" type="application/rss+xml" title ="Perlsphere RSS Feed" />
- <link href="/atom.xml" rel="alternate" type="application/atom+xml" title ="Perlspehere ATOM Feed" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
- <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
-</head>
-<body>
-<style>
-html {
- margin: 0;
- padding: 0;
-}
-body {
- margin: 0;
- padding: 0;
- /* text-align: center;*/
- width: 800px;
- margin-left: auto;
- margin-right: auto;
- font-size: 16px;
-
-}
-#header_text {
-}
-
-.entry {
- background-color: #DDD;
- padding: 10px;
- margin-top: 10px;
- margin-bottom: 10px;
-
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- border: 1px solid #000;
-
- min-height: 220px;
- height:auto !important;
- min-height: 220px;
-}
-
-.left {
- width: 675px;
- position: relative;
- background-color: #EEEEEE;
-
- padding: 5px;
-
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- border: 1px solid #000;
-
-}
-
-.entry_info {
- margin-top: 10px;
- width: 675px;
- background-color: #E4E4E4;
- padding: 5px;
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- border: 1px solid #000;
-}
-
-.social_link {
- float: right;
- position: relative;
- width: 70px;
- background-color: #DFDFDF;
- text-align: center;
-
- padding: 5px;
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- border: 1px solid #000;
-
-}
-
-
-.title {
- font-size: 24px;
- font-weight: bold;
-}
-.title a {
- text-decoration: none;
-}
-</style>
-
-
- <h1>Perlsphere</h1>
- <div id="header_text">
- The Perl firehose! The Web's biggest collection of Perl blogs.
- If you'd like your Perl blog or tech blog's Perl category to appear here, send mail to szabgab@gmail.com
- (Please have several posts already). <a href="/feeds.html">feeds</a>.
- </div>
-
-[% FOR e IN entries %]
- <div class="entry">
-
- <div class="social_link">
- <a href="http://twitter.com/share" class="twitter-share-button"
- data-text="[% e.title %]" data-url="[% e.link %]" data-count="vertical" data-via="szabgab">Tweet</a>
- <script type="text/javascript" src="http://platform.twitter.com/widgets.js">
- </script>
-
- <script>reddit_url='[% e.link %]'</script>
- <script>reddit_title='[% e.title %]'</script>
- <script type="text/javascript" src="http://reddit.com/button.js?t=2"></script>
-
-
- <g:plusone size="tall" href="[% e.link %]"></g:plusone>
-
-<!--
- <a name="fb_share" type="box_count" class="fb_share"
- share_url="[% e.link %]">Share</a>
- <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
--->
-
- </div>
-
- <div class="left">
- <div class="source"><a href="[% e.source_url %]">[% e.source_name %]</a></div>
- <div class="title"><a href="[% e.link %]">[% e.title %]</a></div>
- <div class="summary">
- [% e.display %]
- </div>
- </div>
- <div class="entry_info">
- <div class="date">Posted on [% e.issued %]</div>
- <div class="permalink">For the full article visit <a href="[% e.link %]">[% e.title %]</a></div>
- </div>
- </div>
-[% END %]
-
-<div>
-<div>
-Last updated: [% last_update %]
-</div>
-</div>
-[% track %]
-</body>
-</html>
View
23 views/feed_rss.tt
@@ -1,23 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet title="CSS_formatting" type="text/css" href="http://www.interglacial.com/rss/rss.css"?>
-<rss version="2.0"><channel>
-
-<link>[% url %]</link>
-<title>[% title %]</title>
-<description>[% description %]</description>
-<language>[% language %]</language>
-<lastBuildDate>[% last_build_date %]</lastBuildDate>
-<webMaster>[% admin_email %]</webMaster>
-
-<docs>http://www.interglacial.com/rss/about.html</docs>
-
-[% FOR e IN entries %]
-<item>
- <title>[% e.title %]</title>
- <link>[% e.link %]</link>
- <description><![CDATA[[% e.display %]]]></description>
- <dc:date>[% e.issued %]</dc:date>
-</item>
-[% END %]
-
-</channel></rss>
Please sign in to comment.
Something went wrong with that request. Please try again.