task/gemgem.rb in dm-is-reflective-1.0.1.rc vs task/gemgem.rb in dm-is-reflective-1.0.1

- old
+ new

@@ -10,27 +10,92 @@ def create yield(spec = Gem::Specification.new{ |s| s.authors = ['Lin Jen-Shin (godfat)'] s.email = ['godfat (XD) godfat.org'] - s.summary = File.read("#{Gemgem.dir}/README"). - match(/DESCRIPTION:\n\n(.+?)\n\n/m)[1] - s.description = s.summary + s.description = description.join + s.summary = description.first - s.extra_rdoc_files = %w[CHANGES CONTRIBUTORS LICENSE TODO] - s.rdoc_options = %w[--main README] s.rubygems_version = Gem::VERSION s.date = Time.now.strftime('%Y-%m-%d') s.files = gem_files s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$}) + s.executables = Dir['bin/*'].map{ |f| File.basename(f) } s.require_paths = %w[lib] }) - spec.homepage = "https://github.com/godfat/#{spec.name}" unless - spec.homepage + spec.homepage ||= "https://github.com/godfat/#{spec.name}" spec end + def readme + path = %w[README.md README].find{ |name| + File.exist?("#{Gemgem.dir}/#{name}") + } + @readme ||= + if path + ps = "##{File.read(path)}". + scan(/((#+)[^\n]+\n\n.+?(?=\n\n\2[^#\n]+\n))/m).map(&:first) + ps.inject({'HEADER' => ps.first}){ |r, s, i| + r[s[/\w+/]] = s + r + } + else + {} + end + end + + def description + @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a + end + + def changes + path = %w[CHANGES.md CHANGES].find{ |name| + File.exist?("#{Gemgem.dir}/#{name}") + } + @changes ||= + if path + date = '\d+{4}\-\d+{2}\-\d{2}' + File.read(path).match( + /([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1] + else + '' + end + end + + def ann_md + "#{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \ + "##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \ + "### CHANGES:\n\n" \ + "###{changes}\n\n" \ + "##{readme['INSTALLATION']}\n\n" + + if readme['SYNOPSIS'] then "##{readme['SYNOPSIS'][/[^\n]+\n\n[^\n]+/]}" + else '' end + end + + def ann_html + gem 'nokogiri' + gem 'kramdown' + + IO.popen('kramdown', 'r+') do |md| + md.puts Gemgem.ann_md + md.close_write + require 'nokogiri' + html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>") + html.css('*').each{ |n| n.delete('id') } + html.root.children.to_html + end + end + + def ann_email + "#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \ + "#{readme['DESCRIPTION']}\n\n" \ + "#{readme['INSTALLATION']}\n\n" + + if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end + + "## CHANGES:\n\n" \ + "##{changes}\n\n" + end + def gem_tag "#{spec.name}-#{spec.version}" end def write @@ -48,11 +113,11 @@ } end def all_files @all_files ||= find_files(Pathname.new(dir)).map{ |file| - if file.to_s =~ %r{\.git/} + if file.to_s =~ %r{\.git/|\.git$} nil else file.to_s end }.compact.sort @@ -81,11 +146,11 @@ path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten end def ignore_patterns @ignore_files ||= expand_patterns( - File.read("#{dir}/.gitignore").split("\n").reject{ |pattern| + gitignore.split("\n").reject{ |pattern| pattern.strip == '' }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} } end def expand_patterns pathes @@ -98,10 +163,18 @@ Pathname.new(File.dirname(path)).children.select(&:directory?). map{ |prefix| "#{prefix}/#{File.basename(path)}" }) end }.flatten end + + def gitignore + if File.exist?(path = "#{dir}/.gitignore") + File.read(path) + else + '' + end + end end namespace :gem do desc 'Install gem' @@ -126,35 +199,64 @@ task :check do ver = Gemgem.spec.version.to_s if ENV['VERSION'].nil? - puts("\x1b[35mExpected " \ - "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ver}\x1b[m") + puts("\e[35mExpected " \ + "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m") exit(1) elsif ENV['VERSION'] != ver - puts("\x1b[35mExpected \x1b[33mVERSION\x1b[35m=\x1b[33m#{ver} " \ - "\x1b[35mbut got\n " \ - "\x1b[33mVERSION\x1b[35m=\x1b[33m#{ENV['VERSION']}\x1b[m") + puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \ + "\e[35mbut got\n " \ + "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m") exit(2) end end end # of gem namespace -desc 'Run tests' +desc 'Run tests in memory' task :test do - sh("#{Gem.ruby} -I lib -S bacon --quiet test/test_*.rb") + require 'bacon' + Bacon.extend(Bacon::TestUnitOutput) + Bacon.summary_on_exit + $LOAD_PATH.unshift('lib') + Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] } end +desc 'Run tests with shell' +task 'test:shell', :RUBY_OPTS do |t, args| + files = Dir['test/**/test_*.rb'].join(' ') + + cmd = [Gem.ruby, args[:RUBY_OPTS], + '-I', 'lib', '-S', 'bacon', '--quiet', files] + + sh(cmd.compact.join(' ')) +end + +desc 'Generate ann markdown' +task 'ann:md' => ['gem:spec'] do + puts Gemgem.ann_md +end + +desc 'Generate ann html' +task 'ann:html' => ['gem:spec'] do + puts Gemgem.ann_html +end + +desc 'Generate ann email' +task 'ann:email' => ['gem:spec'] do + puts Gemgem.ann_email +end + desc 'Generate rdoc' task :doc => ['gem:spec'] do sh("yardoc -o rdoc --main README.md" \ " --files #{Gemgem.spec.extra_rdoc_files.join(',')}") end -desc 'Removed ignored files' +desc 'Remove ignored files' task :clean => ['gem:spec'] do trash = "~/.Trash/#{Gemgem.spec.name}/" sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash)) Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" } end