mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-24 22:42:27 -05:00
33 lines
666 B
Ruby
33 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
|