diff --git a/Gemfile b/Gemfile index 320b086..bbc3a9e 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'github-markdown' gem 'hirb' #pretty console output gem 'rb-readline', '~> 0.4.2' gem 'rest-client' +gem 'epic-editor-rails' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 91ddf99..2b4bc11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,8 @@ GEM execjs coffee-script-source (1.6.2) debug_inspector (0.0.2) + epic-editor-rails (0.2.3) + railties (>= 3.2, < 5.0) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -140,6 +142,7 @@ DEPENDENCIES better_errors binding_of_caller coffee-rails (~> 3.2.1) + epic-editor-rails github-markdown hirb jquery-rails diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index b7bbd20..666fd58 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -1,24 +1,45 @@ $(function(){ - $('.flash').click(function(){ - $('.flash').animate({ - opacity: 0 - }, 'fast', function(){ - $(this).animate({ - height: 0 - }, 'slow', function(){ - $(this).hide(); - }) - }); + $('.flash').click(function(){ + $('.flash').animate({ + opacity: 0 + }, 'fast', function(){ + $(this).animate({ + height: 0 + }, 'slow', function(){ + $(this).hide(); + }) }); - setTimeout(function(){ - $('.flash').animate({ - opacity: 0 - }, 3000, function(){ - $(this).animate({ - height: 0 - }, 'slow', function(){ - $(this).hide(); - }) - }); - }, 4000); -}) \ No newline at end of file + }); + setTimeout(function(){ + $('.flash').animate({ + opacity: 0 + }, 3000, function(){ + $(this).animate({ + height: 0 + }, 'slow', function(){ + $(this).hide(); + }) + }); + }, 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) {} +}); \ No newline at end of file diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 50cd919..2c48026 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,4 +11,5 @@ // GO AFTER THE REQUIRES BELOW. //= require jquery //= require jquery_ujs +//= require epiceditor //= require app diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index e93ffaf..62f8d8f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -3,4 +3,7 @@ *= require style.css *= require screen.css *= require mobi.css - */ \ No newline at end of file + */ + @import 'base/epiceditor'; + @import 'preview/github'; + @import 'editor/epic-light'; \ No newline at end of file diff --git a/app/assets/stylesheets/screen.css.scss b/app/assets/stylesheets/screen.css.scss index 3873a8a..6d8a44e 100644 --- a/app/assets/stylesheets/screen.css.scss +++ b/app/assets/stylesheets/screen.css.scss @@ -145,9 +145,9 @@ and (min-width: 0px) //TODO display: block; } - .post { + .post, .thread { margin-bottom: 50px; - .post-title { + .post-title, .thread-title { margin-bottom: 10px; word-wrap: break-word; h1 { @@ -169,7 +169,7 @@ and (min-width: 0px) //TODO font-weight: bold !important; text-shadow: none !important; } - .post-info { + .post-info, .thread-info { border-bottom: 2px dashed #999; color: #888; width: 100%; @@ -179,11 +179,11 @@ and (min-width: 0px) //TODO color: #d55; } } - .post-edit { + .post-edit, .thread-edit { float: right; } } - .post-content { + .post-content, .thread-content { margin-top: 10px; clear: both; word-wrap: break-word; @@ -445,6 +445,9 @@ and (min-width: 0px) //TODO background: #EE8383; } } + &.left { + float: left; + } &.right { float: right; } @@ -495,14 +498,6 @@ and (min-width: 0px) //TODO transition: opacity 0.3s, margin 0.3s; } - #edit_create_post, #edit_create_comment { - float: left; - } - - #delete_post, #delete_comment { - float: right; - } - #blogpost_text { width: 100%; } @@ -514,7 +509,7 @@ and (min-width: 0px) //TODO } #forum_groups { - .group { + .item_group { margin: 10px 0; &:hover .editlink { opacity: 1; @@ -526,15 +521,25 @@ and (min-width: 0px) //TODO padding: 0.5em; border-bottom: 1px solid #ccc; } - .forums { + .items { border: 1px solid #ddd; border-top: none; border-bottom: none; - .forum { + .item { display: block; font-weight: bold; padding: 0.5em; border-bottom: 1px solid #ddd; + &.locked:after { + color: #000; + font-weight: normal; + content: " (L)"; + } + &.sticky:before { + color: #000; + font-weight: normal; + content: "(S) "; + } } } } diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 56b15e4..9474ef8 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -45,7 +45,7 @@ class BlogpostsController < ApplicationController def update @post = Blogpost.find(params[:id]) - if mod? + if mod? || @comment.author.is?(current_user) @post.user_editor = current_user if @post.update_attributes(params[:blogpost] ? params[:blogpost].slice(:title, :content, :user_editor) : {}) redirect_to @post, notice: 'Post has been updated.' diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 5c387a1..86c6377 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -14,7 +14,7 @@ class ForumsController < ApplicationController def show @forum = Forum.find(params[:id]) 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 redirect_to forums_path end diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index d76df10..d55accf 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -6,7 +6,26 @@ class ForumthreadsController < ApplicationController def show @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 def new diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index 4753fd1..7a5e9b1 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -11,4 +11,16 @@ class Forumthread < ActiveRecord::Base def to_s title end + + def author + @author ||= if self.user_author.present? + user_author + else + User.first + end + end + + def editor + @editor ||= user_editor + end end \ No newline at end of file diff --git a/app/views/blogposts/edit.html.erb b/app/views/blogposts/edit.html.erb index 3b85d52..3bc349c 100644 --- a/app/views/blogposts/edit.html.erb +++ b/app/views/blogposts/edit.html.erb @@ -2,9 +2,8 @@
Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!
<%= simple_form_for @post do |f|%> <%= f.input :title, :label => false %> - <%= f.input :content, :label => false, input_html: {class: "full-width vertical"} %> - <%= f.submit "Update Post", :id => "edit_create_post", class: "btn blue" %> + <%= f.hidden_field :content, id: "epic-textarea", :label => false, input_html: {class: "full-width vertical"} %> + + <%= f.submit "Update Post", class: "btn blue left" %> <% end %> -Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!
<%= simple_form_for @post do |f|%> <%= f.input :title, placeholder: "Title" %> - <%= f.input :content, placeholder: "Text", input_html: {class: "full-width vertical"} %> - <%= f.submit "Create Post", id: "edit_create_post", class: "btn blue" %> + <%= f.hidden_field :content, id: "epic-textarea", placeholder: "Text", input_html: {class: "full-width vertical"} %> + + <%= f.submit "Create Post", class: "btn blue left" %> <% end %> diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb index 4a0aac9..a29b07c 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -1,9 +1,7 @@<%= link_to "New thread", new_forum_forumthread_path(@forum), class: "btn blue" %>
Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!
+<%= 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"} %> + + <%= 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" %> \ No newline at end of file diff --git a/app/views/forumthreads/new.html.erb b/app/views/forumthreads/new.html.erb index c8a2393..6d1f221 100644 --- a/app/views/forumthreads/new.html.erb +++ b/app/views/forumthreads/new.html.erb @@ -1,17 +1,17 @@ <%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= link_to @forum, @forum %> → New thread