lib/inochi/tasks/4-ann.rake in inochi-4.0.1 vs lib/inochi/tasks/4-ann.rake in inochi-5.0.0
- old
+ new
@@ -5,24 +5,25 @@
# when announcing things on the ruby-talk mailing list
@ann_subject_prefix = '[ANN] '
task :@ann_subject do
unless @ann_subject
- Rake::Task[:@project].invoke
@ann_subject = @ann_subject_prefix +
@project_module::PROJECT + ' ' + @project_module::VERSION
end
end
# fetch project description from manual
task :@ann_nfo_html_nodes do
unless @ann_nfo_html_nodes
begin
- head, body = fetch_nodes_between('h2#NAME ~ p', 'h1,h2,h3,h4,h5,h6')
+ head, body = fetch_nodes_between(
+ 'h2#_description + div', 'h1,h2,h3,h4,h5,h6'
+ )
rescue => error
error.message.insert 0,
- "The manual lacks a <H2> ABOUT heading.\n"
+ "The manual lacks a <h2> DESCRIPTION heading.\n"
raise error
end
@ann_nfo_html_nodes = body
end
@@ -37,14 +38,16 @@
# fetch release notes from manual
task :@ann_rel_html_body_nodes do
unless @ann_rel_html_body_nodes
begin
- head, body = fetch_nodes_between('h2#HISTORY ~ h3', 'h1,h2,h3')
+ head, body = fetch_nodes_between(
+ 'h2#_history + div > h3', 'h1,h2,h3'
+ )
rescue => error
error.message.insert 0,
- "The manual lacks a <H3> heading under a <H2> HISTORY heading.\n"
+ "The manual lacks a <h3> heading beneath the <h2> HISTORY heading.\n"
raise error
end
@ann_rel_html_title_node = head
@ann_rel_html_body_nodes = body
@@ -53,14 +56,16 @@
# fetch authors list from manual
task :@project_authors_html_nodes do
unless @project_authors_html_nodes
begin
- head, body = fetch_nodes_between('h2#AUTHORS', 'h1,h2,h3,h4,h5,h6')
+ head, body = fetch_nodes_between(
+ 'h2#_authors + div', 'h1,h2,h3,h4,h5,h6'
+ )
rescue => error
error.message.insert 0,
- "The manual lacks content under a <H2> AUTHORS heading.\n"
+ "The manual lacks content under a <h2> AUTHORS heading.\n"
raise error
end
@project_authors_html_nodes = body
end
@@ -85,14 +90,17 @@
<h2>#{@project_module::TAGLINE}</h2>
<p>#{@project_module::WEBSITE}</p>
</center>
#{@ann_nfo_html_nodes.join}
#{@ann_rel_html_title_node}
- #{@ann_rel_html_body_nodes.map(&:to_xml).join}
- }.strip
-
- @ann_html = resolve_html_links(@ann_html)
+ #{@ann_rel_html_body_nodes.map(&:to_html).join}
+ }.
+ strip.
+ #
+ # resolve internal hyperlinks to the project website
+ #
+ gsub(/<a href=['"]?(?=#)/) { $& + @project_module::WEBSITE }
end
end
task :@ann_text do
unless @ann_text
@@ -108,11 +116,11 @@
@ann_html_dst = 'ann.html'
desc 'Build HTML announcement.'
task 'ann:html' => @ann_html_dst
-file @ann_html_dst => @man_src do
+file @ann_html_dst => @man_asciidoc_src do
Rake::Task[:@ann_html].invoke
File.write @ann_html_dst, @ann_html
end
CLOBBER.include @ann_html_dst
@@ -124,11 +132,11 @@
@ann_text_dst = 'ann.txt'
desc 'Build plain text announcement.'
task 'ann:text' => @ann_text_dst
-file @ann_text_dst => @man_src do
+file @ann_text_dst => @man_asciidoc_src do
Rake::Task[:@ann_text].invoke
File.write @ann_text_dst, @ann_text
end
CLOBBER.include @ann_text_dst
@@ -140,12 +148,11 @@
@ann_feed_dst = 'ann.xml'
desc 'Build RSS feed announcement.'
task 'ann:feed' => @ann_feed_dst
-file @ann_feed_dst => @man_src do
- Rake::Task[:@project].invoke
+file @ann_feed_dst => @man_asciidoc_src do
Rake::Task[:@ann_nfo_html_nodes].invoke
Rake::Task[:@ann_rel_html_body_nodes].invoke
require 'rss/maker'
rss = RSS::Maker.make('2.0') do |feed|
@@ -156,11 +163,11 @@
item = feed.items.new_item
item.link = @project_module::WEBSITE
require 'time'
item.date = Time.parse(@project_module::RELDATE)
item.title = @ann_rel_html_title_node.inner_text
- item.description = @ann_rel_html_body_nodes.join
+ item.description = @ann_rel_html_body_nodes.map(&:to_html).join
end
File.write @ann_feed_dst, rss
end
@@ -178,53 +185,38 @@
# Fetches all nodes between those matching the given head and tail selectors.
#
def fetch_nodes_between head_selector, tail_selector
Rake::Task[:@man_html_dom].invoke
- head = @man_html_dom.at(head_selector)
+ head = @man_html_dom.at(head_selector) or raise head_selector
body = []
tail = head
- while tail = tail.next_sibling and not tail.matches? tail_selector
- body << tail
- end
+ body << tail while
+ tail = tail.next_sibling and
+ not tail.matches? tail_selector
[head, body, tail]
end
##
# Converts the given HTML into plain text. we do this using
# lynx because (1) it outputs a list of all hyperlinks used
# in the HTML document and (2) it runs on all major platforms
#
def convert_html_to_text html
- # lynx's -dump option requires a .html file
+ # lynx's -dump option requires a *.html file
require 'tempfile'
tmp_file = Tempfile.new('inochi').path + '.html'
begin
- File.write tmp_file, html
-
- `lynx -dump #{tmp_file} -width 70`.
+ File.write tmp_file, html.to_s.
#
- # improve readability of list items
- # by adding a blank line between them
+ # add space between subsections and list items to improve readability
#
- gsub(/(\r?\n)( +\* \S)/, '\1\1\2')
+ gsub(/(?=<div class="title">|<li>)/, '<p> </p>')
+
+ `lynx -dump #{tmp_file} -width 70`
ensure
File.delete tmp_file
end
-end
-
-##
-# Converts relative URLs in the given HTML into
-# absolute URLs bound to the given base URL.
-#
-# http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
-#
-def resolve_html_links html, base_url = nil
- Rake::Task[:@project].invoke
- base_url ||= @project_module::WEBSITE
-
- require 'cgi'
- "<base href='#{CGI.escapeHTML base_url}'/> #{html}"
end