Skip to content

Commit 441bc00

Browse files
committed
Add ATOM feed
1 parent 55f5c6d commit 441bc00

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

app/controllers/jobs_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def index
99
respond_to do |format|
1010
format.html
1111
format.json
12+
format.atom
1213
end
1314
end
1415

app/views/jobs/index.atom.builder

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
xml.instruct!(:xml, :encoding => "UTF-8")
2+
3+
xml.feed("xmlns" => "http://www.w3.org/2005/Atom") do
4+
5+
xml.title 'code4lib jobs'
6+
# an author is required, so we'll just use the app name
7+
xml.author { xml.name 'code4lib jobs' }
8+
9+
xml.link "rel" => "self", "href" => jobs_url(page: @jobs.current_page)
10+
xml.id jobs_url(page: @jobs.current_page)
11+
12+
# Navigational and context links
13+
14+
xml.link( "rel" => "next",
15+
"href" => jobs_url(page: @jobs.next_page)
16+
) unless @jobs.last_page?
17+
18+
xml.link( "rel" => "previous",
19+
"href" => jobs_url(page: @jobs.prev_page)
20+
) unless @jobs.first_page?
21+
22+
xml.link( "rel" => "first",
23+
"href" => jobs_url(page: 1))
24+
25+
xml.link( "rel" => "last",
26+
"href" => jobs_url(page: @jobs.total_pages))
27+
28+
xml.updated @jobs.first.published_at.iso8601
29+
30+
@jobs.each do |job|
31+
xml.entry do
32+
xml.title job.title
33+
xml.updated job.published_at.iso8601
34+
xml.link job_url(job)
35+
xml.id job_url(job)
36+
37+
xml.author { xml.name(job.user&.email) }
38+
xml.content type: 'html' do |content_element|
39+
content_element.text! render_marked_up_description(job.description, format: job.description_markup)
40+
end
41+
end
42+
end
43+
end

app/views/jobs/index.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<% content_for(:head) do %>
2+
<%= auto_discovery_link_tag :atom, format: :atom %>
3+
<% end %>
4+
15
<p id="notice"><%= notice %></p>
26
<%= link_to 'New Job', new_job_path, class: 'btn btn-primary float-right' if can? :create, Job %>
37

0 commit comments

Comments
 (0)