Class: RDocText

Inherits:
String show all
Defined in:
lib/acts_as_markup/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.



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

def initialize(str)
  super(str)
  @text = str.to_s
  @markup = SM::SimpleMarkup.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
  
  @html = @markup.convert(@text, @html_formatter)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



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

def html
  @html
end

#html_formaterObject (readonly)

Returns the value of attribute html_formater.



70
71
72
# File 'lib/acts_as_markup/exts/rdoc.rb', line 70

def html_formater
  @html_formater
end

#markupObject (readonly)

Returns the value of attribute markup.



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

def markup
  @markup
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#to_htmlObject



97
98
99
# File 'lib/acts_as_markup/exts/rdoc.rb', line 97

def to_html
  @html
end