Skip to content

Commit c183eb1

Browse files
committed
Merge pull request #1068 from projectblacklight/rss-atom
Render atom and rss feeds using the document partial rendering pipeline,...
2 parents f838d0a + e031627 commit c183eb1

File tree

5 files changed

+75
-63
lines changed

5 files changed

+75
-63
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
xml.entry do
2+
3+
4+
xml.title document.to_semantic_values[:title][0] || presenter(document).render_document_index_label(document_show_link_field(document))
5+
6+
# updated is required, for now we'll just set it to now, sorry
7+
xml.updated Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
8+
9+
xml.link "rel" => "alternate", "type" => "text/html", "href" => polymorphic_url(url_for_document(document))
10+
# add other doc-specific formats, atom only lets us have one per
11+
# content type, so the first one in the list wins.
12+
xml << render_link_rel_alternates(document, :unique => true)
13+
14+
xml.id polymorphic_url(url_for_document(document))
15+
16+
17+
if document.to_semantic_values[:author][0]
18+
xml.author { xml.name(document.to_semantic_values[:author][0]) }
19+
end
20+
21+
with_format("html") do
22+
xml.summary "type" => "html" do
23+
xml.text! render_document_partial(document,
24+
:index,
25+
:document_counter => document_counter)
26+
end
27+
end
28+
29+
#If they asked for a format, give it to them.
30+
if (params["content_format"] &&
31+
document.export_formats[params["content_format"].to_sym])
32+
33+
type = document.export_formats[params["content_format"].to_sym][:content_type]
34+
35+
xml.content :type => type do |content_element|
36+
data = document.export_as(params["content_format"])
37+
38+
# encode properly. See:
39+
# http://tools.ietf.org/html/rfc4287#section-4.1.3.3
40+
type = type.downcase
41+
if (type.downcase =~ /\+|\/xml$/)
42+
# xml, just put it right in
43+
content_element << data
44+
elsif (type.downcase =~ /text\//)
45+
# text, escape
46+
content_element.text! data
47+
else
48+
#something else, base64 encode it
49+
content_element << Base64.encode64(data)
50+
end
51+
end
52+
53+
end
54+
55+
56+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
xml.item do
2+
xml.title( document.to_semantic_values[:title][0] || presenter(document).render_document_index_label(document_show_link_field(document)) )
3+
xml.link(polymorphic_url(url_for_document(document)))
4+
xml.author( document.to_semantic_values[:author][0] ) if document.to_semantic_values[:author][0]
5+
end

app/views/catalog/index.atom.builder

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,63 +45,9 @@ xml.feed("xmlns" => "http://www.w3.org/2005/Atom",
4545
# updated is required, for now we'll just set it to now, sorry
4646
xml.updated Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
4747

48-
@document_list.each_with_index do |doc, document_counter|
49-
xml.entry do
50-
xml.title doc.to_semantic_values[:title][0] || doc.id
51-
52-
# updated is required, for now we'll just set it to now, sorry
53-
xml.updated Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
54-
55-
xml.link "rel" => "alternate", "type" => "text/html", "href" => polymorphic_url(doc)
56-
# add other doc-specific formats, atom only lets us have one per
57-
# content type, so the first one in the list wins.
58-
xml << render_link_rel_alternates(doc, :unique => true)
59-
60-
xml.id polymorphic_url(doc)
61-
62-
63-
if doc.to_semantic_values[:author][0]
64-
xml.author { xml.name(doc.to_semantic_values[:author][0]) }
65-
end
66-
67-
with_format("html") do
68-
xml.summary "type" => "html" do
69-
xml.text! render_document_partial(doc,
70-
:index,
71-
:document_counter => document_counter)
72-
end
73-
end
74-
75-
#If they asked for a format, give it to them.
76-
if (params["content_format"] &&
77-
doc.export_formats[params["content_format"].to_sym])
78-
79-
type = doc.export_formats[params["content_format"].to_sym][:content_type]
80-
81-
xml.content :type => type do |content_element|
82-
data = doc.export_as(params["content_format"])
83-
84-
# encode properly. See:
85-
# http://tools.ietf.org/html/rfc4287#section-4.1.3.3
86-
type = type.downcase
87-
if (type.downcase =~ /\+|\/xml$/)
88-
# xml, just put it right in
89-
content_element << data
90-
elsif (type.downcase =~ /text\//)
91-
# text, escape
92-
content_element.text! data
93-
else
94-
#something else, base64 encode it
95-
content_element << Base64.encode64(data)
96-
end
97-
end
98-
99-
end
100-
101-
102-
end
48+
@document_list.each_with_index do |document, document_counter|
49+
xml << Nokogiri::XML.fragment(render_document_partials(document, blacklight_config.view_config(:atom).partials, document_counter: document_counter))
10350
end
104-
10551
end
10652

10753

app/views/catalog/index.rss.builder

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ xml.rss(:version=>"2.0") {
77
xml.link(search_action_url(params))
88
xml.description(t('blacklight.search.title', :application_name => application_name))
99
xml.language('en-us')
10-
@document_list.each do |doc|
11-
xml.item do
12-
xml.title( doc.to_semantic_values[:title][0] || doc.id )
13-
xml.link(polymorphic_url(doc))
14-
xml.author( doc.to_semantic_values[:author][0] ) if doc.to_semantic_values[:author][0]
15-
end
10+
@document_list.each_with_index do |document, document_counter|
11+
xml << Nokogiri::XML.fragment(render_document_partials(document, blacklight_config.view_config(:rss).partials, document_counter: document_counter))
1612
end
1713

1814
}

lib/blacklight/configuration.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ def default_values
7878
),
7979
:navbar => OpenStructWithHashAccess.new(partials: { }),
8080
# Configurations for specific types of index views
81-
:view => NestedOpenStructWithHashAccess.new(ViewConfig, 'list'),
81+
:view => NestedOpenStructWithHashAccess.new(ViewConfig,
82+
'list',
83+
atom: {
84+
if: false, # by default, atom should not show up as an alternative view
85+
partials: [:document]
86+
},
87+
rss: {
88+
if: false, # by default, rss should not show up as an alternative view
89+
partials: [:document]
90+
}),
8291
# Maxiumum number of spelling suggestions to offer
8392
:spell_max => 5,
8493
# Maximum number of results to show per page

0 commit comments

Comments
 (0)