2013-08-23 02:21:52 -04:00
|
|
|
# loaded really early
|
|
|
|
module Plugin; end
|
|
|
|
|
|
|
|
class Plugin::Metadata
|
2013-08-30 11:27:24 -04:00
|
|
|
FIELDS ||= [:name, :about, :version, :authors]
|
2013-08-23 02:21:52 -04:00
|
|
|
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
|