summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Davis <ryand@zenspider.com>2020-02-08 15:14:16 -0800
committerRyan Davis <ryand@zenspider.com>2020-02-08 15:14:16 -0800
commitdd845b9d716ff80392b1dd593c54b64e232b8ce5 (patch)
tree982e27a379a97e1228b33af81c7084d86cd016a7
parent408c71645f34ea8e9bb1239b935957100f50121b (diff)
downloadhoe-dd845b9d716ff80392b1dd593c54b64e232b8ce5.tar.gz
+ 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]
-rw-r--r--lib/hoe.rb32
-rw-r--r--test/test_hoe.rb43
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",