Markdown in comments

openid
Marcin Kulik 12 years ago
parent 06fcbf65c4
commit 936dac6baa

@ -1,5 +1,5 @@
<div class="left">
<a href="{{profile_path}}"><img src="{{user.avatar_url}}" alt="{{user.nickanme}}" class="avatar" /></a>
<a href="{{profile_path}}"><img src="{{user.avatar_url}}" alt="{{user.nickname}}" class="avatar" /></a>
</div>
<div class="right">
@ -10,7 +10,7 @@
| <a href="#" class="remove">remove</a>
{{/if}}
</div>
<div class="body">{{body}}</div>
<div class="body">{{{processed_body}}}</div>
</div>
<div class="clear"></div>

@ -5,7 +5,7 @@ class Api::CommentsController < ApplicationController
before_filter :load_asciicast, :only => [:index, :create]
def index
respond_with @asciicast.comments
respond_with CommentDecorator.decorate(@asciicast.comments)
end
def create
@ -15,7 +15,8 @@ class Api::CommentsController < ApplicationController
@comment.save
respond_with @comment, :location => api_comment_url(@comment)
comment = CommentDecorator.new(@comment)
respond_with comment, :location => api_comment_url(@comment)
end
def destroy

@ -25,4 +25,12 @@ class ApplicationDecorator < Draper::Base
# def updated_at
# formatted_timestamp(model.updated_at)
# end
end
def markdown(text)
MKD_RENDERER.render(text)
end
def as_json(*args)
model.as_json(*args)
end
end

@ -0,0 +1,10 @@
class CommentDecorator < ApplicationDecorator
decorates :comment
def as_json(*args)
data = model.as_json(*args)
data['processed_body'] = markdown(data['body'])
data
end
end

@ -0,0 +1,5 @@
MKD_RENDERER = Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(:filter_html => true),
:no_intra_emphasis => true,
:autolink => true
)

@ -0,0 +1,5 @@
require 'spec_helper'
describe CommentDecorator do
before { ApplicationController.new.set_current_view_context }
end
Loading…
Cancel
Save