diff --git a/Rakefile b/Rakefile index 57ac1b6e..3107de76 100755 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,10 @@ direc = File.dirname(__FILE__) PROJECT_NAME = "pry-doc" -require 'latest_ruby' +begin + require 'latest_ruby' +rescue LoadError +end require 'rake/clean' require "#{direc}/lib/#{PROJECT_NAME}/version" @@ -90,6 +93,7 @@ def generate_docs_for(ruby_ver, latest_ruby) clean_up end +if defined? Latest desc "Generate the latest Ruby 1.9 docs" task "gen19" do generate_docs_for('19', Latest.ruby19) @@ -114,3 +118,9 @@ desc "Generate the latest Ruby 2.3 docs" task "gen23" do generate_docs_for('23', Latest.ruby23) end +end + +desc "Generate Any Version Ruby docs" +task "genAnyVerDoc" do + puts "run command:\n ruby genAnyVerDoc.rb VerNum /path/to/rubydev_dir" +end diff --git a/genAnyVerDoc.rb b/genAnyVerDoc.rb new file mode 100755 index 00000000..8ecc5399 --- /dev/null +++ b/genAnyVerDoc.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +require 'fileutils' + +def main + direc = File.absolute_path(File.dirname(__FILE__)) + print "\n\n" + + src_ver = ARGV.shift + src_path = ARGV.shift + force_yard = ARGV.delete('--force') + + if !src_ver || src_ver !~ /^\d\d$/ || (src_path=File.expand_path(src_path)) && !File.directory?(src_path) + STDERR.puts "syntax:\n ruby #{__FILE__} 24 /path/to/rubydev_dir [--force]" + return + end + puts "Source path:#{src_path} \nGenerate the Ruby #{src_ver} docs.." + + Dir.chdir(direc) + Dir.glob("lib/pry-doc/core_docs_??").each do |di| + system "git rm -r --cache #{di}" + end + docpath = "lib/pry-doc/core_docs_#{src_ver}" + + Dir.chdir(src_path) do + if File.directory?('.yardoc') && !force_yard + puts "Already has .yardoc directory, skip generate!" + else + FileUtils.rm_rf('.yardoc') + system %{ + bash -c "paste <(find . -maxdepth 1 -name '*.c') <(find ext -name '*.c') | + xargs yardoc --no-output" + } + end + FileUtils.rm_rf("#{direc}/#{docpath}") + FileUtils.cp_r(".yardoc", "#{direc}/#{docpath}") + end + system "git add #{docpath}" + + print "\n\ngem build *.gemspec\n" + system "gem build *.gemspec" + + print "\n\nls *.gem\n" + puts Dir.glob('*.gem') + puts 'end.' +end + +if __FILE__ == $0 + main +end + diff --git a/lib/pry-doc.rb b/lib/pry-doc.rb index 59e839cf..fceb48bb 100755 --- a/lib/pry-doc.rb +++ b/lib/pry-doc.rb @@ -10,6 +10,7 @@ module PryDoc def self.load_yardoc(version) path = "#{File.dirname(__FILE__)}/pry-doc/core_docs_#{ version }" + raise "no this pry-doc path" unless File.directory?(path) YARD::Registry.load_yardoc(path) end @@ -27,7 +28,14 @@ def self.load_yardoc(version) when /\A1.9/ PryDoc.load_yardoc('19') else - puts "Ruby #{RUBY_VERSION} isn't supported by this pry-doc version" + begin + RUBY_VERSION=~/\A(\d)\.(\d)/ + ver = "#{$1}#{$2}" + puts "Try load ruby #{ver} pry-doc.." + PryDoc.load_yardoc(ver) + rescue + puts "Ruby #{RUBY_VERSION} isn't supported by this pry-doc version" + end end class Pry