Class: Bwkfanboy::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/bwkfanboy/generate.rb

Class Method Summary collapse

Class Method Details

.atom(src) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
# File 'lib/bwkfanboy/generate.rb', line 20

def self.atom(src)
  feed = RSS::Maker.make("atom") { |maker|
    maker.channel.id = src['channel']['id']
    maker.channel.updated = src['channel']['updated']
    maker.channel.author = src['channel']['author']
    maker.channel.title = src['channel']['title']
    
    maker.channel.links.new_link {|i|
      i.href = src['channel']['link']
      i.rel = 'alternate'
      i.type = 'text/html' # eh
    }
    
    maker.items.do_sort = true

    src['x_entries'].each { |i|
      maker.items.new_item do |item|
        item.links.new_link {|k|
          k.href = i['link']
          k.rel = 'alternate'
          k.type = 'text/html' # only to make happy crappy pr2nntp gateway
        }
        item.title = i['title']
        item.author = i['author']
        item.updated = i['updated']
        item.content.type = src['channel']['x_entries_content_type']
  
        case item.content.type
        when 'text'
          item.content.content = i['content']
        when 'html'
          item.content.content = i['content']
        else
          item.content.xhtml = i['content']
        end
      end
    }
  }

  return feed
end

.validate(t) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/bwkfanboy/generate.rb', line 11

def self.validate(t)
  schema = Bwkfanboy::Utils.gem_dir_system() + '/schema.js'
  begin
    JSON::Schema.validate(t, JSON.parse(File.read(schema)))
  rescue
    Bwkfanboy::Utils.errx(1, "JSON validation with schema (#{schema}) failed");
  end
end