2013-08-23 02:21:52 -04:00
|
|
|
# loaded really early
|
|
|
|
module Plugin; end
|
|
|
|
|
|
|
|
class Plugin::Metadata
|
2016-11-14 19:42:55 -05:00
|
|
|
|
|
|
|
OFFICIAL_PLUGINS = Set.new([
|
|
|
|
"customer-flair",
|
|
|
|
"discourse-adplugin",
|
|
|
|
"discourse-akismet",
|
|
|
|
"discourse-backup-uploads-to-s3",
|
|
|
|
"discourse-cakeday",
|
|
|
|
"Canned Replies",
|
|
|
|
"discourse-data-explorer",
|
|
|
|
"discourse-details",
|
|
|
|
"discourse-nginx-performance-report",
|
|
|
|
"discourse-push-notifications",
|
|
|
|
"discourse-slack-official",
|
|
|
|
"discourse-solved",
|
|
|
|
"Spoiler Alert!",
|
|
|
|
"staff-notes",
|
|
|
|
"GitHub badges",
|
|
|
|
"hosted-site",
|
|
|
|
"lazyYT",
|
|
|
|
"logster-rate-limit-checker",
|
|
|
|
"poll",
|
|
|
|
"discourse-plugin-linkedin-auth",
|
|
|
|
"discourse-plugin-office365-auth",
|
2017-07-18 12:09:27 -04:00
|
|
|
"discourse-oauth2-basic",
|
|
|
|
"discourse-math",
|
|
|
|
"discourse-bbcode-color",
|
|
|
|
"discourse-bbcode",
|
|
|
|
"discourse-affiliate",
|
|
|
|
"discourse-translator",
|
|
|
|
"discourse-patreon"
|
2016-11-14 19:42:55 -05:00
|
|
|
])
|
|
|
|
|
2015-04-27 13:06:53 -04:00
|
|
|
FIELDS ||= [:name, :about, :version, :authors, :url, :required_version]
|
2016-11-14 19:42:55 -05:00
|
|
|
attr_accessor(*FIELDS)
|
2013-08-23 02:21:52 -04:00
|
|
|
|
|
|
|
def self.parse(text)
|
|
|
|
metadata = self.new
|
|
|
|
text.each_line do |line|
|
|
|
|
break unless metadata.parse_line(line)
|
|
|
|
end
|
|
|
|
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] == "#"
|
|
|
|
attribute, *description = line[1..-1].split(":")
|
|
|
|
|
|
|
|
description = description.join(":")
|
2015-04-27 13:06:53 -04:00
|
|
|
attribute = attribute.strip.gsub(/ /, '_').to_sym
|
2013-08-23 02:21:52 -04:00
|
|
|
|
|
|
|
if FIELDS.include?(attribute)
|
|
|
|
self.send("#{attribute}=", description.strip)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|