Merge pull request #3043 from evazion/feat-atom-feeds
Fix #3036: Add Additional ATOM Feeds (forum_posts, comments)
This commit is contained in:
@@ -4,7 +4,7 @@ class CommentsController < ApplicationController
|
|||||||
skip_before_filter :api_check
|
skip_before_filter :api_check
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:group_by] == "comment"
|
if params[:group_by] == "comment" || request.format == Mime::ATOM
|
||||||
index_by_comment
|
index_by_comment
|
||||||
elsif request.format == Mime::JS
|
elsif request.format == Mime::JS
|
||||||
index_for_post
|
index_for_post
|
||||||
@@ -92,6 +92,10 @@ private
|
|||||||
@comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
@comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||||
respond_with(@comments) do |format|
|
respond_with(@comments) do |format|
|
||||||
format.html {render :action => "index_by_comment"}
|
format.html {render :action => "index_by_comment"}
|
||||||
|
format.atom do
|
||||||
|
@comments = @comments.includes(:post, :creator).load
|
||||||
|
render :action => "index"
|
||||||
|
end
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @comments.to_xml(:root => "comments")
|
render :xml => @comments.to_xml(:root => "comments")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,9 +20,15 @@ class ForumTopicsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@query = ForumTopic.active.search(params[:search])
|
@query = ForumTopic.active.search(params[:search])
|
||||||
@forum_topics = @query.includes([:creator, :updater]).order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search])
|
@forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search])
|
||||||
|
|
||||||
respond_with(@forum_topics) do |format|
|
respond_with(@forum_topics) do |format|
|
||||||
|
format.html do
|
||||||
|
@forum_topics = @forum_topics.includes(:creator, :updater).load
|
||||||
|
end
|
||||||
|
format.atom do
|
||||||
|
@forum_topics = @forum_topics.includes(:creator, :original_post).load
|
||||||
|
end
|
||||||
format.json do
|
format.json do
|
||||||
render :json => @forum_topics.to_json
|
render :json => @forum_topics.to_json
|
||||||
end
|
end
|
||||||
@@ -37,8 +43,11 @@ class ForumTopicsController < ApplicationController
|
|||||||
@forum_topic.mark_as_read!(CurrentUser.user)
|
@forum_topic.mark_as_read!(CurrentUser.user)
|
||||||
end
|
end
|
||||||
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
|
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
|
||||||
@forum_posts.each # hack to force rails to eager load
|
respond_with(@forum_topic) do |format|
|
||||||
respond_with(@forum_topic)
|
format.atom do
|
||||||
|
@forum_posts = @forum_posts.includes(:creator).load
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
24
app/views/comments/index.atom.builder
Normal file
24
app/views/comments/index.atom.builder
Normal 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
|
||||||
@@ -29,3 +29,5 @@
|
|||||||
<% content_for(:page_title) do %>
|
<% content_for(:page_title) do %>
|
||||||
Comments - <%= Danbooru.config.app_name %>
|
Comments - <%= Danbooru.config.app_name %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: params[:search]), title: "Comments")) %>
|
||||||
|
|||||||
@@ -37,3 +37,5 @@
|
|||||||
<% content_for(:page_title) do %>
|
<% content_for(:page_title) do %>
|
||||||
Comments - <%= Danbooru.config.app_name %>
|
Comments - <%= Danbooru.config.app_name %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { do_not_bump_post: true }), title: "Comments")) %>
|
||||||
|
|||||||
16
app/views/forum_topics/index.atom.builder
Normal file
16
app/views/forum_topics/index.atom.builder
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
atom_feed do |feed|
|
||||||
|
feed.title("Forum Topics")
|
||||||
|
feed.updated(@forum_topics.first.try(:updated_at))
|
||||||
|
|
||||||
|
@forum_topics.each do |topic|
|
||||||
|
feed.entry(topic, published: topic.created_at, updated: topic.updated_at) do |entry|
|
||||||
|
entry.title("[#{topic.category_name}] #{topic.title}")
|
||||||
|
entry.content(format_text(topic.original_post.body), type: "html")
|
||||||
|
|
||||||
|
entry.author do |author|
|
||||||
|
author.name(topic.creator.name)
|
||||||
|
author.uri(user_url(topic.creator_id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -22,3 +22,5 @@
|
|||||||
<% content_for(:page_title) do %>
|
<% content_for(:page_title) do %>
|
||||||
Forum - <%= Danbooru.config.app_name %>
|
Forum - <%= Danbooru.config.app_name %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(:atom), title: "Forum Topics")) %>
|
||||||
|
|||||||
16
app/views/forum_topics/show.atom.builder
Normal file
16
app/views/forum_topics/show.atom.builder
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
atom_feed do |feed|
|
||||||
|
feed.title(@forum_topic.title)
|
||||||
|
feed.updated(@forum_topic.try(:updated_at))
|
||||||
|
|
||||||
|
@forum_posts.each do |post|
|
||||||
|
feed.entry(post, published: post.created_at, updated: post.updated_at) do |entry|
|
||||||
|
entry.title("@#{post.creator.name}: #{strip_dtext(post.body).truncate(50, separator: /[[:space:]]/)}")
|
||||||
|
entry.content(format_text(post.body), type: "html")
|
||||||
|
|
||||||
|
entry.author do |author|
|
||||||
|
author.name(post.creator.name)
|
||||||
|
author.uri(user_url(post.creator))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -57,3 +57,5 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(@forum_topic, :atom), title: @forum_topic.title)) %>
|
||||||
|
|||||||
@@ -73,11 +73,13 @@
|
|||||||
<li><h1>Comments</h1></li>
|
<li><h1>Comments</h1></li>
|
||||||
<li><%= link_to("Help", wiki_pages_path(:title => "help:comments")) %></li>
|
<li><%= link_to("Help", wiki_pages_path(:title => "help:comments")) %></li>
|
||||||
<li><%= link_to("Listing", comments_path) %></li>
|
<li><%= link_to("Listing", comments_path) %></li>
|
||||||
|
<li><%= link_to("RSS", comments_path(:atom)) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><h1>Forum</h1></li>
|
<li><h1>Forum</h1></li>
|
||||||
<li><%= link_to("Help", wiki_pages_path(:title => "help:forum")) %></li>
|
<li><%= link_to("Help", wiki_pages_path(:title => "help:forum")) %></li>
|
||||||
<li><%= link_to("Listing", forum_topics_path) %></li>
|
<li><%= link_to("Listing", forum_topics_path) %></li>
|
||||||
|
<li><%= link_to("RSS", forum_topics_path(:atom)) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><h1>Wiki</h1></li>
|
<li><h1>Wiki</h1></li>
|
||||||
|
|||||||
@@ -15,3 +15,6 @@
|
|||||||
<% content_for(:page_title) do %>
|
<% content_for(:page_title) do %>
|
||||||
User - <%= @presenter.name %> - <%= Danbooru.config.app_name %>
|
User - <%= @presenter.name %> - <%= Danbooru.config.app_name %>
|
||||||
<% end %>
|
<% 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}")) %>
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ class CommentsControllerTest < ActionController::TestCase
|
|||||||
get :index, {:group_by => "comment"}
|
get :index, {:group_by => "comment"}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render for atom feeds" do
|
||||||
|
get :index, {:format => "atom"}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "search action" do
|
context "search action" do
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ class ForumTopicsControllerTest < ActionController::TestCase
|
|||||||
get :show, {:id => @forum_topic.id}
|
get :show, {:id => @forum_topic.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render for atom feed" do
|
||||||
|
get :show, {:id => @forum_topic.id, :format => :atom}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "index action" do
|
context "index action" do
|
||||||
@@ -64,6 +69,11 @@ class ForumTopicsControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render for atom feed" do
|
||||||
|
get :index, {:format => :atom}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
context "with search conditions" do
|
context "with search conditions" do
|
||||||
should "list all matching forum topics" do
|
should "list all matching forum topics" do
|
||||||
get :index, {:search => {:title_matches => "forum"}}
|
get :index, {:search => {:title_matches => "forum"}}
|
||||||
|
|||||||
Reference in New Issue
Block a user