features, bug fixes

This commit is contained in:
jomo
2014-02-03 01:47:49 +01:00
parent 0d06bc19fc
commit 0604bbce63
18 changed files with 156 additions and 71 deletions

View File

@@ -12,6 +12,7 @@ gem 'github-markdown'
gem 'hirb' #pretty console output gem 'hirb' #pretty console output
gem 'rb-readline', '~> 0.4.2' gem 'rb-readline', '~> 0.4.2'
gem 'rest-client' gem 'rest-client'
gem 'epic-editor-rails'
# Gems used only for assets and not required # Gems used only for assets and not required
# in production environments by default. # in production environments by default.

View File

@@ -46,6 +46,8 @@ GEM
execjs execjs
coffee-script-source (1.6.2) coffee-script-source (1.6.2)
debug_inspector (0.0.2) debug_inspector (0.0.2)
epic-editor-rails (0.2.3)
railties (>= 3.2, < 5.0)
erubis (2.7.0) erubis (2.7.0)
execjs (1.4.0) execjs (1.4.0)
multi_json (~> 1.0) multi_json (~> 1.0)
@@ -140,6 +142,7 @@ DEPENDENCIES
better_errors better_errors
binding_of_caller binding_of_caller
coffee-rails (~> 3.2.1) coffee-rails (~> 3.2.1)
epic-editor-rails
github-markdown github-markdown
hirb hirb
jquery-rails jquery-rails

View File

@@ -21,4 +21,25 @@ $(function(){
}) })
}); });
}, 4000); }, 4000);
})
var editor = new EpicEditor({
container: 'epic',
textarea: 'epic-textarea',
basePath: '/assets',
theme: {
base: '/base/epiceditor.css',
preview: '/preview/github.css',
editor: '/editor/epic-light.css'
},
button: {
bar: true
},
autogrow: {
minHeight: 500
}
});
try {
editor.load();
} catch (e) {}
});

View File

@@ -11,4 +11,5 @@
// GO AFTER THE REQUIRES BELOW. // GO AFTER THE REQUIRES BELOW.
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require epiceditor
//= require app //= require app

View File

@@ -4,3 +4,6 @@
*= require screen.css *= require screen.css
*= require mobi.css *= require mobi.css
*/ */
@import 'base/epiceditor';
@import 'preview/github';
@import 'editor/epic-light';

View File

@@ -145,9 +145,9 @@ and (min-width: 0px) //TODO
display: block; display: block;
} }
.post { .post, .thread {
margin-bottom: 50px; margin-bottom: 50px;
.post-title { .post-title, .thread-title {
margin-bottom: 10px; margin-bottom: 10px;
word-wrap: break-word; word-wrap: break-word;
h1 { h1 {
@@ -169,7 +169,7 @@ and (min-width: 0px) //TODO
font-weight: bold !important; font-weight: bold !important;
text-shadow: none !important; text-shadow: none !important;
} }
.post-info { .post-info, .thread-info {
border-bottom: 2px dashed #999; border-bottom: 2px dashed #999;
color: #888; color: #888;
width: 100%; width: 100%;
@@ -179,11 +179,11 @@ and (min-width: 0px) //TODO
color: #d55; color: #d55;
} }
} }
.post-edit { .post-edit, .thread-edit {
float: right; float: right;
} }
} }
.post-content { .post-content, .thread-content {
margin-top: 10px; margin-top: 10px;
clear: both; clear: both;
word-wrap: break-word; word-wrap: break-word;
@@ -445,6 +445,9 @@ and (min-width: 0px) //TODO
background: #EE8383; background: #EE8383;
} }
} }
&.left {
float: left;
}
&.right { &.right {
float: right; float: right;
} }
@@ -495,14 +498,6 @@ and (min-width: 0px) //TODO
transition: opacity 0.3s, margin 0.3s; transition: opacity 0.3s, margin 0.3s;
} }
#edit_create_post, #edit_create_comment {
float: left;
}
#delete_post, #delete_comment {
float: right;
}
#blogpost_text { #blogpost_text {
width: 100%; width: 100%;
} }
@@ -514,7 +509,7 @@ and (min-width: 0px) //TODO
} }
#forum_groups { #forum_groups {
.group { .item_group {
margin: 10px 0; margin: 10px 0;
&:hover .editlink { &:hover .editlink {
opacity: 1; opacity: 1;
@@ -526,15 +521,25 @@ and (min-width: 0px) //TODO
padding: 0.5em; padding: 0.5em;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
} }
.forums { .items {
border: 1px solid #ddd; border: 1px solid #ddd;
border-top: none; border-top: none;
border-bottom: none; border-bottom: none;
.forum { .item {
display: block; display: block;
font-weight: bold; font-weight: bold;
padding: 0.5em; padding: 0.5em;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
&.locked:after {
color: #000;
font-weight: normal;
content: " (L)";
}
&.sticky:before {
color: #000;
font-weight: normal;
content: "(S) ";
}
} }
} }
} }

