my_forum 0.0.1.beta21 → 0.0.1.beta22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c11068cd89ded12b374df93e26bbf158a42e0f84
4
- data.tar.gz: 1378f0a856061dbf5a547666578eaa31825d6ca0
3
+ metadata.gz: 6687212d40454b3bd545b5c820d5376fda03eb06
4
+ data.tar.gz: 296495aa0ecbac42795cc0160fc015831e484e03
5
5
  SHA512:
6
- metadata.gz: 112f7ff639947e8e4d3d3e3d247588cba505b028dd72288c48ceb82a24d3fe8775ca0098f331bd00beec1b6648110634c99d56326bb43eba0d66c731d095190f
7
- data.tar.gz: 4d64f4d3ab47161a73f9db84f6efc7e4163b4265cbe7b9b266d0bceed884fded1a40e34163d929afceef5d566485b02e36b117d52faaafb97fa9f43936e0ef3e
6
+ metadata.gz: 124b015faae0d8d258efa32adcfbc1a939ef9d6d6aa6fa62a3522c6587fcb25cec81dd498e504f330af85601f306e35422bf6174bcb45a7be78a3b1f074e013b
7
+ data.tar.gz: 63f95b1ff1ec240aaf7abf64472ed6d24cbc0e0fba47196de6c8192452327a79df0adcd1afb74688320a282b481be65feef494b4b53f910b735f52d15368a649
@@ -1,4 +1,22 @@
1
1
  ready = ->
2
+ # Quote button
3
+ $('.quote-post').click (event) ->
4
+ quoute_post_id = $(event.target).data('post-id')
5
+
6
+ $.ajax
7
+ url: '/post/' + quoute_post_id
8
+ type: "GET"
9
+ dataType: "json"
10
+ success: (response) ->
11
+ quote = $('#quick_answer_textarea').val()
12
+ quote += '\n[quote author=' + response.author+ ']'
13
+ quote += response.text
14
+ quote += '[/quote]\n\n'
15
+
16
+ $('#quick_answer_textarea').val(quote)
17
+ $('body').scrollTo($('#quick_answer_textarea'))
18
+
19
+
2
20
  # BBCode editor
3
21
  $('.text-editor-buttons').click (event) ->
4
22
  return false if !$(event.target).is('a') and !$(event.target).is('i')
@@ -2,21 +2,36 @@ require_dependency "my_forum/application_controller"
2
2
 
3
3
  module MyForum
4
4
  class PostsController < ApplicationController
5
- before_filter :find_topic
6
- before_filter :find_forum
5
+ before_filter :find_topic, except: [:show]
6
+ before_filter :find_forum, except: [:show]
7
7
 
8
8
  def create
9
- post = @topic.posts.build(post_params)
10
- post.user = current_user
11
- post.save
9
+ unless params[:post].fetch(:text).blank?
10
+ post = @topic.posts.build(post_params)
11
+ post.user = current_user
12
+ post.save
12
13
 
13
- process_attachments(post)
14
+ process_attachments(post)
15
+ end
14
16
 
15
17
  last_page = @topic.posts.count / Post::PER_PAGE
16
18
  last_page = 1 if last_page == 0
17
19
  redirect_to forum_topic_path(@forum, @topic, page: last_page)
18
20
  end
19
21
 
22
+ def destroy
23
+ post = Post.find(params[:id])
24
+ post.update(is_deleted: true)
25
+ redirect_to forum_topic_path(post.topic.forum, post.topic)
26
+ end
27
+
28
+ def show
29
+ post = Post.find(params[:id])
30
+ respond_to do |format|
31
+ format.js { render json: { text: post.text, author: post.user.login }.as_json, status: :ok }
32
+ end
33
+ end
34
+
20
35
  private
21
36
 
22
37
  def process_attachments(post)
@@ -20,13 +20,13 @@ module MyForum
20
20
  end
21
21
 
22
22
  # Bold text
23
- text.gsub!(/(\[b\])(?<bold_text>.*)(\[\/b\])/i) { |match| "<strong>#{$1}</strong>" }
23
+ text.gsub!(/(\[b\](?<bold_text>.+?)\[\/b\])/i) { |match| "<strong>#{$1}</strong>" }
24
24
 
25
25
  # Italic
26
- text.gsub!(/(\[i\])(?<italic_text>.*)(\[\/i\])/i) { |match| "<i>#{$1}</i>" }
26
+ text.gsub!(/(\[i\])(?<italic_text>.*?)(\[\/i\])/i) { |match| "<i>#{$1}</i>" }
27
27
 
28
28
  # Cut
29
- text.gsub!(/(\[cut\])(?<cut_text>.*)(\[\/cut\])/i) { |match| "<pre>#{$1}</pre>" }
29
+ text.gsub!(/(\[cut\])(?<cut_text>.*?)(\[\/cut\])/i) { |match| "<pre>#{$1}</pre>" }
30
30
 
