class RDoc::AnyMethod
Constants
- TITLE_AFTER
Public Instance Methods
sdoc_markup_code()
click to toggle source
Turns the method's token stream into HTML.
Prepends line numbers if add_line_numbers
is true.
# File lib/sdoc/generator.rb, line 37 def sdoc_markup_code return '' unless @token_stream src = "" starting_title = false @token_stream.each do |t| next unless t style = case t when RDoc::RubyToken::TkFLOAT then 'ruby-number' when RDoc::RubyToken::TkINTEGER then 'ruby-number' when RDoc::RubyToken::TkCONSTANT then 'ruby-constant' when RDoc::RubyToken::TkKW then 'ruby-keyword' when RDoc::RubyToken::TkIVAR then 'ruby-ivar' when RDoc::RubyToken::TkOp then 'ruby-operator' when RDoc::RubyToken::TkId then 'ruby-identifier' when RDoc::RubyToken::TkNode then 'ruby-node' when RDoc::RubyToken::TkCOMMENT then 'ruby-comment' when RDoc::RubyToken::TkREGEXP then 'ruby-regexp' when RDoc::RubyToken::TkSTRING then 'ruby-string' when RDoc::RubyToken::TkVal then 'ruby-value' end if RDoc::RubyToken::TkId === t && starting_title starting_title = false style = 'ruby-keyword ruby-title' end if RDoc::RubyToken::TkKW === t && TITLE_AFTER.include?(t.text) starting_title = true end text = CGI.escapeHTML t.text if style then src << "<span class=\"#{style}\">#{text}</span>" else src << text end end # dedent the source indent = src.length lines = src.lines.to_a lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment lines.each do |line| if line =~ /^ *(?=\S)/ n = $&.length indent = n if n < indent break if n == 0 end end src.gsub!(/^#{' ' * indent}/, '') if indent > 0 add_line_numbers(src) if self.class.add_line_numbers src end