Can edit category descriptions, they show up in a title attribute

This commit is contained in:
Robin Ward
2013-02-21 18:09:56 -05:00
parent 2d9942ceef
commit 532b1f5450
21 changed files with 268 additions and 103 deletions

View File

@@ -1,5 +1,8 @@
require 'edit_rate_limiter'
class PostRevisor
attr_reader :category_changed
def initialize(post)
@post = post
end
@@ -8,6 +11,7 @@ class PostRevisor
@user, @new_raw, @opts = user, new_raw, opts
return false if not should_revise?
revise_post
update_category_description
post_process_post
true
end
@@ -76,6 +80,25 @@ class PostRevisor
@post.save
end
def update_category_description
# If we're revising the first post, we might have to update the category description
return unless @post.post_number == 1
# Is there a category with our topic id?
category = Category.where(topic_id: @post.topic_id).first
return unless category.present?
# If found, update its description
body = @post.cooked
matches = body.scan(/\<p\>(.*)\<\/p\>/)
if matches and matches[0] and matches[0][0]
new_description = matches[0][0]
new_description = nil if new_description == I18n.t("category.replace_paragraph")
category.update_column(:description, new_description)
@category_changed = category
end
end
def post_process_post
@post.invalidate_oneboxes = true
@post.trigger_post_process