8
9
10
11
12
13
14
15
16
17
18
19
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
|
# File 'lib/feedbuilder/provider.rb', line 8
def build_feed(collection, url_builder, options = {}, &block)
feed_updated = nil
collection.each do |model|
if feed_updated.nil? || model.updated_at > feed_updated
feed_updated = model.updated_at
end
end
Atom::Feed.new do |feed|
feed.id = if options.include?(:feed_id)
options[:feed_id]
elsif options.include?(:feed_id_path)
feed_tag_uri(options[:feed_id_path])
elsif self.feed_id_path.present?
feed_tag_uri(self.feed_id_path)
else
self.feed_id
end
feed.title = options[:feed_title]
feed.updated = feed_updated
feed.links << Atom::Link.new(:href => url_builder.html_url, :rel => :via, :type => 'text/html')
feed.links << Atom::Link.new(:href => url_builder.self_url, :rel => :self, :type => 'application/atom+xml')
if collection.respond_to?(:total_pages) && collection.respond_to?(:current_page) &&
collection.respond_to?(:per_page)
if collection.total_pages > 1
feed.links << Atom::Link.new(:href => url_builder.first_url(collection.per_page), :rel => :first,
:type => 'application/atom+xml')
if collection.current_page > 1
feed.links << Atom::Link.new(:href => url_builder.prev_url(collection.current_page, collection.per_page),
:rel => :previous, :type => 'application/atom+xml')
end
if collection.current_page < collection.total_pages
feed.links << Atom::Link.new(:href => url_builder.next_url(collection.current_page, collection.per_page),
:rel => :next, :type => 'application/atom+xml')
end
feed.links << Atom::Link.new(:href => url_builder.last_url(collection.total_pages, collection.per_page),
:rel => :last, :type => 'application/atom+xml')
end
end
collection.each {|model| feed.entries << build_entry(model, &block)}
end
end
|