Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove global state from RDoc::RDoc

RDoc::RDoc.current has been removed.  All objects previously depending
on it now access options or other state through the store or its
attached RDoc::RDoc instance.

To support this change RDoc::Markup::Formatter and RDoc::Markup::ToHtml*
now require an RDoc::Options instance as their first argument.  Some
formatters do not require an RDoc::Options instance since accessing it
was difficult.

Additionally, ri no longer supports the -f html option.
  • Loading branch information...
commit ba1659279da2212b6ae05ad55c34b96c1538370c 1 parent 4d9a87c
Eric Hodel drbrain authored
Showing with 95 additions and 86 deletions.
  1. +18 −3 History.rdoc
  2. +1 −1  lib/rdoc/class_module.rb
  3. +3 −5 lib/rdoc/generator/markup.rb
  4. +3 −1 lib/rdoc/markup/formatter.rb
  5. +2 −0  lib/rdoc/markup/formatter_test_case.rb
  6. +1 −1  lib/rdoc/markup/heading.rb
  7. +2 −4 lib/rdoc/markup/to_html.rb
  8. +8 −9 lib/rdoc/markup/to_html_crossref.rb
  9. +2 −2 lib/rdoc/markup/to_html_snippet.rb
  10. +4 −0 lib/rdoc/markup/to_joined_paragraph.rb
  11. +1 −1  lib/rdoc/markup/to_label.rb
  12. +1 −1  lib/rdoc/markup/to_rdoc.rb
  13. +4 −0 lib/rdoc/markup/to_table_of_contents.rb
  14. +1 −1  lib/rdoc/markup/to_tt_only.rb
  15. +11 −11 lib/rdoc/rdoc.rb
  16. +1 −0  lib/rdoc/ri/driver.rb
  17. +7 −0 lib/rdoc/store.rb
  18. +4 −2 lib/rdoc/test_case.rb
  19. +1 −1  lib/rdoc/top_level.rb
  20. +3 −1 test/test_attribute_manager.rb
  21. +1 −3 test/test_rdoc_generator_markup.rb
  22. +1 −1  test/test_rdoc_markup.rb
  23. +1 −1  test/test_rdoc_markup_formatter.rb
  24. +1 −16 test/test_rdoc_markup_to_html.rb
  25. +5 −3 test/test_rdoc_markup_to_html_crossref.rb
  26. +5 −5 test/test_rdoc_markup_to_html_snippet.rb
  27. +0 −8 test/test_rdoc_rdoc.rb
  28. +0 −4 test/test_rdoc_ri_driver.rb
  29. +3 −1 test/test_rdoc_text.rb
