A platform for community discussion. Free, open, simple.
FEATURE: Export topics to markdown (#15615)
Rafael dos Santos Silva3f91c8835b99
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex 02ced625a42..b3014a111fd 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -28,6 +28,8 @@ class PostsController < ApplicationController:user_posts_feed]+ MARKDOWN_TOPIC_PAGE_SIZE ||= 100+def markdown_idmarkdown Post.find(params[:id].to_i)end@@ -36,8 +38,23 @@ class PostsController < ApplicationControllerif params[:revision].present?post_revision = find_post_revision_from_topic_idrender plain: post_revision.modifications[:raw].last+ elsif params[:post_number].present?+ markdown Post.find_by(topic_id: params[:topic_id].to_i, post_number: params[:post_number].to_i)else- markdown Post.find_by(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i)+ opts = params.slice(:page)+ opts[:limit] = MARKDOWN_TOPIC_PAGE_SIZE+ topic_view = TopicView.new(params[:topic_id], current_user, opts)+ content = topic_view.posts.map do |p|+ <<~HEREDOC+ #{p.user.username} | #{p.updated_at} | ##{p.post_number}++ #{p.raw}++ -------------------------++ HEREDOC+ end+ render plain: content.joinendenddiff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 1091dfb5b9a..883eef44b4d 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -1888,6 +1888,16 @@ describe PostsController doexpect(response.status).to eq(200)expect(response.body).to eq("123456789")end++ it "can show whole topics" do+ topic = Fabricate(:topic)+ post = Fabricate(:post, topic: topic, post_number: 1, raw: "123456789")+ post_2 = Fabricate(:post, topic: topic, post_number: 2, raw: "abcdefghij")+ post.save+ get "/raw/#{topic.id}"+ expect(response.status).to eq(200)+ expect(response.body).to include("123456789", "abcdefghij")+ endenddescribe '#short_link' do