From cef9a74053728d57d0616e5b173749a7d5d854b2 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 30 Apr 2013 16:29:57 +1000 Subject: [PATCH] route for markdown /md/topic_id/post_number --- app/controllers/application_controller.rb | 2 ++ app/controllers/posts_controller.rb | 11 ++++++++++- config/routes.rb | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eea419126fb..e22227523b0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -67,6 +67,8 @@ class ApplicationController < ActionController::Base rescue_from Discourse::NotFound do if !request.format || request.format.html? # for now do a simple remap, we may look at cleaner ways of doing the render + # + # Sam: I am confused about this, we need a comment that explains why this is conditional raise ActiveRecord::RecordNotFound else render file: 'public/404', formats: [:html], layout: false, status: 404 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3bb93c09956..774a4dcd5b8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -7,7 +7,16 @@ class PostsController < ApplicationController before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link] skip_before_filter :store_incoming_links, only: [:short_link] - skip_before_filter :check_xhr, only: [:short_link] + skip_before_filter :check_xhr, only: [:markdown,:short_link] + + def markdown + post = Post.where(topic_id: params[:topic_id].to_i, post_number: (params[:post_number] || 1).to_i).first + if post && guardian.can_see?(post) + render text: post.raw, content_type: 'text/plain' + else + raise Discourse::NotFound + end + end def short_link post = Post.find(params[:post_id].to_i) diff --git a/config/routes.rb b/config/routes.rb index a770a87c45e..eabab717f49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -205,6 +205,8 @@ Discourse::Application.routes.draw do post 't/:topic_id/notifications' => 'topics#set_notifications' , constraints: {topic_id: /\d+/} + get 'md/:topic_id(/:post_number)' => 'posts#markdown' + resources :invites delete 'invites' => 'invites#destroy'