21 History.rdoc
View
@@ -1,6 +1,9 @@
=== 4.0
* Breaking changes
+ * The default output encoding for RDoc is now UTF-8. Previously RDoc used
+ the default external encoding which was determined from your locale.
+ Issue #106 by Justin Baker.
* RDoc::RI::Store is now RDoc::Store so ri data generated by RDoc 4 cannot
be read by earlier versions of RDoc. RDoc::RI::Store exists as an alias
of RDoc::Store so ri data from older versions can still be read.
@@ -16,12 +19,24 @@
* RDoc generators must accept an RDoc::Store and an RDoc::Options in
initialize. RDoc no longer passes an Array of RDoc::TopLevel objects to
#generate. Use RDoc::Store#all_files instead.
- * The default output encoding for RDoc is now UTF-8. Previously RDoc used
- the default external encoding which was determined from your locale.
- Issue #106 by Justin Baker.
+ * Some markup formatters (RDoc::Markup::To*) now accept an RDoc::Options
+ instance as the first argument. Notably, the base class Formatter and
+ ToHtml*. (This is not universal due to the difficult at accessing the
+ user's options instance deep inside RDoc. A future major release may
+ remedy this.)
* Removed RDoc::RI::Paths::SYSDIR and ::SITEDIR. These were hidden
constants so no breakage is expected. Use RDoc::RI::Paths::system_dir
and ::site_dir instead.
+ * ri -f html is no longer supported.
+
+* Major enhancements
+ * Removed global state from RDoc. RDoc::Store holds the documentation tree
+ and connects the driver to the parsers and generator. This also allows
+ documentation parsing and generation for multiple instances (and in
+ multiple threads), but the rdoc command-line tool does not support this.
+
+ Due to this change RDoc::RDoc.current and RDoc::RDoc.reset no longer
+ exist.
* Minor enhancements
* Added Markdown as a supported format. The markdown format can be set on a
2  lib/rdoc/class_module.rb
View
@@ -504,7 +504,7 @@ def parse comment_location
# Path to this class or module
def path
- http_url RDoc::RDoc.current.generator.class_dir
+ http_url @store.rdoc.generator.class_dir
end
##
8 lib/rdoc/generator/markup.rb
View
@@ -33,12 +33,10 @@ def description
def formatter
return @formatter if defined? @formatter
- show_hash = RDoc::RDoc.current.options.show_hash
- hyperlink_all = RDoc::RDoc.current.options.hyperlink_all
+ options = @store.rdoc.options
this = RDoc::Context === self ? self : @parent
- @formatter = RDoc::Markup::ToHtmlCrossref.new(this.path, this, show_hash,
- hyperlink_all)
+ @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
@formatter.code_object = self
@formatter
end
@@ -158,7 +156,7 @@ class RDoc::TopLevel
# command line option to set.
def cvs_url
- url = RDoc::RDoc.current.options.webcvs
+ url = @store.rdoc.options.webcvs
if /%s/ =~ url then
url % @absolute_name
4 lib/rdoc/markup/formatter.rb
View
@@ -20,7 +20,9 @@ class RDoc::Markup::Formatter
##
# Creates a new Formatter
- def initialize markup = nil
+ def initialize options, markup = nil
+ @options = options
+
@markup = markup || RDoc::Markup.new
@am = @markup.attribute_manager
@am.add_special(/<br>/, :HARD_BREAK)
2  lib/rdoc/markup/formatter_test_case.rb
View
@@ -53,6 +53,8 @@ class RDoc::Markup::FormatterTestCase < RDoc::TestCase
def setup
super
+ @options = RDoc::Options.new
+
@m = @RM.new
@bullet_list = @RM::List.new(:BULLET,
2  lib/rdoc/markup/heading.rb
View
@@ -23,7 +23,7 @@ def self.to_html
markup = RDoc::Markup.new
markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
- @to_html = RDoc::Markup::ToHtml.new
+ @to_html = RDoc::Markup::ToHtml.new nil
def @to_html.handle_special_CROSSREF special
special.text.sub(/^\\/, '')
6 lib/rdoc/markup/to_html.rb
View
@@ -65,7 +65,7 @@ def self.gen_relative_url(path, target)
##
# Creates a new formatter that will output HTML
- def initialize markup = nil
+ def initialize options, markup = nil
super
@code_object = nil
@@ -207,10 +207,8 @@ def accept_verbatim verbatim
text = verbatim.text.rstrip
@res << if verbatim.ruby? or parseable? text then
- options = RDoc::RDoc.current.options if RDoc::RDoc.current
-
begin
- tokens = RDoc::RubyLex.tokenize text, options
+ tokens = RDoc::RubyLex.tokenize text, @options
"\n<pre class=\"ruby\">" \
"#{RDoc::TokenStream.to_html tokens}" \
17 lib/rdoc/markup/to_html_crossref.rb
View
@@ -28,21 +28,20 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# references are removed unless +show_hash+ is true. Only method names
# preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
- def initialize(from_path, context, show_hash, hyperlink_all = false,
- markup = nil)
+ def initialize(options, from_path, context, markup = nil)
raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
- super markup
- crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
+ super options, markup
- @cross_reference = RDoc::CrossReference.new context
+ @context = context
+ @from_path = from_path
+ @hyperlink_all = @options.hyperlink_all
+ @show_hash = @options.show_hash
+ crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
@markup.add_special crossref_re, :CROSSREF
- @context = context
- @from_path = from_path
- @hyperlink_all = hyperlink_all
- @show_hash = show_hash
+ @cross_reference = RDoc::CrossReference.new @context
end
##
4 lib/rdoc/markup/to_html_snippet.rb
View
@@ -33,8 +33,8 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
# next word boundary after the given number of +characters+ or +paragraphs+
# of text have been encountered.
- def initialize characters = 100, paragraphs = 3, markup = nil
- super markup
+ def initialize options, characters = 100, paragraphs = 3, markup = nil
+ super options, markup
@character_limit = characters
@paragraph_limit = paragraphs
4 lib/rdoc/markup/to_joined_paragraph.rb
View
@@ -8,6 +8,10 @@
class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
+ def initialize # :nodoc:
+ super nil
+ end
+
def start_accepting
end
2  lib/rdoc/markup/to_label.rb
View
@@ -11,7 +11,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
# Creates a new formatter that will output HTML-safe labels
def initialize markup = nil
- super
+ super nil, markup
@markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
2  lib/rdoc/markup/to_rdoc.rb
View
@@ -42,7 +42,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
# Creates a new formatter that will output (mostly) \RDoc markup
def initialize markup = nil
- super
+ super nil, markup
@markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF)
@width = 78
4 lib/rdoc/markup/to_table_of_contents.rb
View
@@ -18,6 +18,10 @@ def self.to_toc
attr_reader :res
+ def initialize # :nodoc:
+ super nil
+ end
+
##
# Adds +heading+ to the table of contents
2  lib/rdoc/markup/to_tt_only.rb
View
@@ -18,7 +18,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
# Creates a new tt-only formatter.
def initialize markup = nil
- super
+ super nil, markup
add_tag :TT, nil, nil
end
22 lib/rdoc/rdoc.rb
View
@@ -61,7 +61,7 @@ class RDoc::RDoc
##
# The current documentation store
- attr_accessor :store
+ attr_reader :store
##
# Add +klass+ that can generate output after parsing
@@ -86,13 +86,6 @@ def self.current= rdoc
end
##
- # Resets all internal state
-
- def self.reset
- RDoc::RDoc.current = nil
- end
-
- ##
# Creates a new RDoc::RDoc instance. Call #document to parse files and
# generate documentation.
@@ -132,7 +125,7 @@ def gather_files files
# Turns RDoc from stdin into HTML
def handle_pipe
- @html = RDoc::Markup::ToHtml.new
+ @html = RDoc::Markup::ToHtml.new @options
parser = RDoc::Text::MARKUP_FORMAT[@options.markup]
@@ -228,6 +221,15 @@ def setup_output_dir(dir, force)
end
##
+ # Sets the current documentation tree to +store+ and sets the store's rdoc
+ # driver to this instance.
+
+ def store= store
+ @store = store
+ @store.rdoc = self
+ end
+
+ ##
# Update the flag file in an output directory.
def update_output_dir(op_dir, time, last = {})
@@ -431,8 +433,6 @@ def remove_unparseable files
def document options
@store = RDoc::Store.new
- RDoc::RDoc.current = self
-
if RDoc::Options === options then
@options = options
@options.finish
1  lib/rdoc/ri/driver.rb
View
@@ -159,6 +159,7 @@ def self.process_args argv
formatters = formatters.sort.map do |formatter|
formatter.to_s.sub('To', '').downcase
end
+ formatters -= %w[html label test] # remove useless output formats
opt.on("--format=NAME", "-f",
"Uses the selected formatter. The default",
7 lib/rdoc/store.rb
View
@@ -39,6 +39,12 @@ class RDoc::Store
attr_accessor :path
##
+ # The RDoc::RDoc driver for this parse tree. This allows classes consulting
+ # the documentation tree to access user-set options, for example.
+
+ attr_accessor :rdoc
+
+ ##
# Type of ri datastore this was loaded from. See RDoc::RI::Driver,
# RDoc::RI::Paths.
@@ -61,6 +67,7 @@ def initialize path = nil, type = nil
@dry_run = false
@type = type
@path = path
+ @rdoc = nil
@encoding = nil
@cache = {
6 lib/rdoc/test_case.rb
View
@@ -35,7 +35,6 @@ def setup
@RM = RDoc::Markup
- RDoc::RDoc.reset
RDoc::Markup::PreProcess.reset
@pwd = Dir.pwd
@@ -45,7 +44,10 @@ def setup
@rdoc = RDoc::RDoc.new
@rdoc.store = @store
- RDoc::RDoc.current = @rdoc
+ g = Object.new
+ def g.class_dir() end
+ def g.file_dir() end
+ @rdoc.generator = g
end
##
2  lib/rdoc/top_level.rb
View
@@ -208,7 +208,7 @@ def page_name
# Path to this file
def path
- http_url RDoc::RDoc.current.generator.file_dir
+ http_url @store.rdoc.generator.file_dir
end
def pretty_print q # :nodoc:
4 test/test_attribute_manager.rb
View
@@ -5,9 +5,11 @@ class TestAttributeManager < RDoc::TestCase # HACK fix test name
def setup
super
+ @options = RDoc::Options.new
+
@am = RDoc::Markup::AttributeManager.new
@klass = RDoc::Markup::AttributeManager
- @formatter = RDoc::Markup::Formatter.new
+ @formatter = RDoc::Markup::Formatter.new @options
@formatter.add_tag :BOLD, '<B>', '</B>'
@formatter.add_tag :EM, '<EM>', '</EM>'
@formatter.add_tag :TT, '<CODE>', '</CODE>'
4 test/test_rdoc_generator_markup.rb
View
@@ -11,13 +11,11 @@ def setup
super
@options = RDoc::Options.new
- @rdoc = RDoc::RDoc.new
@rdoc.options = @options
+
@parent = self
@path = '/index.html'
@symbols = {}
-
- RDoc::RDoc.current = @rdoc
end
def test_aref_to
2  test/test_rdoc_markup.rb
View
@@ -48,7 +48,7 @@ def test_convert_custom_markup
m = RDoc::Markup.new
m.add_word_pair '{', '}', :STRIKE
- tt = RDoc::Markup::ToTest.new m
+ tt = RDoc::Markup::ToTest.new nil, m
tt.add_tag :STRIKE, 'STRIKE ', ' STRIKE'
out = m.convert str, tt
2  test/test_rdoc_markup_formatter.rb
View
@@ -5,7 +5,7 @@ class TestRDocMarkupFormatter < RDoc::TestCase
class ToTest < RDoc::Markup::Formatter
def initialize markup
- super
+ super nil, markup
add_tag :TT, '<code>', '</code>'
end
17 test/test_rdoc_markup_to_html.rb
View
@@ -7,7 +7,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
def setup
super
- @to = RDoc::Markup::ToHtml.new
+ @to = RDoc::Markup::ToHtml.new @options
end
def test_class_gen_relative_url
@@ -353,11 +353,6 @@ def test_accept_heading_aref_method
end
def test_accept_verbatim_parseable
- options = RDoc::Options.new
- rdoc = RDoc::RDoc.new
- rdoc.options = options
- RDoc::RDoc.current = rdoc
-
verb = @RM::Verbatim.new("class C\n", "end\n")
@to.start_accepting
@@ -374,11 +369,6 @@ def test_accept_verbatim_parseable
end
def test_accept_verbatim_parseable_error
- options = RDoc::Options.new
- rdoc = RDoc::RDoc.new
- rdoc.options = options
- RDoc::RDoc.current = rdoc
-
verb = @RM::Verbatim.new("a %z'foo' # => blah\n")
@to.start_accepting
@@ -396,11 +386,6 @@ def test_accept_verbatim_parseable_error
end
def test_accept_verbatim_ruby
- options = RDoc::Options.new
- rdoc = RDoc::RDoc.new
- rdoc.options = options
- RDoc::RDoc.current = rdoc
-
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
8 test/test_rdoc_markup_to_html_crossref.rb
View
@@ -5,7 +5,9 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
def setup
super
- @to = RDoc::Markup::ToHtmlCrossref.new 'index.html', @c1, true
+ @options.hyperlink_all = true
+
+ @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
end
def test_convert_CROSSREF
@@ -120,7 +122,7 @@ def test_handle_special_HYPERLINK_rdoc
readme = @store.add_file 'README.txt'
readme.parser = RDoc::Parser::Simple
- @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2, true
+ @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
link = @to.handle_special_HYPERLINK hyper 'C2::C3'
@@ -139,7 +141,7 @@ def test_handle_special_TIDYLINK_rdoc
readme = @store.add_file 'README.txt'
readme.parser = RDoc::Parser::Simple
- @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2, true
+ @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
link = @to.handle_special_TIDYLINK tidy 'C2::C3'
10 test/test_rdoc_markup_to_html_snippet.rb
View
@@ -7,7 +7,7 @@ class TestRDocMarkupToHtmlSnippet < RDoc::Markup::FormatterTestCase
def setup
super
- @to = RDoc::Markup::ToHtmlSnippet.new 100, 100
+ @to = RDoc::Markup::ToHtmlSnippet.new @options, 100, 100
@ellipsis = @to.to_html '...'
end
@@ -424,7 +424,7 @@ def test_accept_verbatim_ruby_error
end
def test_add_paragraph
- @to = RDoc::Markup::ToHtmlSnippet.new 0, 3
+ @to = RDoc::Markup::ToHtmlSnippet.new @options, 0, 3
assert_throws :done do
@to.add_paragraph
@to.add_paragraph
@@ -477,7 +477,7 @@ def test_convert_limit_2
end
def test_convert_limit_paragraphs
- @to = RDoc::Markup::ToHtmlSnippet.new 100, 3
+ @to = RDoc::Markup::ToHtmlSnippet.new @options, 100, 3
rdoc = <<-RDOC
= \RDoc - Ruby Documentation System
@@ -508,7 +508,7 @@ def test_convert_limit_paragraphs
end
def test_convert_limit_in_tag
- @to = RDoc::Markup::ToHtmlSnippet.new 4
+ @to = RDoc::Markup::ToHtmlSnippet.new @options, 4
rdoc = "* ab *c* d\n"
expected = "<p>ab <strong>c</strong> #{@ellipsis}\n\n"
@@ -587,7 +587,7 @@ def test_convert_limit_verbatim_multiline
end
def test_convert_limit_over
- @to = RDoc::Markup::ToHtmlSnippet.new 4
+ @to = RDoc::Markup::ToHtmlSnippet.new @options, 4
rdoc = "* text\n" * 2
expected = "<p>text\n"
8 test/test_rdoc_rdoc.rb
View
@@ -12,14 +12,6 @@ def setup
@rdoc.instance_variable_set :@stats, @stats
end
- def test_class_reset
- RDoc::RDoc.current = :junk
-
- RDoc::RDoc.reset
-
- assert_nil RDoc::RDoc.current
- end
-
def test_document # functional test
options = RDoc::Options.new
options.files = [File.expand_path('../xref_data.rb')]
4 test/test_rdoc_ri_driver.rb
View
@@ -646,10 +646,6 @@ def tty.tty?() true; end
driver.instance_variable_set :@paging, true
assert_instance_of @RM::ToBs, driver.formatter(StringIO.new)
-
- driver.instance_variable_set :@formatter_klass, @RM::ToHtml
-
- assert_instance_of @RM::ToHtml, driver.formatter(tty)
end
def test_in_path_eh
4 test/test_rdoc_text.rb
View
@@ -9,6 +9,8 @@ class TestRDocText < RDoc::TestCase
def setup
super
+ @options = RDoc::Options.new
+
@top_level = @store.add_file 'file.rb'
end
@@ -559,7 +561,7 @@ def test_to_html_tt_tag_mismatch
end
def formatter()
- RDoc::Markup::ToHtml.new
+ RDoc::Markup::ToHtml.new @options
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.