Module: TinyAtom

Defined in:
lib/tinyatom/feed.rb

Defined Under Namespace

Classes: Feed

Constant Summary collapse

EnclosureOptionalAttrs =

param name => tag name

{
:enclosure_length => :length,
}
MediaThumbnailOptionalAttrs =

param name => tag name

{
:media_thumbnail_height => :height,
:media_thumbnail_width => :width,
:media_thumbnail_time => :time,
}

Class Method Summary collapse

Class Method Details

.author(markup, h) ⇒ Object

Add author tags if present.



84
85
86
87
88
89
90
91
92
# File 'lib/tinyatom/feed.rb', line 84

def author(markup, h)
  if h[:author_name]
    markup.author {
      markup.name h[:author_name]
      markup.email(h[:author_email])  if h[:author_email]
      markup.uri(h[:author_uri])  if h[:author_uri]
    }
  end
end

.enclosure(markup, h) ⇒ Object

Add enclosure tags if present.



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tinyatom/feed.rb', line 100

def enclosure(markup, h)
  if h[:enclosure_type] and h[:enclosure_href] and h[:enclosure_title]
    options = {}
    h.each do |k,v|
      if EnclosureOptionalAttrs.include?(k)
        options[EnclosureOptionalAttrs[k]] = v
      end
    end

    link markup, 'enclosure', h[:enclosure_type], h[:enclosure_href],
      h[:enclosure_title], options
  end
end

Create link tag.



144
145
146
147
148
149
150
151
# File 'lib/tinyatom/feed.rb', line 144

def link(markup, rel, type, href, title, options={})
  markup.link({
    :rel => rel,
    :type => type,
    :href => href,
    :title => title
    }.merge(options))
end

.media_thumbnail(markup, h) ⇒ Object

Add media:thumbnail tags if present.



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/tinyatom/feed.rb', line 122

def media_thumbnail(markup, h)
  if h[:media_thumbnail_url]
    options = {}
    h.each do |k,v|
      if MediaThumbnailOptionalAttrs.include?(k)
        options[MediaThumbnailOptionalAttrs[k]] = v
      end
    end

    markup.media :thumbnail,
      { :url => h[:media_thumbnail_url] }.merge(options)
  end
end

.via(markup, h) ⇒ Object

Add via tags if present.



137
138
139
140
141
# File 'lib/tinyatom/feed.rb', line 137

def via(markup, h)
  if h[:via_type] and h[:via_href] and h[:via_title]
    link markup, 'via', h[:via_type], h[:via_href], h[:via_title]
  end
end