Permalink
Browse files

Update XML sidebar rendering

- Link to all-in-one feedback feed
- Fix linking to article comments and tag feeds
  • Loading branch information...
mvz committed Jul 9, 2017
1 parent f66b66f commit bd2a73069effdbda0f0cb34add7f6da2962da51e
@@ -3,8 +3,7 @@ class XmlSidebar < Sidebar
description 'RSS and Atom feeds'
setting :articles, true, input_type: :checkbox
setting :comments, true, input_type: :checkbox
setting :trackbacks, false, input_type: :checkbox
setting :feedback, true, input_type: :checkbox
setting :article_comments, true, input_type: :checkbox
setting :tag_feeds, false, input_type: :checkbox
@@ -3,32 +3,28 @@
<ul>
<% if sidebar.articles %>
<li>
<a href="<%= url_for controller: 'articles', action: 'index', :format => sidebar.format_strip %>" title="Articles feed">
<a href="<%= url_for controller: 'articles', action: 'index', format: sidebar.format_strip %>" title="Articles feed">
<%= t(".articles") %>
</a>
</li>
<% end %>
<% if sidebar.comments %>
<% if sidebar.feedback %>
<li>
<a href="<%= comments_url(:format=>sidebar.format_strip) %>" title="Comments feed">
<%= t(".comments") %>
<a href="<%= feedback_index_path(format: sidebar.format_strip) %>" title="Feedback feed">
<%= t(".feedback") %>
</a>
</li>
<% end %>
<% if sidebar.trackbacks %>
<% if sidebar.tag_feeds and controller.controller_name == 'tags' and controller.action_name == 'show' %>
<li>
<a href="<%= url_for controller: 'xml', action: 'feed', format: sidebar.format_strip, type: 'trackbacks' %>" title="Trackbacks feed">
<%= t(".trackbacks")%>
</a>
<%= t('.tag') %>
<%= link_to(@tag.display_name, @tag.feed_url(sidebar.format_strip)) %>
</li>
<% end %>
<% if sidebar.tag_feeds and controller.controller_name == 'tags' and controller.action_name == 'show' %>
<% format = (sidebar.format_strip == 'rss') ? @auto_discovery_url_rss : @auto_discovery_url_atom %>
<%= content_tag(:li, t(".tag", link: link_to(@grouping.display_name, format))) %>
<% end %>
<% if sidebar.article_comments and controller.controller_name == 'redirect' %>
<% format = (sidebar.format_strip == 'rss') ? @auto_discovery_url_rss : @auto_discovery_url_atom %>
<%= content_tag(:li, link_to(@article.title, format)) %>
<% if sidebar.article_comments and controller.controller_name == 'articles' and controller.action_name == 'redirect' %>
<li>
<%= link_to(@article.title, @article.feed_url(sidebar.format_strip)) %>
</li>
<% end %>
</ul>
</div>
@@ -13,7 +13,6 @@ en:
xml_sidebar:
content:
articles: Articles
comments: Comments
feedback: Feedback
syndicate: Syndicate
tag: Tag
trackbacks: Trackbacks
@@ -57,6 +57,10 @@ def permalink
name
end
def feed_url(format)
"#{permalink_url}.#{format.gsub(/\d/, '')}"
end
def permalink_url(_anchor = nil, only_path = false)
blog.url_for(controller: 'tags', action: 'show', id: permalink, only_path: only_path)
end
@@ -6,8 +6,7 @@
get ':year', to: 'articles#index', year: /\d{4}/, as: 'articles_by_year', format: false
get ':year/page/:page', to: 'articles#index', year: /\d{4}/, as: 'articles_by_year_page', format: false
get 'articles.:format', to: 'articles#index', constraints: {format: 'rss'}, as: 'rss'
get 'articles.:format', to: 'articles#index', constraints: {format: 'atom'}, as: 'atom'
get 'articles.:format', to: 'articles#index', constraints: {format: /rss|atom/}, as: 'articles_feed'
get 'sitemap.xml', to: 'xml#sitemap', format: 'googlesitemap'
View
@@ -58,10 +58,9 @@
extended 'extended content for fun'
guid
permalink 'a-big-article'
published_at DateTime.new(2005, 1, 1, 2, 0, 0)
published_at { Time.zone.now }
user
allow_comments true
published true
state :published
allow_pings true
association :text_filter, factory: :textile
@@ -3,7 +3,45 @@
RSpec.describe 'xml_sidebar/_content.html.erb', type: :view do
let(:sidebar) { XmlSidebar.new }
it 'renders an XML sidebar' do
render partial: sidebar.content_partial, locals: sidebar.to_locals_hash
context 'by default' do
before do
render partial: sidebar.content_partial, locals: sidebar.to_locals_hash
end
it 'renders a link to the articles feed' do
expect(rendered).to have_css("a[href='#{articles_feed_path(format: 'atom')}']")
end
it 'renders a link to the feedback feed' do
expect(rendered).to have_css("a[href='#{feedback_index_path(format: 'atom')}']")
end
end
context 'on an article page' do
before do
allow(controller).to receive(:controller_name).and_return 'articles'
allow(controller).to receive(:action_name).and_return 'redirect'
@article = create :article
render partial: sidebar.content_partial, locals: sidebar.to_locals_hash
end
it 'renders a link to the article comments feed' do
expect(rendered).to have_css("a[href='#{@article.feed_url('atom')}']")
end
end
context 'on a tags page' do
before do
sidebar.tag_feeds = true
allow(controller).to receive(:controller_name).and_return 'tags'
allow(controller).to receive(:action_name).and_return 'show'
@tag = create :tag
@auto_discovery_url_atom = 'foofoo'
render partial: sidebar.content_partial, locals: sidebar.to_locals_hash
end
it 'renders a link to the tag feed' do
expect(rendered).to have_css("a[href='#{@tag.feed_url('atom')}']")
end
end
end

0 comments on commit bd2a730

Please sign in to comment.