1313
1414class RDoc ::Markup ::PreProcess
1515
16+ attr_accessor :options
17+
1618 @registered = { }
1719
1820 ##
@@ -38,6 +40,7 @@ def self.registered
3840 def initialize ( input_file_name , include_path )
3941 @input_file_name = input_file_name
4042 @include_path = include_path
43+ @options = nil
4144 end
4245
4346 ##
@@ -54,68 +57,120 @@ def initialize(input_file_name, include_path)
5457 # If +code_object+ is given and the param is set as metadata on the
5558 # +code_object+. See RDoc::CodeObject#metadata
5659
57- def handle text , code_object = nil
60+ def handle text , code_object = nil , &block
61+ encoding = if defined? ( Encoding ) then text . encoding else nil end
5862 # regexp helper (square brackets for optional)
5963 # $1 $2 $3 $4 $5
6064 # [prefix][\]:directive:[spaces][param]newline
61- text . gsub! ( /^([ \t ]*# ?[ \t ]*)(\\ ?):(\w +):([ \t ]*)(.+)?\n / ) do
65+ text . gsub! ( /^([ \t ]*(?:#| \/ ? \* ) ?[ \t ]*)(\\ ?):(\w +):([ \t ]*)(.+)?\n / ) do
6266 # skip something like ':toto::'
6367 next $& if $4. empty? and $5 and $5[ 0 , 1 ] == ':'
6468
6569 # skip if escaped
6670 next "#$1:#$3:#$4#$5\n " unless $2. empty?
6771
68- prefix = $1
69- directive = $3. downcase
70- param = $5
71-
72- case directive
73- when 'include' then
74- filename = param . split [ 0 ]
75- encoding = if defined? ( Encoding ) then text . encoding else nil end
76- include_file filename , prefix , encoding
77- when 'category' then
78- if RDoc ::Context === code_object then
79- section = code_object . add_section param , ''
80- code_object . temporary_section = section
81- end
72+ handle_directive $1, $3, $5, code_object , encoding , &block
73+ end
74+
75+ text
76+ end
77+
78+ #--
79+ # When 1.8.7 support is ditched prefix can be defaulted to ''
80+
81+ def handle_directive prefix , directive , param , code_object = nil ,
82+ encoding = nil
83+ blankline = "#{ prefix . strip } \n "
84+ directive = directive . downcase
85+
86+ case directive
87+ when 'arg' , 'args' then
88+ return blankline unless code_object
89+
90+ code_object . params = param
91+
92+ blankline
93+ when 'category' then
94+ if RDoc ::Context === code_object then
95+ section = code_object . add_section param , ''
96+ code_object . temporary_section = section
97+ end
98+
99+ blankline # ignore category if we're not on an RDoc::Context
100+ when 'doc' then
101+ return blankline unless code_object
102+ code_object . document_self = true
103+ code_object . force_documentation = true
104+
105+ blankline
106+ when 'enddoc' then
107+ return blankline unless code_object
108+ code_object . done_documenting = true
109+
110+ blankline
111+ when 'include' then
112+ filename = param . split . first
113+ include_file filename , prefix , encoding
114+ when 'main' then
115+ @options . main_page = param if @options . respond_to? :main_page
116+
117+ blankline
118+ when 'nodoc' then
119+ return blankline unless code_object
120+ code_object . document_self = nil # notify nodoc
121+ code_object . document_children = param . to_s . downcase != 'all'
82122
83- '' # ignore category if we're not on an RDoc::Context
84- when 'doc' then
85- next unless code_object
86- code_object . document_self = true
87- code_object . force_documentation = true
88- when 'nodoc' then
89- next unless code_object
90- code_object . document_self = nil # notify nodoc
91- code_object . document_children = param . to_s . downcase != 'all'
92- when 'yield' , 'yields' then
93- next unless code_object
94- # remove parameter &block
95- code_object . params . sub! ( /,?\s *&\w +/ , '' ) if code_object . params
96-
97- code_object . block_params = param
98- else
99- result = yield directive , param if block_given?
100-
101- case result
102- when nil then
103- code_object . metadata [ directive ] = param if code_object
104- if RDoc ::Markup ::PreProcess . registered . include? directive then
105- handler = RDoc ::Markup ::PreProcess . registered [ directive ]
106- result = handler . call directive , param if handler
107- else
108- result = "#{ prefix } :#{ directive } : #{ param } \n "
109- end
110- when false then
123+ blankline
124+ when 'notnew' , 'not_new' , 'not-new' then
125+ return blankline unless RDoc ::AnyMethod === code_object
126+
127+ code_object . dont_rename_initialize = true
128+
129+ blankline
130+ when 'startdoc' then
131+ return blankline unless code_object
132+
133+ code_object . start_doc
134+ code_object . force_documentation = true
135+
136+ blankline
137+ when 'stopdoc' then
138+ return blankline unless code_object
139+
140+ code_object . stop_doc
141+
142+ blankline
143+ when 'title' then
144+ @options . default_title = param if @options . respond_to? :default_title=
145+
146+ blankline
147+ when 'yield' , 'yields' then
148+ return blankline unless code_object
149+ # remove parameter &block
150+ code_object . params . sub! ( /,?\s *&\w +/ , '' ) if code_object . params
151+
152+ code_object . block_params = param
153+
154+ blankline
155+ else
156+ result = yield directive , param if block_given?
157+
158+ case result
159+ when nil then
160+ code_object . metadata [ directive ] = param if code_object
161+
162+ if RDoc ::Markup ::PreProcess . registered . include? directive then
163+ handler = RDoc ::Markup ::PreProcess . registered [ directive ]
164+ result = handler . call directive , param if handler
165+ else
111166 result = "#{ prefix } :#{ directive } : #{ param } \n "
112167 end
113-
114- result
168+ when false then
169+ result = " #{ prefix } : #{ directive } : #{ param } \n "
115170 end
116- end
117171
118- text
172+ result
173+ end
119174 end
120175
121176 ##
0 commit comments