Skip to content

Commit

Permalink
Update XML sidebar rendering
Browse files Browse the repository at this point in the history
- 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 bd2a730
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
3 changes: 1 addition & 2 deletions app/models/xml_sidebar.rb
Expand Up @@ -3,8 +3,7 @@ class XmlSidebar < Sidebar
description 'RSS and Atom feeds' description 'RSS and Atom feeds'


setting :articles, true, input_type: :checkbox setting :articles, true, input_type: :checkbox
setting :comments, true, input_type: :checkbox setting :feedback, true, input_type: :checkbox
setting :trackbacks, false, input_type: :checkbox
setting :article_comments, true, input_type: :checkbox setting :article_comments, true, input_type: :checkbox
setting :tag_feeds, false, input_type: :checkbox setting :tag_feeds, false, input_type: :checkbox


Expand Down
26 changes: 11 additions & 15 deletions app/views/xml_sidebar/_content.html.erb
Expand Up @@ -3,32 +3,28 @@
<ul> <ul>
<% if sidebar.articles %> <% if sidebar.articles %>
<li> <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") %> <%= t(".articles") %>
</a> </a>
</li> </li>
<% end %> <% end %>
<% if sidebar.comments %> <% if sidebar.feedback %>
<li> <li>
<a href="<%= comments_url(:format=>sidebar.format_strip) %>" title="Comments feed"> <a href="<%= feedback_index_path(format: sidebar.format_strip) %>" title="Feedback feed">
<%= t(".comments") %> <%= t(".feedback") %>
</a> </a>
</li> </li>
<% end %> <% end %>
<% if sidebar.trackbacks %> <% if sidebar.tag_feeds and controller.controller_name == 'tags' and controller.action_name == 'show' %>
<li> <li>
<a href="<%= url_for controller: 'xml', action: 'feed', format: sidebar.format_strip, type: 'trackbacks' %>" title="Trackbacks feed"> <%= t('.tag') %>
<%= t(".trackbacks")%> <%= link_to(@tag.display_name, @tag.feed_url(sidebar.format_strip)) %>
</a>
</li> </li>
<% end %> <% end %>
<% if sidebar.tag_feeds and controller.controller_name == 'tags' and controller.action_name == 'show' %> <% if sidebar.article_comments and controller.controller_name == 'articles' and controller.action_name == 'redirect' %>
<% format = (sidebar.format_strip == 'rss') ? @auto_discovery_url_rss : @auto_discovery_url_atom %> <li>
<%= content_tag(:li, t(".tag", link: link_to(@grouping.display_name, format))) %> <%= link_to(@article.title, @article.feed_url(sidebar.format_strip)) %>
<% end %> </li>
<% 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)) %>
<% end %> <% end %>
</ul> </ul>
</div> </div>
3 changes: 1 addition & 2 deletions config/locales/sidebars.en.yml
Expand Up @@ -13,7 +13,6 @@ en:
xml_sidebar: xml_sidebar:
content: content:
articles: Articles articles: Articles
comments: Comments feedback: Feedback
syndicate: Syndicate syndicate: Syndicate
tag: Tag tag: Tag
trackbacks: Trackbacks
4 changes: 4 additions & 0 deletions publify_core/app/models/tag.rb
Expand Up @@ -57,6 +57,10 @@ def permalink
name name
end end


def feed_url(format)
"#{permalink_url}.#{format.gsub(/\d/, '')}"
end

def permalink_url(_anchor = nil, only_path = false) def permalink_url(_anchor = nil, only_path = false)
blog.url_for(controller: 'tags', action: 'show', id: permalink, only_path: only_path) blog.url_for(controller: 'tags', action: 'show', id: permalink, only_path: only_path)
end end
Expand Down
3 changes: 1 addition & 2 deletions publify_core/config/routes.rb
Expand Up @@ -6,8 +6,7 @@
get ':year', to: 'articles#index', year: /\d{4}/, as: 'articles_by_year', format: false 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 ':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: /rss|atom/}, as: 'articles_feed'
get 'articles.:format', to: 'articles#index', constraints: {format: 'atom'}, as: 'atom'


get 'sitemap.xml', to: 'xml#sitemap', format: 'googlesitemap' get 'sitemap.xml', to: 'xml#sitemap', format: 'googlesitemap'


Expand Down
3 changes: 1 addition & 2 deletions spec/factories.rb
Expand Up @@ -58,10 +58,9 @@
extended 'extended content for fun' extended 'extended content for fun'
guid guid
permalink 'a-big-article' permalink 'a-big-article'
published_at DateTime.new(2005, 1, 1, 2, 0, 0) published_at { Time.zone.now }
user user
allow_comments true allow_comments true
published true
state :published state :published
allow_pings true allow_pings true
association :text_filter, factory: :textile association :text_filter, factory: :textile
Expand Down
42 changes: 40 additions & 2 deletions spec/views/xml_sidebar/_content.html.erb_spec.rb
Expand Up @@ -3,7 +3,45 @@
RSpec.describe 'xml_sidebar/_content.html.erb', type: :view do RSpec.describe 'xml_sidebar/_content.html.erb', type: :view do
let(:sidebar) { XmlSidebar.new } let(:sidebar) { XmlSidebar.new }


it 'renders an XML sidebar' do context 'by default' do
render partial: sidebar.content_partial, locals: sidebar.to_locals_hash 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
end end

0 comments on commit bd2a730

Please sign in to comment.