Class: RDocSupport::HyperLinkHtml

Inherits:
SM::ToHtml
  • Object
show all
Defined in:
lib/rdocsupport.rb

Overview

Handle special hyperlinking requirments for RDoc formatted entries. Requires RDoc

Instance Method Summary collapse

Constructor Details

#initializeHyperLinkHtml

Initialize the HyperLinkHtml object. [path] location of the node [site] object representing the whole site (typically of class Site)



49
50
51
52
# File 'lib/rdocsupport.rb', line 49

def initialize
  super()
  add_tag(:CENTER, "<center>", "</center>")
end

Instance Method Details

#handle_special_BR(special) ⇒ Object

handle



55
56
57
58
# File 'lib/rdocsupport.rb', line 55

def handle_special_BR(special)
  return "&lt;br/&gt" if special.text[0,1] == '\\'
  special.text
end

Here's a hyperlink where the label is different to the URL [[url label that may contain spaces]]



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rdocsupport.rb', line 104

def handle_special_TIDYLINK(special)
  text = special.text.strip
  return text[1..-1] if text[0,1] == '\\'
  unless text =~ /\[\[(\S+?)\s+(.+?)\]\]/
    return text
  end
  url   = $1
  label = $2
  label = RDocFormatter.new(label).to_html
  label = label.split.select{|x| x =~ /\S/}.
    map{|x| x.chomp}.join(' ')

  case url
  when /link:(\S+)/
    return %{<a href="#{$1}">#{label}</a>}
  when /img:(\S+)/
    return %{<img src="http://#{$1}" alt="#{label}" />}
  when /rubytalk:(\S+)/
    return %{<a href="http://ruby-talk.org/blade/#{$1}">#{label}</a>}
  when /rubygarden:(\S+)/
    return %{<a href="http://www.rubygarden.org/ruby?#{$1}">#{label}</a>}
  when /c2:(\S+)/
    return %{<a href="http://c2.com/cgi/wiki?#{$1}">#{label}</a>}
  when /isbn:(\S+)/
    return %{<a href="http://search.barnesandnoble.com/bookSearch/} +
      %{isbnInquiry.asp?isbn=#{$1}">#{label}</a>}
  end

  unless url =~ /\w+?:/
    url = "http://#{url}"
  end

  "<a href=\"#{url}\">#{label}</a>"
end