lib/inochi/inochi.rb in inochi-0.1.0 vs lib/inochi/inochi.rb in inochi-0.2.0
- old
+ new
@@ -226,13 +226,14 @@
#
# * An AUTHORS constant (which has the form "[[name, info]]"
# where "name" is the name of a copyright holder and "info" is
# their contact information) is added to the project module.
#
- # This information is extracted from copyright notices in
- # the project license file. NOTE that the first copyright
- # notice must correspond to the primary project maintainer.
+ # Unless this information is supplied via the :authors option,
+ # it is automatically extracted from copyright notices in the
+ # project license file, where the first copyright notice is
+ # expected to correspond to the primary project maintainer.
#
# Copyright notices must be in the following form:
#
# Copyright YEAR HOLDER <EMAIL>
#
@@ -245,10 +246,15 @@
# as a namespace for the entire project.
#
# @param [Hash] options
# Additional method parameters, which are all optional:
#
+ # [Array] :authors =>
+ # A list of project authors and their contact information. This
+ # list must have the form "[[name, info]]" where "name" is the name
+ # of a project author and "info" is their contact information.
+ #
# [String] :license_file =>
# Path (relative to the main project directory which contains the
# project Rakefile) to the file which contains the project license.
#
# The default value is "LICENSE".
@@ -303,38 +309,70 @@
program_file = first_caller_file
program_home = File.dirname(program_file)
# load the project module
program_name = File.basename(program_home)
+ project_libs = File.join('lib', program_name)
- require File.join('lib', program_name)
+ require project_libs
project_module = fetch_project_module(project_symbol)
# supply default options
options[:rubyforge_project] ||= program_name
options[:rubyforge_section] ||= program_name
- options[:raa_project] ||= program_name
- options[:license_file] ||= 'LICENSE'
- options[:logins_file] ||= File.join(ENV['HOME'], '.config', 'inochi', 'logins.yaml')
- options[:upload_delete] ||= false
- options[:upload_options] ||= []
+ options[:raa_project] ||= program_name
+ options[:license_file] ||= 'LICENSE'
+ options[:logins_file] ||= File.join(ENV['HOME'], '.config', 'inochi', 'logins.yaml')
+ options[:upload_delete] ||= false
+ options[:upload_options] ||= []
# add AUTHORS constant to the project module
- license = File.read(options[:license_file])
-
- copyright_holders =
- license.scan(/Copyright.*?\d+\s+(.*)/).flatten.
+ copyright_holders = options[:authors] ||
+ File.read(options[:license_file]).
+ scan(/Copyright.*?\d+\s+(.*)/).flatten.
map {|s| (s =~ /\s*<(.*?)>/) ? [$`, $1] : [s, ''] }
project_module.const_set :AUTHORS, copyright_holders
require 'rake/clean'
hide_rake_task = lambda do |name|
Rake::Task[name].instance_variable_set :@comment, nil
end
+ # testing
+ desc 'Run all unit tests.'
+ task :test do
+ ruby '-w', '-I.', '-Ilib', '-r', program_name, '-e', %q{
+ # set title of test suite
+ $0 = File.basename(Dir.pwd)
+
+ require 'minitest/unit'
+ require 'minitest/spec'
+ require 'minitest/mock'
+ MiniTest::Unit.autorun
+
+ Dir['test/**/*.rb'].sort.each do |test|
+ unit = test.sub('test/', 'lib/')
+
+ if File.exist? unit
+ # strip file extension because require()
+ # does not normalize its input and it
+ # will think that the two paths (with &
+ # without file extension) are different
+ unit_path = unit.sub(/\.rb$/, '').sub('lib/', '')
+ test_path = test.sub(/\.rb$/, '')
+
+ require unit_path
+ require test_path
+ else
+ warn "Skipped test #{test.inspect} because it lacks a corresponding #{unit.inspect} unit."
+ end
+ end
+ }
+ end
+
# documentation
desc 'Build all documentation.'
task :doc => %w[ doc:api doc:man ]
# user manual
@@ -432,13 +470,13 @@
text = `lynx -dump #{tmp_file} -width 70`
ensure
File.delete tmp_file
end
- # improve readability of list items that span multiple
- # lines by adding a blank line between such items
- text.gsub! %r{^( *[^\*\s].*)(\r?\n)( *\* \S)}, '\1\2\2\3'
+ # improve readability of list items
+ # by adding a blank line between them
+ text.gsub! %r{(\r?\n)( +\* \S)}, '\1\1\2'
text
end
# binds relative addresses in the given HTML to the project docsite
@@ -479,9 +517,12 @@
#{ann_rel_doc}
}
# remove heading navigation menus
ann_html.gsub! %r{<div class="nav"[^>]*>(.*?)</div>}, ''
+
+ # remove latex-style heading numbers
+ ann_html.gsub! %r"(<(h\d)[^>]*>).+?(?: ){2}(.+?)(</\2>)"m, '\1\3\4'
ann_html = resolve_html_links[ann_html]
end
end