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
|
2017-08-12 10:18:04 +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-automation
|
|
|
|
discourse-bbcode
|
|
|
|
discourse-bbcode-color
|
|
|
|
discourse-bcc
|
|
|
|
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-encrypt
|
|
|
|
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
|
|
|
|
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
|
|
|
|
discourse-moderator-attention
|
|
|
|
discourse-narrative-bot
|
|
|
|
discourse-newsletter-integration
|
|
|
|
discourse-no-bump
|
|
|
|
discourse-oauth2-basic
|
|
|
|
discourse-openid-connect
|
|
|
|
discourse-patreon
|
|
|
|
discourse-perspective-api
|
|
|
|
discourse-linkedin-auth
|
|
|
|
discourse-microsoft-auth
|
|
|
|
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-shared-edits
|
|
|
|
discourse-signatures
|
|
|
|
discourse-sitemap
|
|
|
|
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
|
|
|
|
docker_manager
|
|
|
|
chat
|
|
|
|
poll
|
|
|
|
styleguide
|
|
|
|
checklist
|
2023-10-24 05:26:59 +08:00
|
|
|
footnote
|
|
|
|
spoiler-alert
|
2023-01-09 20:10:19 +08:00
|
|
|
],
|
|
|
|
)
|
2016-11-15 08:42:55 +08:00
|
|
|
|
2023-10-10 08:16:13 +08:00
|
|
|
FIELDS ||= %i[
|
|
|
|
name
|
|
|
|
about
|
|
|
|
version
|
|
|
|
authors
|
|
|
|
contact_emails
|
|
|
|
url
|
|
|
|
required_version
|
|
|
|
transpile_js
|
|
|
|
meta_topic_id
|
2023-11-30 08:53:17 +08:00
|
|
|
label
|
2023-10-10 08:16:13 +08:00
|
|
|
]
|
2016-11-15 08:42:55 +08:00
|
|
|
attr_accessor(*FIELDS)
|
2013-08-23 14:21:52 +08:00
|
|
|
|
2023-11-30 08:53:17 +08:00
|
|
|
MAX_FIELD_LENGTHS ||= {
|
|
|
|
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
|