aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rss2html
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-05-14 20:46:15 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-05-14 20:46:15 +0200
commit4dea5f74319a743a88f77f4efe0226054a955a25 (patch)
treeebe9358407dd5e4a4f4c0b90ef4b6c98c77da54d /lib/rss2html
parent9f1fd3290c2b38345c77eea814baf95c4002b19e (diff)
downloadrss2html-4dea5f74319a743a88f77f4efe0226054a955a25.tar.gz
rss2html-4dea5f74319a743a88f77f4efe0226054a955a25.tar.bz2
rss2html-4dea5f74319a743a88f77f4efe0226054a955a25.zip
Separate lib and executable.
Add a separate executable, and move the rendering of the feeds into the feed class.
Diffstat (limited to 'lib/rss2html')
-rw-r--r--lib/rss2html/feed.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/rss2html/feed.rb b/lib/rss2html/feed.rb
index a2f3db4..0f3f01e 100644
--- a/lib/rss2html/feed.rb
+++ b/lib/rss2html/feed.rb
@@ -16,12 +16,17 @@
require 'rss'
require 'open-uri'
+require 'erb'
class Feed
attr_reader :title, :url
def initialize(title, args)
@title, @url = title, args['url']
+
+ @feed_header = load_template('feed_header.html.erb')
+ @feed_footer = load_template('feed_footer.html.erb')
+ @item_template = load_template('item.html.erb')
end
def fetch
@@ -33,4 +38,23 @@ class Feed
end
end
end
+
+ def render
+ feed = self
+ output = @feed_header.result(binding)
+
+ fetch do |entry|
+ item = FeedItem.new(entry)
+ output += @item_template.result(binding)
+ end
+
+ output += @feed_footer.result(binding)
+ end
+
+ private
+
+ def load_template(t)
+ view_path = File.join(File.dirname(__FILE__), 'views')
+ ERB.new(IO.read(File.join(view_path, t)))
+ end
end