2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-23 02:21:52 -04:00
|
|
|
# loaded really early
|
|
|
|
module Plugin
|
|
|
|
end
|
|
|
|
|
|
|
|
class Plugin::Metadata
|
2024-10-15 22:09:07 -04:00
|
|
|
OFFICIAL_PLUGINS =
|
2023-01-09 07:10:19 -05:00
|
|
|
Set.new(
|
2023-08-02 07:48:20 -04: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 04:22:54 -04:00
|
|
|
discourse-geoblocking
|
2023-08-02 07:48:20 -04:00
|
|
|
discourse-github
|
|
|
|
discourse-gradle-issue
|
|
|
|
discourse-graphviz
|
|
|
|
discourse-group-tracker
|
2024-10-11 16:35:12 -04:00
|
|
|
discourse-hcaptcha
|
2023-08-02 07:48:20 -04:00
|
|
|
discourse-invite-tokens
|
2023-08-10 06:25:22 -04:00
|
|
|
discourse-jira
|
2023-08-02 07:48:20 -04: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 05:40:36 -04:00
|
|
|
discourse-microsoft-auth
|
2023-08-02 07:48:20 -04: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 04:22:54 -04:00
|
|
|
discourse-tag-by-group
|
2023-08-02 07:48:20 -04: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 11:20:43 -04:00
|
|
|
automation
|
2023-08-02 07:48:20 -04:00
|
|
|
chat
|
|
|
|
checklist
|
2024-06-10 05:40:36 -04:00
|
|
|
docker_manager
|
2023-10-23 17:26:59 -04:00
|
|
|
footnote
|
2024-06-10 05:40:36 -04:00
|
|
|
poll
|
2023-10-23 17:26:59 -04:00
|
|
|
spoiler-alert
|
2024-06-10 05:40:36 -04:00
|
|
|
styleguide
|
2023-01-09 07:10:19 -05:00
|
|
|
],
|
|
|
|
)
|
2016-11-14 19:42:55 -05:00
|
|
|
|
2024-10-15 22:09:07 -04:00
|
|
|
FIELDS = %i[name about version authors contact_emails url required_version meta_topic_id label]
|
2016-11-14 19:42:55 -05:00
|
|
|
attr_accessor(*FIELDS)
|
2013-08-23 02:21:52 -04:00
|
|
|
|
2024-10-15 22:09:07 -04:00
|
|
|
MAX_FIELD_LENGTHS = {
|
2023-11-29 19:53:17 -05: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 02:21:52 -04:00
|
|
|
def self.parse(text)
|
|
|
|
metadata = self.new
|
|
|
|
text.each_line { |line| break unless metadata.parse_line(line) }
|
|
|
|
metadata
|
|
|
|
end
|
|
|
|
|
2016-11-14 19:42:55 -05:00
|
|
|
def official?
|
|
|
|
OFFICIAL_PLUGINS.include?(name)
|
|
|
|
end
|
|
|
|
|
2013-08-23 02:21:52 -04:00
|
|
|
def parse_line(line)
|
|
|
|
line = line.strip
|
|
|
|
|
|
|
|
unless line.empty?
|
|
|
|
return false unless line[0] == "#"
|
2023-11-29 19:53:17 -05:00
|
|
|
attribute, *value = line[1..-1].split(":")
|
2013-08-23 02:21:52 -04:00
|
|
|
|
2023-11-29 19:53:17 -05:00
|
|
|
value = value.join(":")
|
2015-04-27 13:06:53 -04:00
|
|
|
attribute = attribute.strip.gsub(/ /, "_").to_sym
|
2013-08-23 02:21:52 -04:00
|
|
|
|
2023-11-29 19:53:17 -05:00
|
|
|
if FIELDS.include?(attribute)
|
|
|
|
self.public_send(
|
|
|
|
"#{attribute}=",
|
|
|
|
value.strip.truncate(MAX_FIELD_LENGTHS[attribute] || 1000),
|
|
|
|
)
|
|
|
|
end
|
2013-08-23 02:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|