Skip to content

Commit

Permalink
+ Added rdoc extension to the history and readme file finder globs.
Browse files Browse the repository at this point in the history
+ 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]
  • Loading branch information
zenspider committed Feb 8, 2020
1 parent 408c716 commit dd845b9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/hoe.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- mode: ruby; coding: us-ascii; -*-

require "rubygems"

begin
gem "rake"
rescue Gem::LoadError
Expand Down Expand Up @@ -651,26 +647,32 @@ def initialize name, version = nil # :nodoc:
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

##
# 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
Expand Down Expand Up @@ -809,7 +811,7 @@ def plugin? name

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
Expand Down
43 changes: 43 additions & 0 deletions test/test_hoe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,49 @@ def test_parse_urls_hash
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",
Expand Down

0 comments on commit dd845b9

Please sign in to comment.