View File

@@ -45,7 +45,7 @@ class BlogpostsController < ApplicationController
def update def update
@post = Blogpost.find(params[:id]) @post = Blogpost.find(params[:id])
if mod? if mod? || @comment.author.is?(current_user)
@post.user_editor = current_user @post.user_editor = current_user
if @post.update_attributes(params[:blogpost] ? params[:blogpost].slice(:title, :content, :user_editor) : {}) if @post.update_attributes(params[:blogpost] ? params[:blogpost].slice(:title, :content, :user_editor) : {})
redirect_to @post, notice: 'Post has been updated.' redirect_to @post, notice: 'Post has been updated.'

View File

@@ -14,7 +14,7 @@ class ForumsController < ApplicationController
def show def show
@forum = Forum.find(params[:id]) @forum = Forum.find(params[:id])
if @forum.role_read.nil? || current_user && @forum.role_read <= current_user.role if @forum.role_read.nil? || current_user && @forum.role_read <= current_user.role
@threads = @forum.forumthreads.reverse @threads = @forum.forumthreads.order("sticky desc, updated_at desc")
else else
redirect_to forums_path redirect_to forums_path
end end

View File

@@ -6,7 +6,26 @@ class ForumthreadsController < ApplicationController
def show def show
@thread = Forumthread.find(params[:id]) @thread = Forumthread.find(params[:id])
render text: @thread.content end
def update
@thread = Forumthread.find(params[:id])
if mod? || @thread.author.is?(current_user)
@thread.user_editor = current_user
if @thread.update_attributes(params[:forumthread] ? params[:forumthread].slice(:title, :content, :user_editor) : {})
redirect_to [@thread.forum, @thread], notice: 'Post has been updated.'
else
flash[:alert] = "There was a problem while updating the post"
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this thread!"
redirect_to [@thread.forum, @thread]
end
end
def edit
@thread = Forumthread.find(params[:id])
end end
def new def new

View File

@@ -11,4 +11,16 @@ class Forumthread < ActiveRecord::Base
def to_s def to_s
title title
end end
def author
@author ||= if self.user_author.present?
user_author
else
User.first
end
end
def editor
@editor ||= user_editor
end
end end

View File

@@ -2,9 +2,8 @@
<p id="markdown-note">Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!</p> <p id="markdown-note">Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!</p>
<%= simple_form_for @post do |f|%> <%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %> <%= f.input :title, :label => false %>
<%= f.input :content, :label => false, input_html: {class: "full-width vertical"} %> <%= f.hidden_field :content, id: "epic-textarea", :label => false, input_html: {class: "full-width vertical"} %>
<%= f.submit "Update Post", :id => "edit_create_post", class: "btn blue" %> <div id="epic"></div>
<%= f.submit "Update Post", class: "btn blue left" %>
<% end %> <% end %>
<div id="delete_post"> <%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post & comments forever?", class: "btn red right" %>
<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post & comments forever?", class: "btn red right" %>
</div>

View File

@@ -2,6 +2,7 @@
<p id="markdown-note">Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!</p> <p id="markdown-note">Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!</p>
<%= simple_form_for @post do |f|%> <%= simple_form_for @post do |f|%>
<%= f.input :title, placeholder: "Title" %> <%= f.input :title, placeholder: "Title" %>
<%= f.input :content, placeholder: "Text", input_html: {class: "full-width vertical"} %> <%= f.hidden_field :content, id: "epic-textarea", placeholder: "Text", input_html: {class: "full-width vertical"} %>
<%= f.submit "Create Post", id: "edit_create_post", class: "btn blue" %> <div id="epic"></div>
<%= f.submit "Create Post", class: "btn blue left" %>
<% end %> <% end %>

View File

@@ -1,9 +1,7 @@
<h1>Edit comment</h1> <h1>Edit comment</h1>
<%= simple_form_for [@comment.blogpost, @comment] do |f| %> <%= simple_form_for [@comment.blogpost, @comment] do |f| %>
<%= f.input :content, :label => false, :as => "text", :placeholder => "Comment" %> <%= f.input :content, label: false, as: "text", placeholder: "Comment" %>
<%= f.submit "Update Comment", :id => "edit_create_comment", class: "btn blue" %> <%= f.submit "Update Comment", class: "btn blue left" %>
<% end %> <% end %>
<div id="delete_comment"> <%= button_to "Delete comment", [@comment.blogpost, @comment] , method: "delete", confirm: "Delete comment forever?", class: "btn red right" %>
<%= button_to "Delete comment", [@comment.blogpost, @comment] , :method => "delete", :confirm => "Delete comment forever?", class: "btn red right" %>
</div>

