Class: RSS2WikiHelper
- Inherits:
-
Object
- Object
- RSS2WikiHelper
- Defined in:
- lib/helpers/rss2wiki-helper.rb
Constant Summary collapse
- DEFAULT_SETTINGS =
{ :url => 'http://localhost:8000/rss/recent%20changes%20to%20this%20site', :pagename => nil, # If nil, uses channel title, :update_on_event => :hour, :author => 'AutomaticRSS2Wiki', }
Instance Method Summary collapse
- #escape(string) ⇒ Object
-
#initialize(wiki, settings = {}) ⇒ RSS2WikiHelper
constructor
A new instance of RSS2WikiHelper.
- #render ⇒ Object
- #update_rss ⇒ Object
- #update_wiki ⇒ Object
Constructor Details
#initialize(wiki, settings = {}) ⇒ RSS2WikiHelper
Returns a new instance of RSS2WikiHelper.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/helpers/rss2wiki-helper.rb', line 14 def initialize( wiki, settings = {} ) @settings = DEFAULT_SETTINGS.merge( settings ) @wiki = wiki update_rss update_wiki @wiki.watch_for(@settings[:update_on_event]) do update_rss update_wiki end end |
Instance Method Details
#escape(string) ⇒ Object
44 45 46 |
# File 'lib/helpers/rss2wiki-helper.rb', line 44 def escape( string ) string.tr('[]=>','') end |
#render ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/helpers/rss2wiki-helper.rb', line 29 def render content = "h1. #{@rss.channel.title}\n\n" @rss.items.each do |item| content << "# [[ #{escape(item.title)} => #{item.link} ]]\n" end content end |
#update_rss ⇒ Object
37 38 39 40 41 42 |
# File 'lib/helpers/rss2wiki-helper.rb', line 37 def update_rss $LOG.info "Updating feed" open(@settings[:url]) do |http| @rss = RSS::Parser.parse( http.read , false) end end |
#update_wiki ⇒ Object
25 26 27 |
# File 'lib/helpers/rss2wiki-helper.rb', line 25 def update_wiki @wiki.revise( @settings[:pagename] || @rss.channel.title, render, @rss.items.first.respond_to?('author') ? @rss.items.first. : "AutomaticRSS" ) end |