Method: RDoc::Markup::PreProcess#include_file
- Defined in:
- lib/rdoc/markup/pre_process.rb
#include_file(name, indent, encoding) ⇒ Object
Handles the :include: _filename_ directive.
If the first line of the included file starts with ‘#’, and contains an encoding information in the form ‘coding:’ or ‘coding=’, it is removed.
If all lines in the included file start with a ‘#’, this leading ‘#’ is removed before inclusion. The included content is indented like the :include: directive. – so all content will be verbatim because of the likely space after ‘#’? TODO shift left the whole file content in that case TODO comment stop/start #– and #++ in included file must be processed here
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/rdoc/markup/pre_process.rb', line 257 def include_file name, indent, encoding full_name = find_include_file name unless full_name then warn "Couldn't find file to include '#{name}' from #{@input_file_name}" return '' end content = RDoc::Encoding.read_file full_name, encoding, true # strip magic comment content = content.sub(/\A# .*coding[=:].*$/, '').lstrip # strip leading '#'s, but only if all lines start with them if content =~ /^[^#]/ then content.gsub(/^/, indent) else content.gsub(/^#?/, indent) end end |