Class: ODDB::Export::Rss::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb/export/rss.rb

Direct Known Subclasses

Feedback

Instance Method Summary collapse

Constructor Details

#initializeExporter

Returns a new instance of Exporter.



11
12
13
14
15
# File 'lib/oddb/export/rss.rb', line 11

def initialize
  @rss_dir = File.join(ODDB.config.var, 'rss')
  @name = self.class.name[/[^:]+$/]
  @filename = @name.downcase + ".rss"
end

Instance Method Details

#exportObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oddb/export/rss.rb', line 16

def export
  items = sorted_items
  return if(items.empty?)
  Export.l10n_sessions { |session|
    dir = File.join(@rss_dir, session.language)
    FileUtils.mkdir_p(dir)
    path = File.join(dir, @filename)
    tmp = File.join(dir, '.' << @filename)
    File.open(tmp, 'w') { |io|
      io.puts rss(items, session)
    }
    File.rename(tmp, path)
  }
end

#rss(items, session) ⇒ Object



30
31
32
33
34
35
# File 'lib/oddb/export/rss.rb', line 30

def rss items, session
  require "oddb/html/view/rss/#{@name.downcase}"
  klass = Html::View::Rss.const_get @name
  view = klass.new(items, session, nil)
  view.to_html(CGI.new('html4'))
end