From dd845b9d716ff80392b1dd593c54b64e232b8ce5 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sat, 8 Feb 2020 15:14:16 -0800 Subject: + Added rdoc extension to the history and readme file finder globs. + Refactored intuit_values to take the file content as an arg. + Extended readme parsing to more intelligently deal with markup sections. [git-p4: depot-paths = "//src/hoe/dev/": change = 12535] --- lib/hoe.rb | 32 +++++++++++++++++--------------- test/test_hoe.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/lib/hoe.rb b/lib/hoe.rb index 9c3cfb5..9790fcd 100644 --- a/lib/hoe.rb +++ b/lib/hoe.rb @@ -1,7 +1,3 @@ -# -*- mode: ruby; coding: us-ascii; -*- - -require "rubygems" - begin gem "rake" rescue Gem::LoadError @@ -651,8 +647,8 @@ class Hoe self.history_file = manifest.grep(/^History\./).first end - self.history_file ||= Dir.glob("History.{txt,md}").first || "History.txt" - self.readme_file ||= Dir.glob("README.{txt,md}").first || "README.txt" + self.history_file ||= Dir.glob("History.{rdoc,txt,md}").first || "History.txt" + self.readme_file ||= Dir.glob("README.{rdoc,txt,md}").first || "README.txt" abort "Hoe.new {...} removed. Switch to Hoe.spec." if block_given? end @@ -660,17 +656,23 @@ class Hoe ## # Intuit values from the readme and history files. - def intuit_values - header_re = /^((?:=+|#+) .*)$/ - readme = File.read_utf(readme_file).split(header_re)[1..-1] rescue "" + def intuit_values input + readme = input + .lines + .chunk { |l| l[/^(?:=+|#+)/] || "" } + .map(&:last) + .each_slice(2) + .map { |k, v| + kp = k.join + kp = kp.strip.chomp(":").split.last.downcase if k.size == 1 + [kp, v.join.strip] + } + .to_h unless readme.empty? then - sections = Hash[*readme.map { |s| - s =~ /^[=#]/ ? s.strip.downcase.chomp(":").split.last : s.strip - }] - desc = sections.values_at(*description_sections).join("\n\n") + desc = readme.values_at(*description_sections).join("\n\n") summ = desc.split(/\.\s+/).first(summary_sentences).join(". ") - urls = parse_urls(readme[1]) + urls = parse_urls(readme.values.first) self.urls ||= urls self.description ||= desc @@ -809,7 +811,7 @@ class Hoe def post_initialize activate_plugin_deps - intuit_values + intuit_values File.read_utf readme_file if readme_file validate_fields define_spec load_plugin_tasks diff --git a/test/test_hoe.rb b/test/test_hoe.rb index 60b9522..a39d479 100644 --- a/test/test_hoe.rb +++ b/test/test_hoe.rb @@ -217,6 +217,49 @@ class TestHoe < Minitest::Test assert_equal exp, hoe.parse_urls(hash) end + def test_parse_mrww + h = nil + mrww_readme = <<~EOM + = make + = rake + = work + = well + + home :: https://github.com/seattlerb/makerakeworkwell + rdoc :: http://docs.seattlerb.org/makerakeworkwell + + == DESCRIPTION: + + make/rake/work/well provides two simple modifications to rake that + make working with file tasks cleaner, easier, and faster. + EOM + + + + assert_silent do + h = Hoe.spec "blah" do + developer "author", "email" + license "MIT" + self.version = "1.0" + self.readme_file = nil + self.history_file = nil + self.changes = true + + self.intuit_values mrww_readme + end + end + + desc = mrww_readme.lines[10..11].join.chomp + urls = { + "home" => "https://github.com/seattlerb/makerakeworkwell", + "rdoc" => "http://docs.seattlerb.org/makerakeworkwell" + } + + assert_equal desc, h.description + assert_equal desc, h.summary + assert_equal urls, h.urls + end + def test_metadata hash = [ "home :: https://github.com/seattlerb/hoe", -- cgit v1.2.1