Permalink
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...
1 parent 4d9a87c commit ba1659279da2212b6ae05ad55c34b96c1538370c @drbrain drbrain committed Aug 9, 2012
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
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
##
@@ -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
@@ -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)
@@ -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,
@@ -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(/^\\/, '')
@@ -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}" \
@@ -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
##
@@ -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
@@ -8,6 +8,10 @@
class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
+ def initialize # :nodoc:
+ super nil
+ end
+
def start_accepting
end
@@ -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)
@@ -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
@@ -18,6 +18,10 @@ def self.to_toc
attr_reader :res
+ def initialize # :nodoc:
+ super nil
+ end
+
##
# Adds +heading+ to the table of contents
@@ -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
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
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",
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 = {
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
##
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:
@@ -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>'
@@ -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
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
@@ -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
Oops, something went wrong.

0 comments on commit ba16592

Please sign in to comment.