Class: RDocText

Inherits:
String show all
Defined in:
lib/acts_as_markup_on/exts/rdoc.rb

Overview

This allows a us to create a wrapper object similar to those provided by the Markdown and Textile libraries. It stores the original and formated HTML text in instance variables. It also stores the SimpleMarkup parser objects in instance variables.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#to_xml

Constructor Details

#initialize(str) ⇒ RDocText

Returns a new instance of RDocText.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 71

def initialize(str)
  super(str)
  @text = str.to_s
  @markup = RDoc::Markup.new
  
  # external hyperlinks
  @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)

  # and links of the form  <text>[<url>]
  @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
  
  # Convert leading comment markers to spaces, but only
  # if all non-blank lines have them

  if str =~ /^(?>\s*)[^\#]/
    content = str
  else
    content = str.gsub(/^\s*(#+)/)  { $1.tr('#',' ') }
  end
  
  @html_formatter = RDocWithHyperlinkToHtml.new(RDoc::Options.new)
  
  @html = @markup.convert(@text, @html_formatter)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



67
68
69
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 67

def html
  @html
end

#html_formaterObject (readonly)

Returns the value of attribute html_formater.



69
70
71
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 69

def html_formater
  @html_formater
end

#markupObject (readonly)

Returns the value of attribute markup.



68
69
70
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 68

def markup
  @markup
end

#textObject (readonly)

Returns the value of attribute text.



66
67
68
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 66

def text
  @text
end

Instance Method Details

#to_htmlObject



96
97
98
# File 'lib/acts_as_markup_on/exts/rdoc.rb', line 96

def to_html
  @html
end