This repository has been archived by the owner on Dec 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
375 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CommentsController < ApplicationController | ||
load_and_authorize_resource :item | ||
load_and_authorize_resource :comment, :through => :item | ||
|
||
respond_to :js | ||
|
||
def create | ||
@comment.user = current_user | ||
respond_with(@item, @comment.save) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,8 @@ def avatar_url(user) | |
end | ||
end | ||
end | ||
|
||
def icon_tag(icon) | ||
content_tag :i, nil, :class => "icon #{icon}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CommentsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :item | ||
belongs_to :user | ||
|
||
validates_presence_of :item_id, :user_id, :markdown | ||
|
||
before_save :assign_html, :if => :markdown? | ||
|
||
private | ||
|
||
def assign_html | ||
self.html = RDiscount.new(self.markdown, :filter_styles, :filter_html, :autolink).to_html | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<article class="comment"> | ||
<header> | ||
<time datetime="<%= comment.created_at.to_s(:db) %>" pubdate="pubdate"><%= comment.created_at.strftime("%d.%m.%Y") %></time> | ||
<%= comment.user.name %> | ||
</header> | ||
<%=raw comment.html %> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div id="wmd-button-bar"></div> | ||
<div> | ||
<%= f.text_area :markdown, :placeholder => t("activerecord.attributes.comment.markdown"), :rows => 10, :autofocus => true %> | ||
</div> | ||
<%= javascript_include_tag("wmd.combined.min") %> | ||
<script type="text/javascript"> | ||
setup_wmd({ | ||
input: "comment_markdown" | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<section class="preview"> | ||
<%= render :partial => "comments/preview", :locals => { :comment => comment } %> | ||
</section> | ||
<section class="form"> | ||
<%= form_for [item, comment], :remote => true do |f| %> | ||
<%= render :partial => "comments/form", :locals => { :f => f } %> | ||
<div class="buttons"> | ||
<%= f.submit t(".create") %> | ||
</div> | ||
<% end %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="wmd-preview"> | ||
<header>Просмотр</header> | ||
<div id="wmd-preview"><%=raw comment.html %></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if @comment.errors.any? %> | ||
$('#item-<%= @item.id %>-new-comment').html('<%= escape_javascript render(:partial => "comments/new", :locals => { :item => @item, :comment => @comment }) %>'); | ||
<% else %> | ||
$('#item-<%= @item.id %>-new-comment').before('<%= escape_javascript render(@comment)%>'); | ||
$('#item-<%= @item.id %>-new-comment').html('<%= escape_javascript render(:partial => "comments/new", :locals => { :item => @item, :comment => @item.comments.new }) %>'); | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ru: | ||
comments: | ||
new: | ||
create: "Добавить" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def self.up | ||
create_table :comments do |t| | ||
t.belongs_to :item | ||
t.belongs_to :user | ||
t.text :markdown | ||
t.text :html | ||
t.timestamps | ||
end | ||
|
||
add_index :comments, :item_id | ||
add_index :comments, :user_id | ||
end | ||
|
||
def self.down | ||
drop_table :comments | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.