Class: JekyllImport::Importers::GoogleReader

Inherits:
JekyllImport::Importer show all
Defined in:
lib/jekyll-import/importers/google_reader.rb

Class Method Summary collapse

Methods inherited from JekyllImport::Importer

inherited, run, stringify_keys, subclasses

Class Method Details

.process(options) ⇒ Object

Process the import.

source - a URL or a local file String.

Returns nothing.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jekyll-import/importers/google_reader.rb', line 35

def self.process(options)
  source = options.fetch('source')

  open(source) do |content|
    feed = RSS::Parser.parse(content)

    raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless feed

    feed.items.each do |item|
      title = item.title.content.to_s
      formatted_date = Date.parse(item.published.to_s)
      post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
        i.downcase if i != ''
      end.compact.join('-')
      name = "#{formatted_date}-#{post_name}"

      header = {
        'layout' => 'post',
        'title' => title
      }

      FileUtils.mkdir_p("_posts")

      File.open("_posts/#{name}.html", "w") do |f|
        f.puts header.to_yaml
        f.puts "---\n\n"
        f.puts item.content.content.to_s
      end
    end
  end
end

.require_depsObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-import/importers/google_reader.rb', line 18

def self.require_deps
  JekyllImport.require_with_fallback(%w[
    rubygems
    rss
    fileutils
    safe_yaml
    open-url
    rexml/document
    date
  ])
end

.specify_options(c) ⇒ Object



14
15
16
# File 'lib/jekyll-import/importers/google_reader.rb', line 14

def self.specify_options(c)
  c.option 'source', '--source', 'Source XML file of Google Reader export'
end

.validate(options) ⇒ Object



8
9
10
11
12
# File 'lib/jekyll-import/importers/google_reader.rb', line 8

def self.validate(options)
  if options['source'].nil?
    abort "Missing mandatory option --source."
  end
end