lib/hoe.rb in hoe-2.9.6 vs lib/hoe.rb in hoe-2.10.0

- old
+ new

@@ -65,11 +65,11 @@ class Hoe include Rake::DSL if defined?(Rake::DSL) # duh - VERSION = '2.9.6' + VERSION = '2.10.0' @@plugins = [:clean, :debug, :deps, :flay, :flog, :newb, :package, :publish, :rcov, :gemcutter, :signing, :test] ## @@ -209,17 +209,27 @@ # Optional: An array of test file patterns [default: test/**/test_*.rb] attr_accessor :test_globs ## - # Optional: The url(s) of the project. (can be array). + # Deprecated: Optional: The url(s) of the project. (can be array). # Auto-populates to a list of urls read from the beginning of # README.txt. + # attr_accessor :url ## + # Optional: The urls of the project. This can be an array or + # (preferably) a hash. Auto-populates to the urls read from the + # beginning of README.txt. + # + # See parse_urls for more details + + attr_accessor :urls + + ## # *MANDATORY*: The version. Don't hardcode! use a constant in the project. attr_accessor :version ## @@ -530,14 +540,23 @@ sections = Hash[*readme.map { |s| s =~ /^[=#]/ ? s.strip.downcase.chomp(':').split.last : s.strip }] desc = sections.values_at(*description_sections).join("\n\n") summ = desc.split(/\.\s+/).first(summary_sentences).join(". ") + urls = parse_urls(readme[1]) + self.urls ||= urls self.description ||= desc self.summary ||= summ - self.url ||= readme[1].gsub(/^\* /, '').split(/\n/).grep(/\S+/) + self.url ||= case urls + when Hash then + urls["home"] || urls["repo"] || urls.values.first + when Array then + urls + else + raise "unknown urls format: #{urls.inspect}" + end else missing readme_file end self.changes ||= begin @@ -545,9 +564,36 @@ h.split(/^(={2,}|\#{2,})/)[1..2].join.strip rescue missing history_file '' end + end + + ## + # Parse the urls section of the readme file. Returns a hash or an + # array depending on the format of the section. + # + # label1 :: url1 + # label2 :: url2 + # label3 :: url3 + # + # vs: + # + # * url1 + # * url2 + # * url3 + # + # The hash format is preferred as it will be used to populate gem + # metadata. The array format will work, but will warn that you + # should update the readme. + + def parse_urls text + lines = text.gsub(/^\* /, '').split(/\n/).grep(/\S+/) + if lines.first =~ /::/ then + Hash[lines.map { |line| line.split(/\s*::\s*/) }] + else + lines + end end ## # Load activated plugins by calling their define tasks method.