2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-23 14:21:52 +08:00
|
|
|
# loaded really early
|
|
|
|
module Plugin
|
|
|
|
end
|
|
|
|
|
|
|
|
class Plugin::Metadata
|
2024-10-16 10:09:07 +08:00
|
|
|
OFFICIAL_PLUGINS =
|
2023-01-09 20:10:19 +08:00
|
|
|
Set.new(
|
2023-08-02 19:48:20 +08:00
|
|
|
%w[
|
|
|
|
discourse-adplugin
|
|
|
|
discourse-affiliate
|
|
|
|
discourse-ai
|
|
|
|
discourse-akismet
|
|
|
|
discourse-algolia
|
|
|
|
discourse-apple-auth
|
|
|
|
discourse-assign
|
|
|
|
discourse-auto-deactivate
|
|
|
|
discourse-bbcode
|
|
|
|
discourse-bbcode-color
|
|
|
|
discourse-cakeday
|
|
|
|
discourse-calendar
|
|
|
|
discourse-categories-suppressed
|
|
|
|
discourse-category-experts
|
|
|
|
discourse-characters-required
|
|
|
|
discourse-chat-integration
|
|
|
|
discourse-code-review
|
|
|
|
discourse-crowd
|
|
|
|
discourse-data-explorer
|
|
|
|
discourse-details
|
|
|
|
discourse-docs
|
|
|
|
discourse-follow
|
|
|
|
discourse-fontawesome-pro
|
|
|
|
discourse-gamification
|
2023-08-25 16:22:54 +08:00
|
|
|
discourse-geoblocking
|
2023-08-02 19:48:20 +08:00
|
|
|
discourse-github
|
|
|
|
discourse-gradle-issue
|
|
|
|
discourse-graphviz
|
|
|
|
discourse-group-tracker
|
2024-10-12 04:35:12 +08:00
|
|
|
discourse-hcaptcha
|
2023-08-02 19:48:20 +08:00
|
|
|
discourse-invite-tokens
|
2023-08-10 18:25:22 +08:00
|
|
|
discourse-jira
|
2023-08-02 19:48:20 +08:00
|
|
|
discourse-lazy-videos
|
|
|
|
discourse-local-dates
|
|
|
|
discourse-login-with-amazon
|
|
|
|
discourse-logster-rate-limit-checker
|
|
|
|
discourse-logster-transporter
|
|
|
|
discourse-lti
|
|
|
|
discourse-math
|
2024-06-10 17:40:36 +08:00
|
|
|
discourse-microsoft-auth
|
2023-08-02 19:48:20 +08:00
|
|
|
discourse-narrative-bot
|
|
|
|
discourse-newsletter-integration
|
|
|
|
discourse-no-bump
|
|
|
|
discourse-oauth2-basic
|
|
|
|
discourse-openid-connect
|
|
|
|
discourse-patreon
|
|
|
|
discourse-perspective-api
|
|
|
|
discourse-policy
|
|
|
|
discourse-post-voting
|
|
|
|
discourse-presence
|
|
|
|
discourse-prometheus
|
|
|
|
discourse-prometheus-alert-receiver
|
|
|
|
discourse-push-notifications
|
|
|
|
discourse-reactions
|
|
|
|
discourse-restricted-replies
|
|
|
|
discourse-rss-polling
|
|
|
|
discourse-salesforce
|
|
|
|
discourse-saml
|
|
|
|
discourse-saved-searches
|
|
|
|
discourse-signatures
|
|
|
|
discourse-solved
|
|
|
|
discourse-staff-alias
|
|
|
|
discourse-steam-login
|
|
|
|
discourse-subscriptions
|
2023-08-25 16:22:54 +08:00
|
|
|
discourse-tag-by-group
|
2023-08-02 19:48:20 +08:00
|
|
|
discourse-teambuild
|
|
|
|
discourse-templates
|
|
|
|
discourse-tooltips
|
|
|
|
discourse-topic-voting
|
|
|
|
discourse-translator
|
|
|
|
discourse-user-card-badges
|
|
|
|
discourse-user-notes
|
|
|
|
discourse-vk-auth
|
|
|
|
discourse-whos-online
|
|
|
|
discourse-yearly-review
|
|
|
|
discourse-zendesk-plugin
|
|
|
|
discourse-zoom
|
2024-04-03 23:20:43 +08:00
|
|
|
automation
|
2023-08-02 19:48:20 +08:00
|
|
|
chat
|
|
|
|
checklist
|
2024-06-10 17:40:36 +08:00
|
|
|
docker_manager
|
2023-10-24 05:26:59 +08:00
|
|
|
footnote
|
2024-06-10 17:40:36 +08:00
|
|
|
poll
|
2023-10-24 05:26:59 +08:00
|
|
|
spoiler-alert
|
2024-06-10 17:40:36 +08:00
|
|
|
styleguide
|
2023-01-09 20:10:19 +08:00
|
|
|
],
|
|
|
|
)
|
2016-11-15 08:42:55 +08:00
|
|
|
|
2024-10-16 10:09:07 +08:00
|
|
|
FIELDS = %i[name about version authors contact_emails url required_version meta_topic_id label]
|
2016-11-15 08:42:55 +08:00
|
|
|
attr_accessor(*FIELDS)
|
2013-08-23 14:21:52 +08:00
|
|
|
|
2024-10-16 10:09:07 +08:00
|
|
|
MAX_FIELD_LENGTHS = {
|
2023-11-30 08:53:17 +08:00
|
|
|
name: 75,
|
|
|
|
about: 350,
|
|
|
|
authors: 200,
|
|
|
|
contact_emails: 200,
|
|
|
|
url: 500,
|
|
|
|
label: 20,
|
|
|
|
}
|
|
|
|
|
|
|
|
def meta_topic_id=(value)
|
|
|
|
@meta_topic_id =
|
|
|
|
begin
|
|
|
|
Integer(value)
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-23 14:21:52 +08:00
|
|
|
def self.parse(text)
|
|
|
|
metadata = self.new
|
|
|
|
text.each_line { |line| break unless metadata.parse_line(line) }
|
|
|
|
metadata
|
|
|
|
end
|
|
|
|
|
2016-11-15 08:42:55 +08:00
|
|
|
def official?
|
|
|
|
OFFICIAL_PLUGINS.include?(name)
|
|
|
|
end
|
|
|
|
|
2013-08-23 14:21:52 +08:00
|
|
|
def parse_line(line)
|
|
|
|
line = line.strip
|
|
|
|
|
|
|
|
unless line.empty?
|
|
|
|
return false unless line[0] == "#"
|
2023-11-30 08:53:17 +08:00
|
|
|
attribute, *value = line[1..-1].split(":")
|
2013-08-23 14:21:52 +08:00
|
|
|
|
2023-11-30 08:53:17 +08:00
|
|
|
value = value.join(":")
|
2015-04-28 01:06:53 +08:00
|
|
|
attribute = attribute.strip.gsub(/ /, "_").to_sym
|
2013-08-23 14:21:52 +08:00
|
|
|
|
2023-11-30 08:53:17 +08:00
|
|
|
if FIELDS.include?(attribute)
|
|
|
|
self.public_send(
|
|
|
|
"#{attribute}=",
|
|
|
|
value.strip.truncate(MAX_FIELD_LENGTHS[attribute] || 1000),
|
|
|
|
)
|
|
|
|
end
|
2013-08-23 14:21:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|