route for markdown /md/topic_id/post_number

This commit is contained in:
Sam 2013-04-30 16:29:57 +10:00
parent b7fc8ac33c
commit cef9a74053
3 changed files with 14 additions and 1 deletions

View File

@ -67,6 +67,8 @@ class ApplicationController < ActionController::Base
rescue_from Discourse::NotFound do rescue_from Discourse::NotFound do
if !request.format || request.format.html? if !request.format || request.format.html?
# for now do a simple remap, we may look at cleaner ways of doing the render # 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 raise ActiveRecord::RecordNotFound
else else
render file: 'public/404', formats: [:html], layout: false, status: 404 render file: 'public/404', formats: [:html], layout: false, status: 404

View File

@ -7,7 +7,16 @@ class PostsController < ApplicationController
before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link] before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link]
skip_before_filter :store_incoming_links, only: [: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 def short_link
post = Post.find(params[:post_id].to_i) post = Post.find(params[:post_id].to_i)

View File

@ -205,6 +205,8 @@ Discourse::Application.routes.draw do
post 't/:topic_id/notifications' => 'topics#set_notifications' , constraints: {topic_id: /\d+/} post 't/:topic_id/notifications' => 'topics#set_notifications' , constraints: {topic_id: /\d+/}
get 'md/:topic_id(/:post_number)' => 'posts#markdown'
resources :invites resources :invites
delete 'invites' => 'invites#destroy' delete 'invites' => 'invites#destroy'