Class Generators::HyperlinkHtml
In: generators/html_generator.rb
Parent: SM::ToHtml

Subclass of the SM::ToHtml class that supports looking up words in the AllReferences list. Those that are found (like AllReferences in this comment) will be hyperlinked

Methods

Public Class methods

We need to record the html path of our caller so we can generate correct relative paths for any hyperlinks that we find

[Source]

    # File generators/html_generator.rb, line 92
92:     def initialize(from_path, context)
93:       super()
94:       @from_path = from_path
95: 
96:       @parent_name = context.parent_name
97:       @parent_name += "::" if @parent_name
98:       @context = context
99:     end

Public Instance methods

Generate a hyperlink for url, labeled with text. Handle the special cases for img: and link: described under handle_special_HYPEDLINK

[Source]

     # File generators/html_generator.rb, line 164
164:     def gen_url(url, text)
165:       if url =~ /([A-Za-z]+):(.*)/
166:         type = $1
167:         path = $2
168:       else
169:         type = "http"
170:         path = url
171:         url  = "http://#{url}"
172:       end
173: 
174:       if type == "link"
175:         if path[0,1] == '#'     # is this meaningful?
176:           url = path
177:         else
178:           url = HTMLGenerator.gen_url(@from_path, path)
179:         end
180:       end
181: 
182:       if (type == "http" || type == "link") && 
183:           url =~ /\.(gif|png|jpg|jpeg|bmp)$/
184: 
185:         "<img src=\"#{url}\">"
186:       else
187:         "<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
188:       end
189:     end

We‘re invoked when any text matches the CROSSREF pattern (defined in MarkUp). If we fine the corresponding reference, generate a hyperlink. If the name we‘re looking for contains no punctuation, we look for it up the module/class chain. For example, HyperlinkHtml is found, even without the Generators:: prefix, because we look for it in module Generators first.

[Source]

     # File generators/html_generator.rb, line 108
108:     def handle_special_CROSSREF(special)
109:       name = special.text
110:       if name[0,1] == '#'
111:         lookup = name[1..-1]
112:         name = lookup unless Options.instance.show_hash
113:       else
114:         lookup = name
115:       end
116: 
117:       # Find class, module, or method in class or module.
118:       if /([A-Z]\w*)[.\#](\w+[!?=]?)/ =~ lookup
119:         container = $1
120:         method = $2
121:         ref = @context.find_symbol(container, method)
122:       elsif /([A-Za-z]\w*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup
123:         container = $1
124:         method = $2
125:         ref = @context.find_symbol(container, method)
126:       else
127:         ref = @context.find_symbol(lookup)
128:       end
129: 
130:       if ref and ref.document_self
131:         "<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
132:       else
133:         name
134:       end
135:     end

CROSSREFFILE is similar to CROSSREF. But this pattern is hit to filenames or methods in files

[Source]

     # File generators/html_generator.rb, line 141
141:     def handle_special_CROSSREFFILE(special)
142:       name = special.text
143: 
144:       # Find file, or method in file
145:       if /([\w\/].*\.\w+)[.\#](.*)/ =~ name
146:         file_name = $1
147:         method = $2
148:         ref = @context.find_file(file_name, method)
149:       else
150:         ref = @context.find_file(name)
151:       end
152: 
153:       if ref and ref.document_self
154:         "<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
155:       else
156:         name
157:       end
158: 
159:     end

And we‘re invoked with a potential external hyperlink mailto: just gets inserted. http: links are checked to see if they reference an image. If so, that image gets inserted using an <img> tag. Otherwise a conventional <a href> is used. We also support a special type of hyperlink, link:, which is a reference to a local file whose path is relative to the —op directory.

[Source]

     # File generators/html_generator.rb, line 198
198:     def handle_special_HYPERLINK(special)
199:       url = special.text
200:       gen_url(url, url)
201:     end

HEre‘s a hypedlink where the label is different to the URL

 <label>[url]

[Source]

     # File generators/html_generator.rb, line 207
207:     def handle_special_TIDYLINK(special)
208:       text = special.text
209: #      unless text =~ /(\S+)\[(.*?)\]/
210:       unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ 
211:         return text
212:       end
213:       label = $1
214:       url   = $2
215:       gen_url(url, label)
216:     end

[Validate]