Class: Hoshi::View::RSS2

Inherits:
Hoshi::View show all
Defined in:
lib/hoshi/view/rss2.rb

Defined Under Namespace

Classes: InvalidChannelError, InvalidItemError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hoshi::View

[], #_tag, #append!, build, #clear!, #comment, #doc, #doctype, dtd!, #entity, #initialize, #method_missing, open_tags, permissive!, permissive?, #raw, #render_cgi, #safe, self_closing_tags, strict!, strict?, tag, #tag, tags

Constructor Details

This class inherits a constructor from Hoshi::View

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hoshi::View

Instance Attribute Details

#channel_blockObject

Returns the value of attribute channel_block.



13
14
15
# File 'lib/hoshi/view/rss2.rb', line 13

def channel_block
  @channel_block
end

#item_blockObject

Returns the value of attribute item_block.



13
14
15
# File 'lib/hoshi/view/rss2.rb', line 13

def item_block
  @item_block
end

#itemsObject

Returns the value of attribute items.



13
14
15
# File 'lib/hoshi/view/rss2.rb', line 13

def items
  @items
end

Class Method Details

.content_typeObject



17
18
19
# File 'lib/hoshi/view/rss2.rb', line 17

def self.content_type
  'application/rss+xml'
end

Instance Method Details

#def_channel(&b) ⇒ Object



21
22
23
# File 'lib/hoshi/view/rss2.rb', line 21

def def_channel &b
  self.channel_block = b
end

#each_item(&b) ⇒ Object



25
26
27
# File 'lib/hoshi/view/rss2.rb', line 25

def each_item &b
  self.item_block = b
end

#pub_date(dt) ⇒ Object

A small helper so you can just pass a date, time, or string rather than worrying about format.



31
32
33
34
35
36
37
38
39
40
# File 'lib/hoshi/view/rss2.rb', line 31

def pub_date dt
  dt =
    case dt
    when Time, Date, DateTime
      dt.rfc822
    else
      dt
    end
  pubDate dt
end

#renderObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hoshi/view/rss2.rb', line 42

def render
  clear!
  doctype
  rss(:version => '2.0') {
    channel {
      channel_block.call
      items.each { |i| 
        item { item_block.call i }
      }
    }
  }
  super()
end