View File

@@ -1,14 +1,14 @@
<div id="forum_groups"> <div id="forum_groups">
<% @groups.each do |group| %> <% @groups.each do |group| %>
<div class="group" id="forums-<%= group.id %>"> <div class="item_group" id="forums-<%= group.id %>">
<div class="header"> <div class="header">
<%= group.name %> <%= group.name %>
<%= link_to "edit", edit_forumgroup_path(group), class: "editlink" if admin? %> <%= link_to "edit", edit_forumgroup_path(group), class: "editlink" if admin? %>
</div> </div>
<div class="forums"> <div class="items">
<% group.forums.each do |f| %> <% group.forums.each do |f| %>
<%= link_to f.name, f, class: "forum" %> <%= link_to f.name, f, class: "item" %>
<% end %> <% end %>
</div> </div>

View File

@@ -3,15 +3,12 @@
<p><%= link_to "New thread", new_forum_forumthread_path(@forum), class: "btn blue" %></p> <p><%= link_to "New thread", new_forum_forumthread_path(@forum), class: "btn blue" %></p>
<div id="forum_groups"> <div id="forum_groups">
<div id="forum-<%= @forum.id %>" class="group"> <div id="forum-<%= @forum.id %>" class="item_group">
<div class="header"> <div class="header">
<%= @forum.name %> <%= link_to "edit", edit_forum_path(@forum), class: "editlink" %> <%= @forum.name %> <%= link_to "edit", edit_forum_path(@forum), class: "editlink" %>
</div> </div>
<div class="forums"> <div class="items">
<% @threads.select{ |t| t.sticky }.each do |thread| %> <% @threads.each do |thread| %>
<%= link_to thread.title, forum_forumthread_path(@forum, thread), class: "forum sticky" %> <%= link_to thread.title, forum_forumthread_path(@forum, thread), class: "item#{" locked" if thread.locked}#{" sticky" if thread.sticky}" %>
<% end %>
<% @threads.reject{ |t| t.sticky }.each do |thread| %>
<%= link_to thread.title, forum_forumthread_path(@forum, thread), class: "forum" %>
<% end %> <% end %>
</div> </div>

View File

@@ -0,0 +1,9 @@
<h1>Edit thread</h1>
<p id="markdown-note">Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!</p>
<%= simple_form_for [@thread.forum, @thread] do |f|%>
<%= f.input :title, label: false %>
<%= f.hidden_field :content, id: "epic-textarea", label: false, input_html: {class: "full-width vertical"} %>
<div id="epic"></div>
<%= f.submit "Update thread", class: "btn blue left" %>
<% end %>
<%= button_to "Delete thread", [@thread.forum, @thread], :method => "delete", :confirm => "Delete thread & comments forever?", class: "btn red right" %>

View File

@@ -1,17 +1,17 @@
<%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= link_to @forum, @forum %> → New thread <%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= link_to @forum, @forum %> → New thread
<h1>New thread</h1> <h1>New thread</h1>
<%= simple_form_for [@forum, @thread] do |f|%> <%= simple_form_for [@forum, @thread] do |f|%>
<% if mod? %>
<%= f.label :sticky %> <%= f.input :sticky %>
<%= f.label :locked %> <%= f.input :locked %>
<% end %>
<div id="form_labels"> <div id="form_labels">
<%= f.label :title %> <%= f.label :title %>
<%= f.label :content, "Text" %>
</div> </div>
<div id="form_inputs"> <div id="form_inputs">
<%= f.input :title, placeholder: "Title" %> <%= f.input :title, placeholder: "Title" %>
<%= f.input :content, placeholder: "Text" %>
</div> </div>
<% if mod? %> <%= f.hidden_field :content, id: "epic-textarea", placeholder: "Text" %>
<%= f.input :sticky %> <%= f.label :sticky %> <div id="epic"></div>
<%= f.input :locked %> <%= f.label :locked %> <%= f.submit "Create thread", class: "btn blue" %><br>
<% end %>
<%= f.submit "Create forum", class: "btn blue" %><br>
<% end %> <% end %>

View File

@@ -0,0 +1,16 @@
<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%= link_to @thread %>
<div class="post">
<div class="thread-title">
<h1><%= @thread.title %></h1>
</div>
<div class="thread-info"><%= link_user @thread.author %> on <%= @thread.created_at.strftime("%e. %b %Y") %>
<% if mod? %>
<%= link_to "edit", edit_forum_forumthread_path(@thread.forum, @thread), class: "thread-edit" %>
<% end %>
</div>
<div class="thread-content">
<%= Sanitize.clean(GitHub::Markdown.render_gfm(@thread.content), Sanitize::Config::RELAXED).html_safe %>
</div>
</div>
<hr>
(replies go here)