diff options
Diffstat (limited to 'lib/rdoc/markup/pre_process.rb')
-rw-r--r-- | lib/rdoc/markup/pre_process.rb | 137 |
1 files changed, 103 insertions, 34 deletions
diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb index 03f919aa0e..53e8e38ec1 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -13,6 +13,8 @@ require 'rdoc/encoding' class RDoc::Markup::PreProcess + attr_accessor :options + @registered = {} ## @@ -38,6 +40,7 @@ class RDoc::Markup::PreProcess def initialize(input_file_name, include_path) @input_file_name = input_file_name @include_path = include_path + @options = nil end ## @@ -54,54 +57,120 @@ class RDoc::Markup::PreProcess # If +code_object+ is given and the param is set as metadata on the # +code_object+. See RDoc::CodeObject#metadata - def handle text, code_object = nil + def handle text, code_object = nil, &block + encoding = if defined?(Encoding) then text.encoding else nil end # regexp helper (square brackets for optional) # $1 $2 $3 $4 $5 # [prefix][\]:directive:[spaces][param]newline - text.gsub!(/^([ \t]*#?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do + text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do # skip something like ':toto::' next $& if $4.empty? and $5 and $5[0, 1] == ':' # skip if escaped next "#$1:#$3:#$4#$5\n" unless $2.empty? - prefix = $1 - directive = $3.downcase - param = $5 - - case directive - when 'include' then - filename = param.split[0] - encoding = if defined?(Encoding) then text.encoding else nil end - include_file filename, prefix, encoding - when 'category' then - if RDoc::Context === code_object then - section = code_object.add_section param, '' - code_object.temporary_section = section - end + handle_directive $1, $3, $5, code_object, encoding, &block + end + + text + end + + #-- + # When 1.8.7 support is ditched prefix can be defaulted to '' + + def handle_directive prefix, directive, param, code_object = nil, + encoding = nil + blankline = "#{prefix.strip}\n" + directive = directive.downcase + + case directive + when 'arg', 'args' then + return blankline unless code_object + + code_object.params = param + + blankline + when 'category' then + if RDoc::Context === code_object then + section = code_object.add_section param, '' + code_object.temporary_section = section + end + + blankline # ignore category if we're not on an RDoc::Context + when 'doc' then + return blankline unless code_object + code_object.document_self = true + code_object.force_documentation = true + + blankline + when 'enddoc' then + return blankline unless code_object + code_object.done_documenting = true + + blankline + when 'include' then + filename = param.split.first + include_file filename, prefix, encoding + when 'main' then + @options.main_page = param if @options.respond_to? :main_page + + blankline + when 'nodoc' then + return blankline unless code_object + code_object.document_self = nil # notify nodoc + code_object.document_children = param !~ /all/i - '' # ignore category if we're not on an RDoc::Context - else - result = yield directive, param if block_given? - - case result - when nil then - code_object.metadata[directive] = param if code_object - if RDoc::Markup::PreProcess.registered.include? directive then - handler = RDoc::Markup::PreProcess.registered[directive] - result = handler.call directive, param if handler - else - result = "#{prefix}:#{directive}: #{param}\n" - end - when false then + blankline + when 'notnew', 'not_new', 'not-new' then + return blankline unless RDoc::AnyMethod === code_object + + code_object.dont_rename_initialize = true + + blankline + when 'startdoc' then + return blankline unless code_object + + code_object.start_doc + code_object.force_documentation = true + + blankline + when 'stopdoc' then + return blankline unless code_object + + code_object.stop_doc + + blankline + when 'title' then + @options.default_title = param if @options.respond_to? :default_title= + + blankline + when 'yield', 'yields' then + return blankline unless code_object + # remove parameter &block + code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params + + code_object.block_params = param + + blankline + else + result = yield directive, param if block_given? + + case result + when nil then + code_object.metadata[directive] = param if code_object + + if RDoc::Markup::PreProcess.registered.include? directive then + handler = RDoc::Markup::PreProcess.registered[directive] + result = handler.call directive, param if handler + else result = "#{prefix}:#{directive}: #{param}\n" end - - result + when false then + result = "#{prefix}:#{directive}: #{param}\n" end - end - text + result + end end ## |