/comments.atom: add atom feed for comments.

This commit is contained in:
evazion
2017-05-11 23:52:35 -05:00
parent 78b08d8394
commit e68946e95d
7 changed files with 42 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ class CommentsController < ApplicationController
skip_before_filter :api_check
def index
if params[:group_by] == "comment"
if params[:group_by] == "comment" || request.format == Mime::ATOM
index_by_comment
elsif request.format == Mime::JS
index_for_post
@@ -92,6 +92,10 @@ private
@comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
respond_with(@comments) do |format|
format.html {render :action => "index_by_comment"}
format.atom do
@comments = @comments.includes(:post, :creator).load
render :action => "index"
end
format.xml do
render :xml => @comments.to_xml(:root => "comments")
end

View File

@@ -0,0 +1,24 @@
atom_feed do |feed|
title = "Comments"
title += " by #{params[:search][:creator_name]}" if params.dig(:search, :creator_name).present?
title += " on #{params[:search][:post_tags_match]}" if params.dig(:search, :post_tags_match).present?
feed.title(title)
feed.updated(@comments.first.try(:updated_at))
@comments.each do |comment|
feed.entry(comment, published: comment.created_at, updated: comment.updated_at) do |entry|
entry.title("@#{comment.creator_name} on post ##{comment.post_id} (#{comment.post.humanized_essential_tag_string})")
entry.content(<<-EOS.strip_heredoc, type: "html")
<img src="#{comment.post.complete_preview_file_url}"/>
#{format_text(comment.body)}
EOS
entry.author do |author|
author.name(comment.creator_name)
author.uri(user_url(comment.creator))
end
end
end
end

View File

@@ -29,3 +29,5 @@
<% content_for(:page_title) do %>
Comments - <%= Danbooru.config.app_name %>
<% end %>
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: params[:search]), title: "Comments")) %>

View File

@@ -37,3 +37,5 @@
<% content_for(:page_title) do %>
Comments - <%= Danbooru.config.app_name %>
<% end %>
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { do_not_bump_post: true }), title: "Comments")) %>

View File

@@ -73,6 +73,7 @@
<li><h1>Comments</h1></li>
<li><%= link_to("Help", wiki_pages_path(:title => "help:comments")) %></li>
<li><%= link_to("Listing", comments_path) %></li>
<li><%= link_to("RSS", comments_path(:atom)) %></li>
</ul>
<ul>
<li><h1>Forum</h1></li>

View File

@@ -15,3 +15,6 @@
<% content_for(:page_title) do %>
User - <%= @presenter.name %> - <%= Danbooru.config.app_name %>
<% end %>
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }), title: "Comments on #{@user.name}'s uploads")) %>
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { post_tags_match: "commenter:#{@user.name}" }), title: "Comments on posts commented on by #{@user.name}")) %>

View File

@@ -36,6 +36,11 @@ class CommentsControllerTest < ActionController::TestCase
get :index, {:group_by => "comment"}
assert_response :success
end
should "render for atom feeds" do
get :index, {:format => "atom"}
assert_response :success
end
end
context "search action" do