Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add generate any version ruby doc #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -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
51 changes: 51 additions & 0 deletions genAnyVerDoc.rb
Original file line number Diff line number Diff line change
@@ -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

10 changes: 9 additions & 1 deletion lib/pry-doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down