-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplugin.rb
94 lines (82 loc) · 2.85 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
# name: discourse-yearly-review
# about: Creates a topic that summarizes the previous year’s forum activity.
# meta_topic_id: 105713
# version: 0.2
# author: Simon Cossar
# url: https://github.com/discourse/discourse-yearly-review
enabled_site_setting :yearly_review_enabled
register_asset "stylesheets/yearly_review.scss"
after_initialize do
module ::YearlyReview
PLUGIN_NAME = "yearly-review"
POST_CUSTOM_FIELD ||= "yearly_review"
def self.current_year
Time.now.year
end
def self.last_year
current_year - 1
end
end
::ActionController::Base.prepend_view_path File.expand_path(
"../app/views/yearly-review",
__FILE__,
)
require_relative "app/jobs/yearly_review"
require_dependency "email/styles"
Email::Styles.register_plugin_style do |doc|
doc.css("[data-review-topic-users] table").each { |element| element["width"] = "100%" }
doc.css("[data-review-featured-topics] table").each { |element| element["width"] = "100%" }
doc
.css("[data-review-topic-users] th")
.each do |element|
element["style"] = "text-align: left;padding-bottom: 12px;"
element["width"] = "50%"
end
doc
.css("[data-review-featured-topics] th")
.each { |element| element["style"] = "text-align: left;padding-bottom: 12px;" }
doc
.css("[data-review-featured-topics] th:first-child")
.each { |element| element["width"] = "15%" }
doc
.css("[data-review-featured-topics] th:nth-child(2)")
.each { |element| element["width"] = "60%" }
doc
.css("[data-review-featured-topics] th:last-child")
.each { |element| element["width"] = "25%" }
doc
.css("[data-review-topic-users] td")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["valign"] = "top"
end
doc
.css("[data-review-featured-topics] td")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["valign"] = "top"
end
doc
.css("[data-review-topic-users] td table td:first-child")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["width"] = "25"
end
doc
.css("[data-review-topic-users] td table td:nth-child(2)")
.each { |element| element["style"] = "padding-left: 4px;padding-bottom: 6px;" }
end
on(:username_changed) do |old_username, new_username|
Post
.joins(:_custom_fields)
.where(
"post_custom_fields.name = ? AND posts.raw LIKE ?",
YearlyReview::POST_CUSTOM_FIELD,
"%/#{old_username}/%",
)
.update_all(
"raw = REPLACE(raw, '/#{old_username}/', '/#{new_username}/'), baked_version = NULL",
)
end
end