Skip to content

Commit

Permalink
Move Servlet under RDoc::RI
Browse files Browse the repository at this point in the history
This class is used as a server for the ri command, not as a rdoc server.
So putting it under RDoc::RI will make its purpose clearer.
  • Loading branch information
st0012 committed Aug 22, 2024
1 parent 5749b22 commit cd50972
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ group :development do
gem 'rubocop', '>= 1.31.0'
gem 'gettext'
gem 'prism', '>= 0.30.0'
gem 'webrick'
end
1 change: 0 additions & 1 deletion lib/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def self.home
autoload :Generator, "#{__dir__}/rdoc/generator"
autoload :Options, "#{__dir__}/rdoc/options"
autoload :Parser, "#{__dir__}/rdoc/parser"
autoload :Servlet, "#{__dir__}/rdoc/servlet"
autoload :RI, "#{__dir__}/rdoc/ri"
autoload :Stats, "#{__dir__}/rdoc/stats"
autoload :Store, "#{__dir__}/rdoc/store"
Expand Down
7 changes: 4 additions & 3 deletions lib/rdoc/ri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ module RDoc::RI

class Error < RDoc::Error; end

autoload :Driver, "#{__dir__}/ri/driver"
autoload :Paths, "#{__dir__}/ri/paths"
autoload :Store, "#{__dir__}/ri/store"
autoload :Driver, "#{__dir__}/ri/driver"
autoload :Paths, "#{__dir__}/ri/paths"
autoload :Store, "#{__dir__}/ri/store"
autoload :Servlet, "#{__dir__}/ri/servlet"

end
2 changes: 1 addition & 1 deletion lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def start_server

extra_doc_dirs = @stores.map {|s| s.type == :extra ? s.path : nil}.compact

server.mount '/', RDoc::Servlet, nil, extra_doc_dirs
server.mount '/', RDoc::RI::Servlet, nil, extra_doc_dirs

trap 'INT' do server.shutdown end
trap 'TERM' do server.shutdown end
Expand Down
10 changes: 5 additions & 5 deletions lib/rdoc/servlet.rb → lib/rdoc/ri/servlet.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require_relative '../rdoc'
require_relative '../../rdoc'
require 'erb'
require 'time'
require 'json'
Expand All @@ -24,14 +24,14 @@
#
# server = WEBrick::HTTPServer.new Port: 8000
#
# server.mount '/', RDoc::Servlet
# server.mount '/', RDoc::RI::Servlet
#
# If you want to mount the servlet some other place than the root, provide the
# base path when mounting:
#
# server.mount '/rdoc', RDoc::Servlet, '/rdoc'
# server.mount '/rdoc', RDoc::RI::Servlet, '/rdoc'

class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
class RDoc::RI::Servlet < WEBrick::HTTPServlet::AbstractServlet

@server_stores = Hash.new { |hash, server| hash[server] = {} }
@cache = Hash.new { |hash, store| hash[store] = {} }
Expand Down Expand Up @@ -146,7 +146,7 @@ def do_GET req, res
# Fills in +res+ with the class, module or page for +req+ from +store+.
#
# +path+ is relative to the mount_path and is used to determine the class,
# module or page name (/RDoc/Servlet.html becomes RDoc::Servlet).
# module or page name (/RDoc/RI.html becomes RDoc::RI).
# +generator+ is used to create the page.

def documentation_page store, generator, path, req, res
Expand Down
2 changes: 1 addition & 1 deletion rdoc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
"lib/rdoc/ri/paths.rb",
"lib/rdoc/ri/store.rb",
"lib/rdoc/ri/task.rb",
"lib/rdoc/ri/servlet.rb",
"lib/rdoc/rubygems_hook.rb",
"lib/rdoc/servlet.rb",
"lib/rdoc/single_class.rb",
"lib/rdoc/stats.rb",
"lib/rdoc/stats/normal.rb",
Expand Down
4 changes: 2 additions & 2 deletions test/rdoc/test_rdoc_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def @server.mount(*) end

@extra_dirs = [File.join(@tempdir, 'extra1'), File.join(@tempdir, 'extra2')]

@s = RDoc::Servlet.new @server, @stores, @cache, nil, @extra_dirs
@s = RDoc::RI::Servlet.new @server, @stores, @cache, nil, @extra_dirs

@req = WEBrick::HTTPRequest.new :Logger => nil
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
Expand Down Expand Up @@ -141,7 +141,7 @@ def @req.path() raise 'no' end
end

def test_do_GET_mount_path
@s = RDoc::Servlet.new @server, @stores, @cache, '/mount/path'
@s = RDoc::RI::Servlet.new @server, @stores, @cache, '/mount/path'

temp_dir do
FileUtils.mkdir 'css'
Expand Down

0 comments on commit cd50972

Please sign in to comment.