31
31
  # Color
32
32
  text.gsub!(/\[color=(.*?)\](.*?)\[\/color\]/i) { "<span style='color: #{$1}'>#{$2}</span>" }
@@ -35,9 +35,15 @@ module MyForum
35
35
  text.gsub!(/\[size=(.*?)\](.*?)\[\/size\]/i) { "<span style='font-size: #{$1}'>#{$2}</span>" }
36
36
 
37
37
  # Quote
38
- text.gsub!(/\[quote author=(.*?) link=(.*?) date=(.*?)\]/i) { bbquote(author: $1, date: $3) }
39
- text.gsub!(/\[\/quote\]/i, '</div>')
40
- text.gsub!(/\[quote(.*)\]/i, "<div class='bbqoute'>")
38
+ #text.gsub!(/\[quote author=(.*?) link=(.*?) date=(.*?)\]/i) { bbquote(author: $1, date: $3) }
39
+ #text.gsub!(/\[\/quote\]/i, '</div>')
40
+ #text.gsub!(/\[quote(.*)\]/i, "<div class='bbqoute'>")
41
+ text.gsub!(/(?<open>\[quote author=(?<autor>(.*?)) (.+)\](?<text>(.+))(?<close>\[\/quote\]))/i) do |match|
42
+ # "<div class='bbqoute'> <div class='quote_info'>#{$~[:autor]} #{t('my_forum.bbquote.wrote')} #{Time.now}:</div> #{$~[:text]} </div>"
43
+ "<div class='bbqoute'> <div class='quote_info'>#{$~[:autor]} #{t('my_forum.bbquote.wrote')}:</div> #{$~[:text]} </div>"
44
+ end
45
+
46
+
41
47
 
42
48
  # Link
43
49
  text.gsub!(/\[url=(.*?)\](.*?)\[\/url\]/i) { "<a href='#{$1}'>#{$2}</a>" }
@@ -5,6 +5,8 @@ module MyForum
5
5
 
6
6
  after_create :update_topic_latest_post
7
7
 
8
+ default_scope { where(is_deleted: false) }
9
+
8
10
  PER_PAGE = 15
9
11
 
10
12
  private
@@ -5,7 +5,12 @@
5
5
  - user_login = post.user.try(:login)
6
6
  = online_user_marker(user_login)
7
7
  = user_login
8
- .col-md-1.post_number.pull-right
8
+ .col-md-2.post_number.text-right
9
+ - # TODO optimize condition!
10
+ - if current_user and current_user.is_admin? and post.topic.posts.first != post
11
+ =link_to t('.delete'), forum_topic_post_path(@forum, post.topic, post), class: 'btn btn-xs btn-danger', method: :delete, data: { confirm: "Are you sure?" }
12
+ %button.btn.btn-xs.btn-warning.quote-post{ data: { post_id: post.id } }
13
+ =t('.quote')
9
14
  =link_to t('.number', post_number: post_counter), forum_topic_path(@forum, post.topic, show_post: post_counter)
10
15
  .row
11
16
  .col-md-2
@@ -71,6 +71,8 @@ ru:
71
71
  post:
72
72
  sent: "Отправленно: %{datetime}"
73
73
  number: "Сообщение #%{post_number}"
74
+ quote: 'Цитировать'
75
+ delete: 'удалить'
74
76
 
75
77
  users:
76
78
  signin:
data/config/routes.rb CHANGED
@@ -8,6 +8,8 @@ MyForum::Engine.routes.draw do
8
8
  match 'unread_topics', to: 'forums#unread_topics', via: [:get], as: :unread_topics
9
9
  match 'mark_all_as_read', to: 'forums#mark_all_as_read', via: [:get], as: :mark_all_as_read
10
10
 
11
+ match 'post/:id', to: 'posts#show', via: [:get], as: :post_content
12
+
11
13
  resources :images
12
14
  resources :avatars
13
15
  resources :attachments
@@ -0,0 +1,6 @@
1
+ class AddIsDeleted < ActiveRecord::Migration
2
+ def change
3
+ add_column :my_forum_posts, :is_deleted, :boolean, default: false
4
+ add_column :my_forum_topics, :is_deleted, :boolean, default: false
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module MyForum
2
- VERSION = "0.0.1.beta21"
2
+ VERSION = "0.0.1.beta22"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_forum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta21
4
+ version: 0.0.1.beta22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Omelchenko
@@ -278,6 +278,7 @@ files:
278
278
  - db/migrate/20150215212443_create_my_forum_category_permissions.rb
279
279
  - db/migrate/20150227210814_create_my_forum_private_messages.rb
280
280
  - db/migrate/20151012095554_create_my_forum_images.rb
281
+ - db/migrate/20151218135729_add_is_deleted.rb
281
282
  - lib/my_forum.rb
282
283
  - lib/my_forum/engine.rb
283
284
  - lib/my_forum/version.rb