mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 13:45:59 +08:00
34 lines
666 B
Ruby
34 lines
666 B
Ruby
# loaded really early
|
|
module Plugin; end
|
|
|
|
class Plugin::Metadata
|
|
FIELDS ||= [:name, :about, :version, :authors]
|
|
attr_accessor *FIELDS
|
|
|
|
def self.parse(text)
|
|
metadata = self.new
|
|
text.each_line do |line|
|
|
break unless metadata.parse_line(line)
|
|
end
|
|
metadata
|
|
end
|
|
|
|
def parse_line(line)
|
|
line = line.strip
|
|
|
|
unless line.empty?
|
|
return false unless line[0] == "#"
|
|
attribute, *description = line[1..-1].split(":")
|
|
|
|
description = description.join(":")
|
|
attribute = attribute.strip.to_sym
|
|
|
|
if FIELDS.include?(attribute)
|
|
self.send("#{attribute}=", description.strip)
|
|
end
|
|
end
|
|
|
|
true
|
|
end
|
|
end
|