aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 01:41:25 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 01:41:25 +0000
commitd42d6e690e3f553b971322eae783ac6b0d4d9692 (patch)
tree2004bf4517ee7b81466c300cf30092e62e65467e /lib/rdoc
parent670c6e8ce9d4a12bb4832e10fab27365398649bf (diff)
downloadruby-d42d6e690e3f553b971322eae783ac6b0d4d9692.tar.gz
* lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(313287)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/any_method.rb10
-rw-r--r--lib/rdoc/context.rb11
-rw-r--r--lib/rdoc/encoding.rb4
-rw-r--r--lib/rdoc/generator.rb1
-rw-r--r--lib/rdoc/generator/pot.rb97
-rw-r--r--lib/rdoc/generator/pot/message_extractor.rb67
-rw-r--r--lib/rdoc/generator/pot/po.rb84
-rw-r--r--lib/rdoc/generator/pot/po_entry.rb140
-rw-r--r--lib/rdoc/generator/template/darkfish/_head.rhtml17
-rw-r--r--[-rwxr-xr-x]lib/rdoc/generator/template/darkfish/images/add.pngbin733 -> 733 bytes
-rw-r--r--[-rwxr-xr-x]lib/rdoc/generator/template/darkfish/images/arrow_up.pngbin372 -> 372 bytes
-rw-r--r--[-rwxr-xr-x]lib/rdoc/generator/template/darkfish/images/delete.pngbin715 -> 715 bytes
-rw-r--r--[-rwxr-xr-x]lib/rdoc/generator/template/darkfish/images/tag_blue.pngbin1880 -> 1880 bytes
-rw-r--r--lib/rdoc/generator/template/darkfish/js/darkfish.js43
-rw-r--r--lib/rdoc/generator/template/darkfish/rdoc.css12
-rw-r--r--lib/rdoc/i18n.rb9
-rw-r--r--lib/rdoc/i18n/locale.rb101
-rw-r--r--lib/rdoc/i18n/text.rb125
-rw-r--r--lib/rdoc/markup.rb4
-rw-r--r--lib/rdoc/method_attr.rb3
-rw-r--r--lib/rdoc/options.rb58
-rw-r--r--lib/rdoc/parser.rb2
-rw-r--r--lib/rdoc/parser/c.rb10
-rw-r--r--lib/rdoc/parser/changelog.rb4
-rw-r--r--lib/rdoc/parser/ruby.rb24
-rw-r--r--lib/rdoc/rd/block_parser.rb2
-rw-r--r--lib/rdoc/rd/inline_parser.rb2
-rw-r--r--lib/rdoc/rdoc.rb8
-rw-r--r--lib/rdoc/ruby_lex.rb2
-rw-r--r--lib/rdoc/ruby_token.rb8
-rw-r--r--lib/rdoc/rubygems_hook.rb8
-rw-r--r--lib/rdoc/stats/normal.rb11
-rw-r--r--lib/rdoc/task.rb2
-rw-r--r--lib/rdoc/text.rb9
34 files changed, 811 insertions, 67 deletions
diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb
index 3afafc86b8..ae022d72f8 100644
--- a/lib/rdoc/any_method.rb
+++ b/lib/rdoc/any_method.rb
@@ -240,7 +240,15 @@ class RDoc::AnyMethod < RDoc::MethodAttr
return []
end
- params = params.gsub(/\s+/, '').split ','
+ if @block_params then
+ # If this method has explicit block parameters, remove any explicit
+ # &block
+ params.sub!(/,?\s*&\w+/, '')
+ else
+ params.sub!(/\&(\w+)/, '\1')
+ end
+
+ params = params.gsub(/\s+/, '').split(',').reject(&:empty?)
params.map { |param| param.sub(/=.*/, '') }
end
diff --git a/lib/rdoc/context.rb b/lib/rdoc/context.rb
index 892a43e118..5eb86ddc92 100644
--- a/lib/rdoc/context.rb
+++ b/lib/rdoc/context.rb
@@ -164,6 +164,8 @@ class RDoc::Context < RDoc::CodeObject
# Contexts are sorted by full_name
def <=>(other)
+ return nil unless RDoc::CodeObject === other
+
full_name <=> other.full_name
end
@@ -321,10 +323,11 @@ class RDoc::Context < RDoc::CodeObject
end
# fix up superclass
- superclass = nil if full_name == 'BasicObject'
- superclass = nil if full_name == 'Object' and defined?(::BasicObject)
- superclass = '::BasicObject' if
- defined?(::BasicObject) and full_name == 'Object'
+ if full_name == 'BasicObject' then
+ superclass = nil
+ elsif full_name == 'Object' then
+ superclass = defined?(::BasicObject) ? '::BasicObject' : nil
+ end
# find the superclass full name
if superclass then
diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb
index 9fe3539412..b3515a435f 100644
--- a/lib/rdoc/encoding.rb
+++ b/lib/rdoc/encoding.rb
@@ -29,7 +29,9 @@ module RDoc::Encoding
encoding ||= Encoding.default_external
orig_encoding = content.encoding
- if utf8 then
+ if not orig_encoding.ascii_compatible? then
+ content.encode! encoding
+ elsif utf8 then
content.force_encoding Encoding::UTF_8
content.encode! encoding
else
diff --git a/lib/rdoc/generator.rb b/lib/rdoc/generator.rb
index 9051f8a658..7d3989d42f 100644
--- a/lib/rdoc/generator.rb
+++ b/lib/rdoc/generator.rb
@@ -45,6 +45,7 @@ module RDoc::Generator
autoload :Darkfish, 'rdoc/generator/darkfish'
autoload :JsonIndex, 'rdoc/generator/json_index'
autoload :RI, 'rdoc/generator/ri'
+ autoload :POT, 'rdoc/generator/pot'
end
diff --git a/lib/rdoc/generator/pot.rb b/lib/rdoc/generator/pot.rb
new file mode 100644
index 0000000000..db6f3a0354
--- /dev/null
+++ b/lib/rdoc/generator/pot.rb
@@ -0,0 +1,97 @@
+##
+# Generates a POT file.
+#
+# Here is a translator work flow with the generator.
+#
+# == Create .pot
+#
+# You create .pot file by pot formatter:
+#
+# % rdoc --format pot
+#
+# It generates doc/rdoc.pot.
+#
+# == Create .po
+#
+# You create .po file from doc/rdoc.pot. This operation is needed only
+# the first time. This work flow assumes that you are a translator
+# for Japanese.
+#
+# You create locale/ja/rdoc.po from doc/rdoc.pot. You can use msginit
+# provided by GNU gettext or rmsginit provided by gettext gem. This
+# work flow uses gettext gem because it is more portable than GNU
+# gettext for Rubyists. Gettext gem is implemented by pure Ruby.
+#
+# % gem install gettext
+# % mkdir -p locale/ja
+# % rmsginit --input doc/rdoc.pot --output locale/ja/rdoc.po --locale ja
+#
+# Translate messages in .po
+#
+# You translate messages in .po by a PO file editor. po-mode.el exists
+# for Emacs users. There are some GUI tools such as GTranslator.
+# There are some Web services such as POEditor and Tansifex. You can
+# edit by your favorite text editor because .po is a text file.
+# Generate localized documentation
+#
+# You can generate localized documentation with locale/ja/rdoc.po:
+#
+# % rdoc --locale ja
+#
+# You can find documentation in Japanese in doc/. Yay!
+#
+# == Update translation
+#
+# You need to update translation when your application is added or
+# modified messages.
+#
+# You can update .po by the following command lines:
+#
+# % rdoc --format pot
+# % rmsgmerge --update locale/ja/rdoc.po doc/rdoc.pot
+#
+# You edit locale/ja/rdoc.po to translate new messages.
+
+class RDoc::Generator::POT
+
+ RDoc::RDoc.add_generator self
+
+ ##
+ # Description of this generator
+
+ DESCRIPTION = 'creates .pot file'
+
+ ##
+ # Set up a new .pot generator
+
+ def initialize store, options #:not-new:
+ @options = options
+ @store = store
+ end
+
+ ##
+ # Writes .pot to disk.
+
+ def generate
+ po = extract_messages
+ pot_path = 'rdoc.pot'
+ File.open(pot_path, "w") do |pot|
+ pot.print(po.to_s)
+ end
+ end
+
+ def class_dir
+ nil
+ end
+
+ private
+ def extract_messages
+ extractor = MessageExtractor.new(@store)
+ extractor.extract
+ end
+
+ autoload :MessageExtractor, 'rdoc/generator/pot/message_extractor'
+ autoload :PO, 'rdoc/generator/pot/po'
+ autoload :POEntry, 'rdoc/generator/pot/po_entry'
+
+end
diff --git a/lib/rdoc/generator/pot/message_extractor.rb b/lib/rdoc/generator/pot/message_extractor.rb
new file mode 100644
index 0000000000..ceabc5262a
--- /dev/null
+++ b/lib/rdoc/generator/pot/message_extractor.rb
@@ -0,0 +1,67 @@
+##
+# Extracts message from RDoc::Store
+
+class RDoc::Generator::POT::MessageExtractor
+
+ ##
+ # Creates a message extractor for +store+.
+
+ def initialize store
+ @store = store
+ @po = RDoc::Generator::POT::PO.new
+ end
+
+ ##
+ # Extracts messages from +store+, stores them into
+ # RDoc::Generator::POT::PO and returns it.
+
+ def extract
+ @store.all_classes_and_modules.each do |klass|
+ extract_from_klass(klass)
+ end
+ @po
+ end
+
+ private
+
+ def extract_from_klass klass
+ extract_text(klass.comment_location, klass.full_name)
+
+ klass.each_section do |section, constants, attributes|
+ extract_text(section.title ,"#{klass.full_name}: section title")
+ section.comments.each do |comment|
+ extract_text(comment, "#{klass.full_name}: #{section.title}")
+ end
+ end
+
+ klass.each_constant do |constant|
+ extract_text(constant.comment, constant.full_name)
+ end
+
+ klass.each_attribute do |attribute|
+ extract_text(attribute.comment, attribute.full_name)
+ end
+
+ klass.each_method do |method|
+ extract_text(method.comment, method.full_name)
+ end
+ end
+
+ def extract_text text, comment, location = nil
+ return if text.nil?
+
+ options = {
+ :extracted_comment => comment,
+ :references => [location].compact,
+ }
+ i18n_text = RDoc::I18n::Text.new(text)
+ i18n_text.extract_messages do |part|
+ @po.add(entry(part[:paragraph], options))
+ end
+ end
+
+ def entry msgid, options
+ RDoc::Generator::POT::POEntry.new(msgid, options)
+ end
+
+end
diff --git a/lib/rdoc/generator/pot/po.rb b/lib/rdoc/generator/pot/po.rb
new file mode 100644
index 0000000000..0d45c57dc1
--- /dev/null
+++ b/lib/rdoc/generator/pot/po.rb
@@ -0,0 +1,84 @@
+##
+# Generates a PO format text
+
+class RDoc::Generator::POT::PO
+
+ ##
+ # Creates an object that represents PO format.
+
+ def initialize
+ @entries = {}
+ add_header
+ end
+
+ ##
+ # Adds a PO entry to the PO.
+
+ def add entry
+ existing_entry = @entries[entry.msgid]
+ if existing_entry
+ entry = existing_entry.merge(entry)
+ end
+ @entries[entry.msgid] = entry
+ end
+
+ ##
+ # Returns PO format text for the PO.
+
+ def to_s
+ po = ''
+ sort_entries.each do |entry|
+ po << "\n" unless po.empty?
+ po << entry.to_s
+ end
+ po
+ end
+
+ private
+
+ def add_header
+ add(header_entry)
+ end
+
+ def header_entry
+ comment = <<-COMMENT
+SOME DESCRIPTIVE TITLE.
+Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+This file is distributed under the same license as the PACKAGE package.
+FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+
+ COMMENT
+
+ content = <<-CONTENT
+Project-Id-Version: PACKAGE VERSEION
+Report-Msgid-Bugs-To:
+PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE
+Last-Translator: FULL NAME <EMAIL@ADDRESS>
+Language-Team: LANGUAGE <LL@li.org>
+Language:
+MIME-Version: 1.0
+Content-Type: text/plain; charset=CHARSET
+Content-Transfer-Encoding: 8bit
+Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
+ CONTENT
+
+ options = {
+ :msgstr => content,
+ :translator_comment => comment,
+ :flags => ['fuzzy'],
+ }
+ RDoc::Generator::POT::POEntry.new('', options)
+ end
+
+ def sort_entries
+ headers, messages = @entries.values.partition do |entry|
+ entry.msgid.empty?
+ end
+ # TODO: sort by location
+ sorted_messages = messages.sort_by do |entry|
+ entry.msgid
+ end
+ headers + sorted_messages
+ end
+
+end
diff --git a/lib/rdoc/generator/pot/po_entry.rb b/lib/rdoc/generator/pot/po_entry.rb
new file mode 100644
index 0000000000..d4cef59ee9
--- /dev/null
+++ b/lib/rdoc/generator/pot/po_entry.rb
@@ -0,0 +1,140 @@
+##
+# A PO entry in PO
+
+class RDoc::Generator::POT::POEntry
+
+ # The msgid content
+ attr_reader :msgid
+
+ # The msgstr content
+ attr_reader :msgstr
+
+ # The comment content created by translator (PO editor)
+ attr_reader :translator_comment
+
+ # The comment content extracted from source file
+ attr_reader :extracted_comment
+
+ # The locations where the PO entry is extracted
+ attr_reader :references
+
+ # The flags of the PO entry
+ attr_reader :flags
+
+ ##
+ # Creates a PO entry for +msgid+. Other valus can be specified by
+ # +options+.
+
+ def initialize msgid, options = {}
+ @msgid = msgid
+ @msgstr = options[:msgstr] || ""
+ @translator_comment = options[:translator_comment]
+ @extracted_comment = options[:extracted_comment]
+ @references = options[:references] || []
+ @flags = options[:flags] || []
+ end
+
+ ##
+ # Returns the PO entry in PO format.
+
+ def to_s
+ entry = ''
+ entry << format_translator_comment
+ entry << format_extracted_comment
+ entry << format_references
+ entry << format_flags
+ entry << <<-ENTRY
+msgid #{format_message(@msgid)}
+msgstr #{format_message(@msgstr)}
+ ENTRY
+ end
+
+ ##
+ # Merges the PO entry with +other_entry+.
+
+ def merge other_entry
+ options = {
+ :extracted_comment => merge_string(@extracted_comment,
+ other_entry.extracted_comment),
+ :translator_comment => merge_string(@translator_comment,
+ other_entry.translator_comment),
+ :references => merge_array(@references,
+ other_entry.references),
+ :flags => merge_array(@flags,
+ other_entry.flags),
+ }
+ self.class.new(@msgid, options)
+ end
+
+ private
+
+ def format_comment mark, comment
+ return '' unless comment
+ return '' if comment.empty?
+
+ formatted_comment = ''
+ comment.each_line do |line|
+ formatted_comment << "#{mark} #{line}"
+ end
+ formatted_comment << "\n" unless formatted_comment.end_with?("\n")
+ formatted_comment
+ end
+
+ def format_translator_comment
+ format_comment('#', @translator_comment)
+ end
+
+ def format_extracted_comment
+ format_comment('#.', @extracted_comment)
+ end
+
+ def format_references
+ return '' if @references.empty?
+
+ formatted_references = ''
+ @references.sort.each do |file, line|
+ formatted_references << "\#: #{file}:#{line}\n"
+ end
+ formatted_references
+ end
+
+ def format_flags
+ return '' if @flags.empty?
+
+ formatted_flags = flags.join(",")
+ "\#, #{formatted_flags}\n"
+ end
+
+ def format_message message
+ return "\"#{escape(message)}\"" unless message.include?("\n")
+
+ formatted_message = '""'
+ message.each_line do |line|
+ formatted_message << "\n"
+ formatted_message << "\"#{escape(line)}\""
+ end
+ formatted_message
+ end
+
+ def escape string
+ string.gsub(/["\\\t\n]/) do |special_character|
+ case special_character
+ when "\t"
+ "\\t"
+ when "\n"
+ "\\n"
+ else
+ "\\#{special_character}"
+ end
+ end
+ end
+
+ def merge_string string1, string2
+ [string1, string2].compact.join("\n")
+ end
+
+ def merge_array array1, array2
+ (array1 + array2).uniq
+ end
+
+end
diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml
index 062160a751..c87ba95096 100644
--- a/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_head.rhtml
@@ -2,6 +2,13 @@
<title><%= h @title %></title>
+<script type="text/javascript">
+ var rdoc_rel_prefix = "<%= rel_prefix %>/";
+</script>
+
+<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
+<script src="<%= asset_rel_prefix %>/js/darkfish.js"></script>
+
<link href="<%= asset_rel_prefix %>/fonts.css" rel="stylesheet">
<link href="<%= asset_rel_prefix %>/rdoc.css" rel="stylesheet">
<% if @options.template_stylesheets.flatten.any? then %>
@@ -10,13 +17,3 @@
<% end %>
<% end %>
-<script type="text/javascript">
- var rdoc_rel_prefix = "<%= rel_prefix %>/";
-</script>
-
-<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
-<script src="<%= asset_rel_prefix %>/js/navigation.js"></script>
-<script src="<%= search_index_rel_prefix %>/js/search_index.js"></script>
-<script src="<%= asset_rel_prefix %>/js/search.js"></script>
-<script src="<%= asset_rel_prefix %>/js/searcher.js"></script>
-<script src="<%= asset_rel_prefix %>/js/darkfish.js"></script>
diff --git a/lib/rdoc/generator/template/darkfish/images/add.png b/lib/rdoc/generator/template/darkfish/images/add.png
index 6332fefea4..6332fefea4 100755..100644
--- a/lib/rdoc/generator/template/darkfish/images/add.png
+++ b/lib/rdoc/generator/template/darkfish/images/add.png
Binary files differ
diff --git a/lib/rdoc/generator/template/darkfish/images/arrow_up.png b/lib/rdoc/generator/template/darkfish/images/arrow_up.png
index 1ebb193243..1ebb193243 100755..100644
--- a/lib/rdoc/generator/template/darkfish/images/arrow_up.png
+++ b/lib/rdoc/generator/template/darkfish/images/arrow_up.png
Binary files differ
diff --git a/lib/rdoc/generator/template/darkfish/images/delete.png b/lib/rdoc/generator/template/darkfish/images/delete.png
index 08f249365a..08f249365a 100755..100644
--- a/lib/rdoc/generator/template/darkfish/images/delete.png
+++ b/lib/rdoc/generator/template/darkfish/images/delete.png
Binary files differ
diff --git a/lib/rdoc/generator/template/darkfish/images/tag_blue.png b/lib/rdoc/generator/template/darkfish/images/tag_blue.png
index 3f02b5f8f8..3f02b5f8f8 100755..100644
--- a/lib/rdoc/generator/template/darkfish/images/tag_blue.png
+++ b/lib/rdoc/generator/template/darkfish/images/tag_blue.png
Binary files differ
diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js
index 06fef3b215..b789a65631 100644
--- a/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js
@@ -44,14 +44,6 @@ function hookSourceViews() {
$('.method-heading').click( showSource );
};
-function toggleDebuggingSection() {
- $('.debugging-section').slideToggle();
-};
-
-function hookDebuggingToggle() {
- $('#debugging-toggle img').click( toggleDebuggingSection );
-};
-
function hookSearch() {
var input = $('#search-field').eq(0);
var result = $('#search-results').eq(0);
@@ -129,12 +121,41 @@ function highlightClickTarget( event ) {
};
};
+function loadAsync(path, success) {
+ $.ajax({
+ url: rdoc_rel_prefix + path,
+ dataType: 'script',
+ success: success,
+ cache: true
+ });
+};
$(document).ready( function() {
hookSourceViews();
- hookDebuggingToggle();
- hookSearch();
highlightLocationTarget();
-
$('ul.link-list a').bind( "click", highlightClickTarget );
+
+ var search_scripts_loaded = {
+ navigation_loaded: false,
+ search_loaded: false,
+ search_index_loaded: false,
+ searcher_loaded: false,
+ }
+
+ var search_success_function = function(variable) {
+ return (function (data, status, xhr) {
+ search_scripts_loaded[variable] = true;
+
+ if (search_scripts_loaded['navigation_loaded'] == true &&
+ search_scripts_loaded['search_loaded'] == true &&
+ search_scripts_loaded['search_index_loaded'] == true &&
+ search_scripts_loaded['searcher_loaded'] == true)
+ hookSearch();
+ });
+ }
+
+ loadAsync('js/navigation.js', search_success_function('navigation_loaded'));
+ loadAsync('js/search.js', search_success_function('search_loaded'));
+ loadAsync('js/search_index.js', search_success_function('search_index_loaded'));
+ loadAsync('js/searcher.js', search_success_function('searcher_loaded'));
});
diff --git a/lib/rdoc/generator/template/darkfish/rdoc.css b/lib/rdoc/generator/template/darkfish/rdoc.css
index 4f22adaae1..2f4dca7e08 100644
--- a/lib/rdoc/generator/template/darkfish/rdoc.css
+++ b/lib/rdoc/generator/template/darkfish/rdoc.css
@@ -23,12 +23,22 @@ h3 span,
h4 span,
h5 span,
h6 span {
+ position: relative;
+
display: none;
padding-left: 1em;
+ line-height: 0;
+ vertical-align: baseline;
font-size: 10px;
- vertical-align: super;
}
+h1 span { top: -1.3em; }
+h2 span { top: -1.2em; }
+h3 span { top: -1.0em; }
+h4 span { top: -0.8em; }
+h5 span { top: -0.5em; }
+h6 span { top: -0.5em; }
+
h1:hover span,
h2:hover span,
h3:hover span,
diff --git a/lib/rdoc/i18n.rb b/lib/rdoc/i18n.rb
new file mode 100644
index 0000000000..4cccbc66d3
--- /dev/null
+++ b/lib/rdoc/i18n.rb
@@ -0,0 +1,9 @@
+##
+# This module provides i18n realated features.
+
+module RDoc::I18n
+
+ autoload :Locale, 'rdoc/i18n/locale'
+ autoload :Text, 'rdoc/i18n/text'
+
+end
diff --git a/lib/rdoc/i18n/locale.rb b/lib/rdoc/i18n/locale.rb
new file mode 100644
index 0000000000..e98732e086
--- /dev/null
+++ b/lib/rdoc/i18n/locale.rb
@@ -0,0 +1,101 @@
+##
+# A message container for a locale.
+#
+# This object provides the following two features:
+#
+# * Loads translated messages from .po file.
+# * Translates a message into the locale.
+
+class RDoc::I18n::Locale
+
+ @@locales = {} # :nodoc:
+
+ class << self
+
+ ##
+ # Returns the locale object for +locale_name+.
+
+ def [](locale_name)
+ @@locales[locale_name] ||= new(locale_name)
+ end
+
+ ##
+ # Sets the locale object for +locale_name+.
+ #
+ # Normally, this method is not used. This method is useful for
+ # testing.
+
+ def []=(locale_name, locale)
+ @@locales[locale_name] = locale
+ end
+
+ end
+
+ ##
+ # The name of the locale. It uses IETF language tag format
+ # +[language[_territory][.codeset][@modifier]]+.
+ #
+ # See also {BCP 47 - Tags for Identifying
+ # Languages}[http://tools.ietf.org/rfc/bcp/bcp47.txt].
+
+ attr_reader :name
+
+ ##
+ # Creates a new locale object for +name+ locale. +name+ must
+ # follow IETF language tag format.
+
+ def initialize(name)
+ @name = name
+ @messages = {}
+ end
+
+ ##
+ # Loads translation messages from +locale_directory+/+@name+/rdoc.po
+ # or +locale_directory+/+@name+.po. The former has high priority.
+ #
+ # This method requires gettext gem for parsing .po file. If you
+ # don't have gettext gem, this method doesn't load .po file. This
+ # method warns and returns +false+.
+ #
+ # Returns +true+ if succeeded, +false+ otherwise.
+
+ def load(locale_directory)
+ return false if @name.nil?
+
+ po_file_candidates = [
+ File.join(locale_directory, @name, 'rdoc.po'),
+ File.join(locale_directory, "#{@name}.po"),
+ ]
+ po_file = po_file_candidates.find do |po_file_candidate|
+ File.exist?(po_file_candidate)
+ end
+ return false unless po_file
+
+ begin
+ require 'gettext/po_parser'
+ require 'gettext/mo'
+ rescue LoadError
+ warn('Need gettext gem for i18n feature:')
+ warn(' gem install gettext')
+ return false
+ end
+
+ po_parser = GetText::POParser.new
+ messages = GetText::MO.new
+ po_parser.report_warning = false
+ po_parser.parse_file(po_file, messages)
+
+ @messages.merge!(messages)
+
+ true
+ end
+
+ ##
+ # Translates the +message+ into locale. If there is no tranlsation
+ # messages for +message+ in locale, +message+ itself is returned.
+
+ def translate(message)
+ @messages[message] || message
+ end
+
+end
diff --git a/lib/rdoc/i18n/text.rb b/lib/rdoc/i18n/text.rb
new file mode 100644
index 0000000000..ee5c66a1ff
--- /dev/null
+++ b/lib/rdoc/i18n/text.rb
@@ -0,0 +1,125 @@
+##
+# An i18n supported text.
+#
+# This object provides the following two features:
+#
+# * Extracts translation messages from wrapped raw text.
+# * Translates wrapped raw text in specified locale.
+#
+# Wrapped raw text is one of String, RDoc::Comment or Array of them.
+
+class RDoc::I18n::Text
+
+ ##
+ # Creates a new i18n supported text for +raw+ text.
+
+ def initialize(raw)
+ @raw = raw
+ end
+
+ ##
+ # Extracts translation target messages and yields each message.
+ #
+ # Each yielded message is a Hash. It consists of the followings:
+ #
+ # :type :: :paragraph
+ # :paragraph :: String (The translation target message itself.)
+ # :line_no :: Integer (The line number of the :paragraph is started.)
+ #
+ # The above content may be added in the future.
+
+ def extract_messages
+ parse do |part|
+ case part[:type]
+ when :empty_line
+ # ignore
+ when :paragraph
+ yield(part)
+ end
+ end
+ end
+
+ # Translates raw text into +locale+.
+ def translate(locale)
+ translated_text = ''
+ parse do |part|
+ case part[:type]
+ when :paragraph
+ translated_text << locale.translate(part[:paragraph])
+ when :empty_line
+ translated_text << part[:line]
+ else
+ raise "should not reach here: unexpected type: #{type}"
+ end
+ end
+ translated_text
+ end
+
+ private
+ def parse(&block)
+ paragraph = ''
+ paragraph_start_line = 0
+ line_no = 0
+
+ each_line(@raw) do |line|
+ line_no += 1
+ case line
+ when /\A\s*\z/
+ if paragraph.empty?
+ emit_empty_line_event(line, line_no, &block)
+ else
+ paragraph << line
+ emit_paragraph_event(paragraph, paragraph_start_line, line_no,
+ &block)
+ paragraph = ''
+ end
+ else
+ paragraph_start_line = line_no if paragraph.empty?
+ paragraph << line
+ end
+ end
+
+ unless paragraph.empty?
+ emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
+ end
+ end
+
+ def each_line(raw, &block)
+ case raw
+ when RDoc::Comment
+ raw.text.each_line(&block)
+ when Array
+ raw.each do |comment, location|
+ each_line(comment, &block)
+ end
+ else
+ raw.each_line(&block)
+ end
+ end
+
+ def emit_empty_line_event(line, line_no)
+ part = {
+ :type => :empty_line,
+ :line => line,
+ :line_no => line_no,
+ }
+ yield(part)
+ end
+
+ def emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
+ paragraph_part = {
+ :type => :paragraph,
+ :line_no => paragraph_start_line,
+ }
+ match_data = /(\s*)\z/.match(paragraph)
+ if match_data
+ paragraph_part[:paragraph] = match_data.pre_match
+ yield(paragraph_part)
+ emit_empty_line_event(match_data[1], line_no, &block)
+ else
+ paragraph_part[:paragraph] = paragraph
+ yield(paragraph_part)
+ end
+ end
+
+end
diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb
index e1d75fa52b..0e754ff33d 100644
--- a/lib/rdoc/markup.rb
+++ b/lib/rdoc/markup.rb
@@ -84,7 +84,7 @@
#
# markup.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
#
-# wh = WikiHtml.new markup
+# wh = WikiHtml.new RDoc::Options.new, markup
# wh.add_tag(:STRIKE, "<strike>", "</strike>")
#
# puts "<body>#{wh.convert ARGF.read}</body>"
@@ -163,7 +163,7 @@
#
# The header's id would be:
#
-# <h1 id="method-i-do_fun_things-label-Example">Example</h3>
+# <h1 id="method-i-do_fun_things-label-Example">Example</h1>
#
# The label can be linked-to using <tt>SomeClass@Headers</tt>. See
# {Links}[RDoc::Markup@Links] for further details.
diff --git a/lib/rdoc/method_attr.rb b/lib/rdoc/method_attr.rb
index 00c9318852..9af64539c3 100644
--- a/lib/rdoc/method_attr.rb
+++ b/lib/rdoc/method_attr.rb
@@ -110,6 +110,9 @@ class RDoc::MethodAttr < RDoc::CodeObject
# Order by #singleton then #name
def <=>(other)
+ return unless other.respond_to?(:singleton) &&
+ other.respond_to?(:name)
+
[ @singleton ? 0 : 1, name] <=>
[other.singleton ? 0 : 1, other.name]
end
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index e27be89dbf..5779d35c44 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -214,6 +214,16 @@ class RDoc::Options
attr_accessor :line_numbers
##
+ # The output locale.
+
+ attr_accessor :locale
+
+ ##
+ # The directory where locale data live.
+
+ attr_accessor :locale_dir
+
+ ##
# Name of the file, class or module to display in the initial index page (if
# not specified the first file we encounter is used)
@@ -325,7 +335,7 @@ class RDoc::Options
# other visibilities may be overridden on a per-method basis with the :doc:
# directive.
- attr_accessor :visibility
+ attr_reader :visibility
def initialize # :nodoc:
init_ivars
@@ -343,6 +353,9 @@ class RDoc::Options
@generators = RDoc::RDoc::GENERATORS
@hyperlink_all = false
@line_numbers = false
+ @locale = nil
+ @locale_name = nil
+ @locale_dir = 'locale'
@main_page = nil
@markup = 'rdoc'
@coverage_report = false
@@ -388,6 +401,8 @@ class RDoc::Options
@generator_name = map['generator_name']
@hyperlink_all = map['hyperlink_all']
@line_numbers = map['line_numbers']
+ @locale_name = map['locale_name']
+ @locale_dir = map['locale_dir']
@main_page = map['main_page']
@markup = map['markup']
@op_dir = map['op_dir']
@@ -412,6 +427,8 @@ class RDoc::Options
@generator_name == other.generator_name and
@hyperlink_all == other.hyperlink_all and
@line_numbers == other.line_numbers and
+ @locale == other.locale and
+ @locale_dir == other.locale_dir and
@main_page == other.main_page and
@markup == other.markup and
@op_dir == other.op_dir and
@@ -515,6 +532,13 @@ class RDoc::Options
@template_dir = template_dir_for @template
end
+ if @locale_name
+ @locale = RDoc::I18n::Locale[@locale_name]
+ @locale.load(@locale_dir)
+ else
+ @locale = nil
+ end
+
self
end
@@ -677,6 +701,19 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
end
+
+ opt.on("--locale=NAME",
+ "Specifies the output locale.") do |value|
+ @locale_name = value
+ end
+
+ opt.on("--locale-data-dir=DIR",
+ "Specifies the directory where locale data live.") do |value|
+ @locale_dir = value
+ end
+
+ opt.separator nil
+
opt.on("--all", "-a",
"Synonym for --visibility=private.") do |value|
@visibility = :private
@@ -1016,8 +1053,7 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
- opt.on("--help",
- "Display this help") do
+ opt.on("--help", "-h", "Display this help") do
RDoc::RDoc::GENERATORS.each_key do |generator|
setup_generator generator
end
@@ -1174,6 +1210,22 @@ Usage: #{opt.program_name} [options] [names...]
end
end
+ # Sets the minimum visibility of a documented method.
+ #
+ # Accepts +:public+, +:protected+, +:private+, +:nodoc+, or +:all+.
+ #
+ # When +:all+ is passed, visibility is set to +:private+, similarly to
+ # RDOCOPT="--all", see #visibility for more information.
+
+ def visibility= visibility
+ case visibility
+ when :all
+ @visibility = :private
+ else
+ @visibility = visibility
+ end
+ end
+
##
# Displays a warning using Kernel#warn if we're being verbose
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index 5572ba10a4..4da7f00d3c 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -83,7 +83,7 @@ class RDoc::Parser
mode = "r"
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
- mode = "r:#{encoding}" if encoding
+ mode = "rb:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
not s.valid_encoding?
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb
index f7d0a9afa0..dd3ba5efdb 100644
--- a/lib/rdoc/parser/c.rb
+++ b/lib/rdoc/parser/c.rb
@@ -594,9 +594,10 @@ class RDoc::Parser::C < RDoc::Parser
\s*#{attr_name}\s*,
#{rw},.*?\)\s*;%xm then
$1
- elsif @content =~ %r%Document-attr:\s#{attr_name}\s*?\n
- ((?>.*?\*/))%xm then
- $1
+ elsif @content =~ %r%(/\*.*?(?:\s*\*\s*)?)
+ Document-attr:\s#{attr_name}\s*?\n
+ ((?>(.|\n)*?\*/))%x then
+ "#{$1}\n#{$2}"
else
''
end
@@ -610,7 +611,7 @@ class RDoc::Parser::C < RDoc::Parser
def find_body class_name, meth_name, meth_obj, file_content, quiet = false
case file_content
when %r%((?>/\*.*?\*/\s*)?)
- ((?:(?:static|SWIGINTERN)\s+)?
+ ((?:(?:\w+)\s+)?
(?:intern\s+)?VALUE\s+#{meth_name}
\s*(\([^)]*\))([^;]|$))%xm then
comment = RDoc::Comment.new $1, @top_level
@@ -1185,7 +1186,6 @@ class RDoc::Parser::C < RDoc::Parser
if hash then
args << "p#{position} = {}"
- position += 1
end
args << '&block' if block
diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb
index 75fcaaad85..a3567c1f81 100644
--- a/lib/rdoc/parser/changelog.rb
+++ b/lib/rdoc/parser/changelog.rb
@@ -146,10 +146,10 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
entry_name = nil unless entry_name =~ /#{time.year}/
rescue NoMethodError
# HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
- time, = entry_name.split ' ', 2
+ entry_name.split ' ', 2
rescue ArgumentError
if /out of range/ =~ $!.message
- time = Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
+ Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
else
entry_name = nil
end
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index 1c4b637640..ce1083edc7 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -187,15 +187,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
- # Extracts the visibility information for the visibility token +tk+.
+ # Extracts the visibility information for the visibility token +tk+
+ # and +single+ class type identifier.
#
# Returns the visibility type (a string), the visibility (a symbol) and
# +singleton+ if the methods following should be converted to singleton
# methods.
- def get_visibility_information tk # :nodoc:
+ def get_visibility_information tk, single # :nodoc:
vis_type = tk.name
- singleton = false
+ singleton = single == SINGLE
vis =
case vis_type
@@ -226,6 +227,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
comment = ''
comment.force_encoding @encoding if @encoding
first_line = true
+ first_comment_tk_class = nil
tk = get_tk
@@ -238,6 +240,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
skip_tkspace
tk = get_tk
else
+ break if first_comment_tk_class and not first_comment_tk_class === tk
+ first_comment_tk_class = tk.class
+
first_line = false
comment << tk.text << "\n"
tk = get_tk
@@ -841,7 +846,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
# true, no found constants will be added to RDoc.
def parse_constant container, tk, comment, ignore_constants = false
- prev_container = container
offset = tk.seek
line_no = tk.line_no
@@ -864,8 +868,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
unless TkASSIGN === eq_tk then
- suppress_parents container, prev_container
-
unget_tk eq_tk
return false
end
@@ -889,7 +891,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
@stats.add_constant con
- con = container.add_constant con
+ container.add_constant con
true
end
@@ -1305,7 +1307,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
return unless name
meth = RDoc::AnyMethod.new get_tkread, name
- meth.singleton = singleton
+ meth.singleton = single == SINGLE ? true : singleton
record_location meth
meth.offset = offset
@@ -1875,9 +1877,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Determines the visibility in +container+ from +tk+
def parse_visibility(container, single, tk)
- singleton = (single == SINGLE)
-
- vis_type, vis, singleton = get_visibility_information tk
+ vis_type, vis, singleton = get_visibility_information tk, single
skip_tkspace_comment false
@@ -2078,7 +2078,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def skip_for_variable
skip_tkspace false
- tk = get_tk
+ get_tk
skip_tkspace false
tk = get_tk
unget_tk(tk) unless TkIN === tk
diff --git a/lib/rdoc/rd/block_parser.rb b/lib/rdoc/rd/block_parser.rb
index ed621290fd..a495ca4e1e 100644
--- a/lib/rdoc/rd/block_parser.rb
+++ b/lib/rdoc/rd/block_parser.rb
@@ -1,6 +1,6 @@
#
# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.9
+# This file is automatically generated by Racc 1.4.11
# from Racc grammer file "".
#
diff --git a/lib/rdoc/rd/inline_parser.rb b/lib/rdoc/rd/inline_parser.rb
index c3c1f4b030..80d029cc21 100644
--- a/lib/rdoc/rd/inline_parser.rb
+++ b/lib/rdoc/rd/inline_parser.rb
@@ -1,6 +1,6 @@
#
# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.9
+# This file is automatically generated by Racc 1.4.11
# from Racc grammer file "".
#
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index b41434ba39..4d45d47978 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -305,6 +305,9 @@ option)
when "directory" then
next if rel_file_name == "CVS" || rel_file_name == ".svn"
+ created_rid = File.join rel_file_name, "created.rid"
+ next if File.file? created_rid
+
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
if File.file? dot_doc then
@@ -336,7 +339,7 @@ option)
# Parses +filename+ and returns an RDoc::TopLevel
def parse_file filename
- if defined?(Encoding) then
+ if Object.const_defined? :Encoding then
encoding = @options.encoding
filename = filename.encode encoding
end
@@ -411,8 +414,6 @@ The internal error was:
return [] if file_list.empty?
- file_info = []
-
@stats.begin_adding
file_info = file_list.map do |filename|
@@ -565,4 +566,5 @@ end
# require built-in generators after discovery in case they've been replaced
require 'rdoc/generator/darkfish'
require 'rdoc/generator/ri'
+require 'rdoc/generator/pot'
diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb
index d470d2b5f8..ce1c25dd6b 100644
--- a/lib/rdoc/ruby_lex.rb
+++ b/lib/rdoc/ruby_lex.rb
@@ -434,7 +434,7 @@ class RDoc::RubyLex
|op, io|
@ltype = "="
res = ''
- nil until (ch = getc) == "\n"
+ nil until getc == "\n"
until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
(ch = getc)
diff --git a/lib/rdoc/ruby_token.rb b/lib/rdoc/ruby_token.rb
index 81d3eb0b25..f091e1a676 100644
--- a/lib/rdoc/ruby_token.rb
+++ b/lib/rdoc/ruby_token.rb
@@ -73,7 +73,7 @@ module RDoc::RubyToken
@node = node
end
- attr_reader :node
+ attr_reader:node
def ==(other)
self.class == other.class and
@@ -101,7 +101,7 @@ module RDoc::RubyToken
super(seek, line_no, char_no)
@name = name
end
- attr_reader :name
+ attr_reader:name
def ==(other)
self.class == other.class and
@@ -192,7 +192,7 @@ module RDoc::RubyToken
@text = nil
end
- attr_reader :op
+ attr_reader:op
def ==(other)
self.class == other.class and
@@ -217,7 +217,7 @@ module RDoc::RubyToken
super(seek, line_no, char_no)
@name = name
end
- attr_reader :name
+ attr_reader:name
def ==(other)
self.class == other.class and
diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb
index b4393114f1..c4eaddbd97 100644
--- a/lib/rdoc/rubygems_hook.rb
+++ b/lib/rdoc/rubygems_hook.rb
@@ -153,7 +153,13 @@ class RDoc::RubygemsHook
options = nil
args = @spec.rdoc_options
- args.concat @spec.require_paths
+
+ if @spec.respond_to? :source_paths then
+ args.concat @spec.source_paths
+ else
+ args.concat @spec.require_paths
+ end
+
args.concat @spec.extra_rdoc_files
case config_args = Gem.configuration[:rdoc]
diff --git a/lib/rdoc/stats/normal.rb b/lib/rdoc/stats/normal.rb
index 32de631e2e..ef366a500e 100644
--- a/lib/rdoc/stats/normal.rb
+++ b/lib/rdoc/stats/normal.rb
@@ -1,4 +1,7 @@
-require 'io/console/size'
+begin
+ require 'io/console/size'
+rescue LoadError
+end
##
# Stats printer that prints just the files being documented with a progress
@@ -22,7 +25,11 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
# Print a progress bar, but make sure it fits on a single line. Filename
# will be truncated if necessary.
- terminal_width = IO.console_size[1].to_i.nonzero? || 80
+ terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
+ IO.console_size[1].to_i.nonzero? || 80
+ else
+ 80
+ end
max_filename_size = terminal_width - progress_bar.size
if filename.size > max_filename_size then
diff --git a/lib/rdoc/task.rb b/lib/rdoc/task.rb
index d347e4d6ab..a83939090d 100644
--- a/lib/rdoc/task.rb
+++ b/lib/rdoc/task.rb
@@ -291,7 +291,7 @@ class RDoc::Task < Rake::TaskLib
private
def rdoc_target
- "#{rdoc_dir}/index.html"
+ "#{rdoc_dir}/created.rid"
end
def rdoc_task_name
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb
index 0fda72e3ae..3a58641ec1 100644
--- a/lib/rdoc/text.rb
+++ b/lib/rdoc/text.rb
@@ -103,6 +103,15 @@ module RDoc::Text
# Requires the including class to implement #formatter
def markup text
+ if @store.rdoc.options
+ locale = @store.rdoc.options.locale
+ else
+ locale = nil
+ end
+ if locale
+ i18n_text = RDoc::I18n::Text.new(text)
+ text = i18n_text.translate(locale)
+ end
parse(text).accept formatter
end